Code: Select all
// pMyCam is of type CameraLibrary::Camera *
int camWidth = pMyCam->Width();
int camHeight = pMyCam->Height();
// we set up a new OpenCV matrix for our frame image
// note that we use 1 channel with a depth of 8 bit,
// i.e. we want to get the data as grayscale picture
cv::Mat matFrame(cv::Size(camWidth, camHeight), CV_8UC1);
// which is why we also set this constant to 8
const int BACKBUFFER_BITSPERPIXEL = 8;
// later on, when we get the frame as usual:
CameraLibrary::Frame * pFrame = pMyCam->GetFrame();
// as usual, check pFrame against NULL, and then the main call:
pFrame->Rasterize(camWidth, camHeight, matFrame.step, BACKBUFFER_BITSPERPIXEL, matFrame.data);
// now we can do everything we want with matFrame, for example just:
cv::imshow("My Window Name", matFrame);
// as always, don't forget this:
pFrame->Release();
If you want the frame as 3-channel color RGB matrix (for further processing), use:
Code: Select all
// 3 channels
cv::Mat matFrame(cv::Size(camWidth, camHeight), CV_8UC3);
// 3*8 = 24
const int BACKBUFFER_BITSPERPIXEL = 24;
Hope this helps, feel free to comment etc.
Linus