I want to implement a framesafe capture with Point Grey Research cameras. To do that, I want to check if any frames have been missed by any cameras. The wrapper class that I am extending to do this is using the FlyCapture 2 API, so I would like to keep using that if possible.
The PGR FAQ on this question only refers to the old API and IEEE-1394 cameras (the ones I use use USB 3.0). I am trying to use the frame counting functionality previously provided by uiSeqNum through the ImageMetadata object and its embeddedFrameCounter member. However, it always seems to be 0.
I wonder if I am making a stupid mistake along the way or if it's a bug. In any case this code should run if you link the necessary files for OpenCV and Flycapture.
#include<iostream>
#include"opencv2\opencv.hpp"
#include"FlyCapture2.h"
int main() {
BusManager busMgr;
PGRGuid guid;
Camera cam;
Image rawImage, convertedimage;
busMgr.GetCameraFromIndex(0, &guid);
cam.Connect(&guid);
cam.SetVideoModeAndFrameRate(VIDEOMODE_640x480RGB,FRAMERATE_30);
cam.StartCapture();
IplImage* src_img;
while ((waitKey(30) > 0) == false) {
cam.RetrieveBuffer(&rawImage);
ImageMetadata metadata = rawImage.GetMetadata();
cout << "framecount: " << metadata.embeddedFrameCounter << endl;
rawImage.Convert(PIXEL_FORMAT_BGR, &convertedimage);
src_img = cvCreateImage(cvSize(rawImage.GetCols(),rawImage.GetRows()),IPL_DEPTH_8U,3);
memcpy(src_img->imageData, convertedimage.GetData(), convertedimage.GetDataSize());
cvShowImage("Test", src_img);
cvReleaseData(src_img)
}
waitKey(0);
}
As an aside: tips on improving the memory management in this capture loop are appreciated.