0

I'm working with a PointGrey camera which returns an image having type:

typedef struct FlyCaptureImage
{
   // Rows, in pixels, of the image.
   int iRows;
   // Columns, in pixels, of the image.
   int iCols;
   // Row increment.  The number of bytes per row.
   int iRowInc;
   // Video mode that this image was captured with.  This member is only
   // populated when the image is returned from a grab call.
   FlyCaptureVideoMode videoMode;
   // Timestamp of this image.
   FlyCaptureTimestamp timeStamp;
   // Pointer to the actual image data.
   unsigned char* pData;
   //
   // If the returned image is Y8, Y16, RAW8 or RAW16, this flag indicates
   // whether it is a greyscale or stippled (bayer tiled) image.  In all
   // other modes, this flag has no meaning.
   //
   bool bStippled;
   // The pixel format of this image.
   FlyCapturePixelFormat pixelFormat;

   // This field is always 1 for single lens cameras.  This field is 
   // used to indicate the number of images contained in the structure 
   // when dealing with multi-imager systems such as the Bumblebee2 
   // or XB3?   int iNumImages;
   int iNumImages;

   // Reserved for future use.
   unsigned long  ulReserved[ 5 ];

} FlyCaptureImage;

whereas I want to process the image in OpenCV Mat, therefore, a conversion is needed. I did successfully try to iterate every element in the image to copy. But it's slow. So, it's better to copy just the pointer. This is my code using Mat initialization, simply like:

MatImg = Mat::Mat(FCImg.iRows, FCImg.iCols, CV_8UC3, FCImg.pData);

Please give me some advices on this. Is it the correct way to do?? I put this conversion in a separate class from the main program which received returned Mat image, e.g., mycam.getframe(image)

Thanks!

TSL_
  • 2,049
  • 3
  • 34
  • 55

1 Answers1

0

Often, each pixel row contains extra padding pixels at the end.
The full row size in bytes has several names including step, stepWidth and stride.
In the struct FlyCaptureImage this is called row increment: iRowInc.

Thus, in your case, you should specify the stride as in:

cv::Mat pgImg(FCImg.iRows, FCImg.iCols, CV_8UC3, FCImg.pData, FCImg.iRowInc);
Adi Shavit
  • 16,743
  • 5
  • 67
  • 137