0

I am using PS3 camera with opencv it works with PByte data type.Gives PByte as frame result.In SDK samples they use IplImage.I want use Mat instead IplImage.But i cant convert PByte to Mat.How can i convert PByte to Mat ? Example In SDK

     IplImage *pCapImage;
    PBYTE pCapBuffer = NULL;
    cvGetImageRawData(pCapImage, &pCapBuffer);
    while(_running)
        {
            cvGetImageRawData(pCapImage, &pCapBuffer);
            CLEyeCameraGetFrame(_cam, pCapBuffer, (i==0)?2000:0);
}
//Function from SDK

IMPORT(bool) CLEyeCameraGetFrame(CLEyeCameraInstance cam, PBYTE pData, int waitTimeout = 2000);

//MyCode //I use 2 camera.

    cv::Mat pCapImage[2];
    PBYTE pCapBuffer = NULL;
    while(_running){

        for (int i = 0; i < 2; i++)
                {
                                  //trying convert
                    pCapImage[i] = cv::Mat (cvSize(w, h), 4, &pCapBuffer,IPL_DEPTH_8U).clone();

                    CLEyeCameraGetFrame(_cam[i], pCapBuffer);
                }

                Mat pCapImageMatL = pCapImage[0];
                Mat pCapImageMatR = pCapImage[1];
                imshow(_windowNameL, pCapImageMatL);
                imshow(_windowNameR, pCapImageMatR);
}
user1924375
  • 10,581
  • 6
  • 20
  • 27

2 Answers2

1

Given that you have successfully converted PBYTE to IplImage *, you can further convert it to cv::Mat as follows:

IplImage *pCapImage;  // this is the IplImage * that you have converted from PBYTE 
cv::Mat pCapImageMat(pCapImage);
cvReleaseImage(&pCapImage); // free the previous memory
herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
  • can i make this without using pCapImage. I just want pCapBuffer to Mat directly.Because in documentation i see IplImage need manuel memory management. – user1924375 Sep 30 '15 at 16:16
  • @user1924375 Then just release previous memory. It's easy. Please check the updated answer. – herohuyongtao Sep 30 '15 at 16:34
1

If you are using OpenCV 3, IPlImage has been deprecated. So @herohuyongtao answer won't work.

In this case, the workaround is

cv::Mat frame;
frame = cv::cvarrToMat(pCapImage);
gibertoni
  • 1,368
  • 12
  • 21
  • can i make this without using pCapImage. I just want pCapBuffer to Mat directly.Because in documentation i see IplImage need manuel memory management. – user1924375 Sep 30 '15 at 16:16