0

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.

FvD
  • 1,286
  • 13
  • 25
  • 1
    If you are using c++ and opencv use the c++ interface. The code will be nicer. Use Mat instead of IplImage and VideoCapture instead of Camera. Declear the varibles outside the loop to improve memory managment. – Xale May 23 '13 at 07:49
  • I think I need to use the Camera class to get the metadata of the image. I'm unsure of how to use memcpy with Mat or if there's a more appropriate function. The loop was just careless copypasting for this snippet. – FvD May 23 '13 at 08:35
  • I will accept my answer tomorrow, this is solved. Also fixed an embarrassing memory leak in the question's code. – FvD May 24 '13 at 10:17

1 Answers1

1

Alright: you have to activate the frame count in advance, like most if not all other embedded image metadata. You can do it with the EmbeddedImageInfo object like this (if you insert these lines after the call to connect the camera):

EmbeddedImageInfo EmbeddedInfo;
cam.GetEmbeddedImageInfo(&EmbeddedInfo);

if (EmbeddedInfo.frameCounter.available == true) {
    EmbeddedInfo.frameCounter.onOff = true; 
}
else {
    cout << "Framecounter is not available!" << endl;
}

cam.SetEmbeddedImageInfo(&EmbeddedInfo);

The sample ExtendedShutterEx provides basically this code snippet more generally with error checking and for multiple cameras.

BenMorel
  • 34,448
  • 50
  • 182
  • 322
FvD
  • 1,286
  • 13
  • 25