Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to read pixel every frame?

Hello!

I using Opencv 2.3.1 and cimg!

I need to read every frame with IP camera and record it into the BMP file.

I have the following code:

       Mat frame;
    VideoCapture cam("rtsp://admin:admin@192.168.2.228/defaultPrimary?streamType=u");
    while(true)
    {   
        if (!cam.read(frame))
            continue;

        count++;
        cimg_library::CImg<unsigned char>* m_frameData = new cimg_library::CImg<unsigned char>(1920, 1080, 1 , 3);

        if (frame.data)
        {
            cvtColor(frame, frameRGB, CV_BGR2RGB);
            uchar* pixelsRGB = frameRGB.data;

            for (unsigned int x = 0; x < frame.rows; x++)               
            {
                for (unsigned int y = 0; y < frame.cols; y++)   
                {                       
                    m_frameData->atXYZC(x,y,0,0) = (int) pixelsRGB[ y + x];
                    m_frameData->atXYZC(x,y,0,1) = (int)pixelsRGB [ y + x + 1];
                    m_frameData->atXYZC(x,y,0,2) = (int) pixelsRGB[ y + x + 2];
                }
            }

            std::string fileWrite = "C:\\Temp\\out" +count+ ".bmp";             
            m_frameData->save_bmp(fileWrite.c_str());

            delete m_frameData;
     }

When I open the BMP file I get: image description

But it should be this: image description

Please help me! Thanks.