Pt Grey Flycapture
Hi all,
New to the whole google groups thing so if I'm posting in the wrong group let me know!
I'm currently developing a Stereo V-SLAM application and run into some problem with grabbing images from a pair of pt grey FMVU-13S2c cameras.
I am running Codeblocks on Ubuntu using c++ and the Flycapture api.
As i have to capture from two cameras my problem lies in the fact that when i have 2 cameras connected the image from the second camera gets corrupted.
code as follows:
#include "FlyCapture2.h"
#include <iostream>
#include <sstream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace FlyCapture2;
using namespace std;
using namespace cv;
int main(int /*argc*/, char ** /*argv*/)
{
//defines
FlyCapture2::Image leftRaw;
FlyCapture2::Image leftRgb;
cv::Mat imgLeft;
FlyCapture2::Image rightRaw;
FlyCapture2::Image rightRgb;
cv::Mat imgRight;
unsigned int rowBytesL;
unsigned int rowBytesR;
const int k_numImages = 100;
FlyCapture2::Error error;
FlyCapture2::BusManager busMgr;
FlyCapture2::Camera LeftCam;
FlyCapture2::Camera RightCam;
FlyCapture2::PGRGuid guidL;
FlyCapture2::PGRGuid guidR;
//Connect left camera and start capture.
busMgr.GetCameraFromIndex(0, &guidL);
LeftCam.Connect(&guidL);
LeftCam.StartCapture();
//connect right camera and start capture
busMgr.GetCameraFromIndex(1, &guidR);
RightCam.Connect(&guidR);
RightCam.StartCapture();
//create windows to display images.
namedWindow("LeftImage",WINDOW_AUTOSIZE);
namedWindow("RightImage",WINDOW_AUTOSIZE);
//capture images
for (int i = 0; i < k_numImages ;i++)
{
//capture images from cameras
LeftCam.RetrieveBuffer(&leftRaw);
RightCam.RetrieveBuffer(&rightRaw);
//convert captured images to BRG format then to openCV Mat format for display
//convert left
leftRaw.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &leftRgb);
rowBytesL = (double)leftRgb.GetDataSize()/(double)leftRgb.GetRows();
imgLeft = cv::Mat(leftRgb.GetRows(), leftRgb.GetCols(), CV_8UC3, leftRgb.GetData(),rowBytesL);
//convert right
rightRaw.Convert( FlyCapture2::PIXEL_FORMAT_BGR, &rightRgb);
rowBytesR = (double)rightRgb.GetDataSize()/(double)rightRgb.GetRows();
imgRight = cv::Mat(rightRgb.GetRows(), rightRgb.GetCols(), CV_8UC3, rightRgb.GetData(),rowBytesR);
//SaveImages
ostringstream leftFileName;
leftFileName << "LeftImage-" << "-" << i << ".jpg";
leftRgb.Save(leftFileName.str().c_str());
ostringstream rightfilename;
rightfilename << "RightImage-" << "-" << i << ".jpg";
rightRgb.Save(rightfilename.str().c_str());
//display images
imshow("LeftImage",imgLeft);
imshow("RightImage",imgRight);
waitKey(1);
}
//
// Stop streaming for each camera
//
LeftCam.StopCapture();
LeftCam.Disconnect();
RightCam.StopCapture();
RightCam.Disconnect();
cout << "Press Enter to exit..." << endl;
cin.ignore();
return 0;
}
If i connect each camera individually or stop capturing and disconnect the camera object before capturing the image from the other camera both images are fine.
Sound familiar to anyone??
Thanks,
Patrick
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)