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:[email protected]/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:
But it should be this:
Please help me! Thanks.
before doing anything else, - please update your opencv . 2.3.1 is stone age, and must not be used.
I can't update opecv because i working in visual studio 2005.
can't you just imwrite() the image to bmp, without using cimg at all ? it all looks unnesserarily complicated.
No, because I have a lot of cameras, not all cameras work with opencv. And before writing to the disk, I must add text to image bmp.
I don't really understand your last comment. If you have cameras that don't work with OpenCV, then you can't use the code with them, and therefore using cimg inside the code makes no difference. Moreover, you can add text to the image before saving and still use imwrite()
This design. I have the function of receiving a frame (char*) this function adds a text in frame, and writes in the BMP file.
Once again, you can add text to a frame and save it as bmp file without using cimg. If we're not understanding your problem, please give more details
I can't update opecv because i working in visual studio 2005. To me that seems to be bullshit. Why would you not be able to do it? You will need to rebuild opencv yourself, but it should work just fine.
Once again, you can add text to a frame and save it as bmp file without using cimg. If we're not understanding your problem, please give more details.Of course I can use Opencv but then it will not match the design of the program. If it does not I will use Opencv.
To be honest I don't know what you're asking or what you want us to resolve, and I don't think anyone does at this point.