OpenCV VideoCapture.Open to RGB buffer Problem in MAC Mountain Lion

asked 2013-01-09 04:47:57 -0500

Hello,

I have a problem with format of the camera buffer. When I get a cv::Mat image frame, the image is RGB24 format, but the step is like RGB32 format???

For example, in a 320x240 capture format, the cv::Mat obtained is

each ROW: 320 * 3([R,G,B] pixel) bytes and in the end of the ROW there is 3201(PADDING???) bytes. This is equal to STEP =3204.

I need to format the buffer to obtain a normal RGB Buffer using this function:

    void VideoCaptureOCV::getFrame(uchar *pImg)
{
    if (m_initialized && m_cap && pImg)
    {
        cv::Mat img;
        *m_cap >> img;

                    int cvIndex, cvLineStart;
                   cvIndex = 0; cvLineStart = 0;
                  for (int y = 0; y < img.rows; y++)
                  {
                        memcpy(pImg,img.datastart+cvLineStart,m_width*3);
                        pImg=pImg+m_width*3;
                        cvLineStart += img.step1();   //jump the width*1 padding
                  }
           }
}

there is any opencv parameter for the open device or the cv::Mat that avoid this problem?

thanks.

edit retag flag offensive close merge delete