//---------- void Color::update(IColorFrame * frame) { this->isFrameNewFlag = true; IFrameDescription * frameDescription = NULL; try { //allocate pixels and texture if we need to if (FAILED(frame->get_FrameDescription(&frameDescription))) { throw Exception("Failed to get frame description"); } int width, height; if (FAILED(frameDescription->get_Width(&width)) || FAILED(frameDescription->get_Height(&height))) { throw Exception("Failed to get width and height of frame"); } if (width != this->pixels.getWidth() || height != this->texture.getHeight()) { this->pixels.allocate(width, height, OF_IMAGE_COLOR_ALPHA); this->texture.allocate(this->pixels); } //update local rgba image if (FAILED(frame->CopyConvertedFrameDataToArray(this->pixels.size(), this->pixels.getPixels(), ColorImageFormat_Rgba))) { throw Exception("Couldn't pull pixel buffer"); } if (this->useTexture) { this->texture.loadData(this->pixels); } //update yuv if (this->yuvPixelsEnabled) { if (width != this->yuvPixels.getWidth() || height != this->yuvPixels.getHeight()) { this->yuvPixels.allocate(width, height, OF_PIXELS_YUY2); } if (FAILED(frame->CopyRawFrameDataToArray(this->yuvPixels.size(), this->yuvPixels.getPixels()))) { throw Exception("Couldn't pull raw YUV pixel buffer"); } } //update field of view if (FAILED(frameDescription->get_HorizontalFieldOfView(&this->horizontalFieldOfView))) { throw Exception("Failed to get horizonal field of view"); } if (FAILED(frameDescription->get_VerticalFieldOfView(&this->verticalFieldOfView))) { throw Exception("Failed to get vertical field of view"); } if (FAILED(frameDescription->get_DiagonalFieldOfView(&this->diagonalFieldOfView))) { throw Exception("Failed to get diagonal field of view"); } IColorCameraSettings * cameraSettings; if (FAILED(frame->get_ColorCameraSettings(&cameraSettings))) { throw Exception("Failed to get color camera settings"); } cameraSettings->get_ExposureTime(&this->exposure); cameraSettings->get_FrameInterval(&this->frameInterval); cameraSettings->get_Gain(&this->gain); cameraSettings->get_Gamma(&this->gamma); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frameDescription); }
//---------- void Color::update() { CHECK_OPEN IColorFrame * frame = NULL; IFrameDescription * frameDescription = NULL; try { //acquire frame if (FAILED(this->reader->AcquireLatestFrame(&frame))) { return; // we often throw here when no new frame is available } //allocate pixels and texture if we need to if (FAILED(frame->get_FrameDescription(&frameDescription))) { throw Exception("Failed to get frame description"); } int width, height; if (FAILED(frameDescription->get_Width(&width)) || FAILED(frameDescription->get_Height(&height))) { throw Exception("Failed to get width and height of frame"); } if (width != this->pixels.getWidth() || height != this->texture.getHeight()) { this->pixels.allocate(width, height, OF_IMAGE_COLOR_ALPHA); this->texture.allocate(this->pixels); } //update local assets if (FAILED(frame->CopyConvertedFrameDataToArray(this->pixels.size(), this->pixels.getPixels(), ColorImageFormat_Rgba))) { throw Exception("Couldn't pull pixel buffer"); } if (this->useTexture) { this->texture.loadData(this->pixels); } //update field of view if (FAILED(frameDescription->get_HorizontalFieldOfView(&this->horizontalFieldOfView))) { throw Exception("Failed to get horizonal field of view"); } if (FAILED(frameDescription->get_VerticalFieldOfView(&this->verticalFieldOfView))) { throw Exception("Failed to get vertical field of view"); } if (FAILED(frameDescription->get_DiagonalFieldOfView(&this->diagonalFieldOfView))) { throw Exception("Failed to get diagonal field of view"); } IColorCameraSettings * cameraSettings; if (FAILED(frame->get_ColorCameraSettings(&cameraSettings))) { throw Exception("Failed to get color camera settings"); } cameraSettings->get_ExposureTime(&this->exposure); cameraSettings->get_FrameInterval(&this->frameInterval); cameraSettings->get_Gain(&this->gain); cameraSettings->get_Gamma(&this->gamma); } catch (std::exception & e) { OFXKINECTFORWINDOWS2_ERROR << e.what(); } SafeRelease(frameDescription); SafeRelease(frame); }