static bool frameToImage (FlyCapture2::Image * frame, sensor_msgs::Image & image) { // Get the raw image dimensions FlyCapture2::PixelFormat pixFormat; uint32_t rows, cols, stride; FlyCapture2::Image convertedImage; FlyCapture2::Error error; error = frame->Convert(FlyCapture2::PIXEL_FORMAT_RGB, &convertedImage ); if (error != FlyCapture2::PGRERROR_OK) { error.PrintErrorTrace(); return false; } // Get the raw image dimensions convertedImage.GetDimensions( &rows, &cols, &stride, &pixFormat ); return sensor_msgs::fillImage (image, sensor_msgs::image_encodings::RGB8, rows, cols, stride, convertedImage.GetData ()); }
void CCaptureGUIView::setFlyImage(const FlyCapture2::Image& image) { unsigned int rows, cols, stride; FlyCapture2::PixelFormat format; image.GetDimensions(&rows, &cols, &stride, &format); m_bmpmutex.lock(); auto error = image.Convert(FlyCapture2::PIXEL_FORMAT_BGR, &fly_image); m_bmpmutex.unlock(); assert(error != FlyCapture2::PGRERROR_OK); // error check }
static bool frameToImage (FlyCapture2::Image * frame, sensor_msgs::Image & image) { std::string encoding; // Get the raw image dimensions FlyCapture2::PixelFormat pixFormat; uint32_t rows, cols, stride; // NOTE: 16-bit and Yuv formats not supported static const char *BAYER_ENCODINGS[] = { "none", "bayer_rggb8", "bayer_grbg8", "bayer_gbrg8", "bayer_bggr8", "unknown" }; //unsigned int bpp = frame->GetBitsPerPixel(); FlyCapture2::BayerTileFormat bayerFmt; bayerFmt = frame->GetBayerTileFormat (); //ROS_INFO("bayer is %u", bayerFmt); frame->GetDimensions( &rows, &cols, &stride, &pixFormat ); //ROS_INFO("Frame WxH = %d x %d", cols, rows); // FIXME: Dynamic resizing of camera is now working //ROS_INFO("Pixel Format (from Raw Image): 0x%08x", pixFormat); //ROS_INFO("Stride of Raw Image (The number of bytes between rows of the image): %d", stride); if (bayerFmt == FlyCapture2::NONE) { //ROS_INFO("Pixel Format (from Raw Image): 0x%08x", pixFormat); encoding = sensor_msgs::image_encodings::MONO8; return sensor_msgs::fillImage (image, encoding, rows, cols, stride, frame->GetData ()); } else { // Create a converted image FlyCapture2::Image convertedImage; FlyCapture2::Error error; //encoding = BAYER_ENCODINGS[bayerFmt]; switch ((FlyCapture2::PixelFormat) pixFormat) { case FlyCapture2::PIXEL_FORMAT_RAW8: // Convert the raw image error = frame->Convert(FlyCapture2::PIXEL_FORMAT_RGB, &convertedImage ); encoding = sensor_msgs::image_encodings::RGB8; // Arbitrary encoding based on pixel format if (error != FlyCapture2::PGRERROR_OK) { error.PrintErrorTrace(); return false; } // Get the raw image dimensions convertedImage.GetDimensions( &rows, &cols, &stride, &pixFormat ); break; default: return false; // FIXME: Now, it's arbitrarily converting Raw images to RGB8 encoding // TODO: Handle encoding directly from Bayer break; } // switch //ROS_INFO("Stride of Converted Image (The number of bytes between rows of the image): %d", stride); return sensor_msgs::fillImage (image, encoding, rows, cols, stride, convertedImage.GetData ()); } //else }