• Pt Grey Flycapture

    From lentfer.patrick.86@gmail.com@21:1/5 to All on Fri Apr 13 21:17:29 2018
    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)
  • From yanru wang@21:1/5 to All on Thu Oct 25 19:21:13 2018
    在 2018年4月14日星期六 UTC+8下午12:17:32,lentfer.p...@gmail.com写道:
    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

    Hi Patrick,

    I had more 2 Pt Grey cameras connected successfully. The code to capture the images is wrote with matlab script by another guy from my previous group. I couldn't help you with your code, but I do know the conflicts between cameras coming from the trigger
    timing sequence. I need to reset the timing everytime when I reconnect the cameras. So maybe notice the trigger timing.

    Thanks,

    Yanru

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)