Point Grey Blackfly and OpenCV

Here is a quick tutorial on how to use the Point Grey Research Blackfly camera with OpenCV. This tutorial should work for using OpenCV with other flycap cameras as well but I haven’t been able to test it out.

The flycap examples themselves that come with the sdk are quite involved and I wasn’t sure that all of their code was really necessary to simply acquire images etc. Turns out it isn’t! Check out this simple example program on my GitHub page:


Here are the lines of code that convert an image from Point Grey’s Image object to a cv::Mat for OpenCV:

// rawImage is captured using the flycap example

// convert to rgb
Image rgbImage;
rawImage.Convert(FlyCapture2::PIXEL_FORMAT_BGR, &rgbImage);

// convert to OpenCV Mat
unsigned int rowBytes =(double)rgbImage.GetReceivedDataSize()/(double)rgbImage.GetRows();
cv::Mat image = cv::Mat(rgbImage.GetRows(), rgbImage.GetCols(), CV_8UC3, rgbImage.GetData(),rowBytes);