Ask Your Question
0

png Saving with a video camera

asked 2013-02-26 07:14:53 -0600

Lucas gravatar image

Hi,

I'm currently working on a video acquisition project in which I have to save frames from a video camera. My software works when I save frames in bmp format but so as to use less space on the hard drive I would like to save them in png format. But when I change the format my application doesn't work anymore (xxx.exe encountered a problem and needs to close). Then I reduced the code to its minimum to save only one image from the video camera (see code below) and I don't understand why it works perfectly in bmp and bugs in png :

#include "stdafx.h"
#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

int main()
{
    VideoCapture cap(0);
    if(!cap.isOpened())
        return -1;

    Mat frame;
    cap >> frame;
    // Mat frameC;
    // frame.convertTo(frameC,CV_16UC3);
    imwrite("C:\\Frames\\frame.png",frame);

    return 0;
}

It also doesn't work in jpg format. I'm working with Visual Studio 2005 on Windows XP and OpenCV2.1. I tried to convert the image before saving it, but no change (comments in the code) And if I just open and save a png image (without using the video camera) then it works.

Debugging indicates that the problem is in malloc.c (l. 163) :

res = _heap_alloc(size);

And the error is "Unhandled exception at 0x70100fcd in TestOpenCV.exe: 0xC0000005: Access violation reading location 0x00000000" I don't know what is "size" in this function but its type is size_t and its value 32. Then the program stops with the code -1073741819.

I've no idea how to fix this problem or even if it's possible. Maybe the problem comes from the camera or the acquisition card (Intensity Pro from BlackMagicDesign). Any ideas?

Your help or advices are welcome, I'm really stuck with this issue.

Thanks a lot.

Lucas

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2013-02-26 07:57:17 -0600

berak gravatar image

iirc, older opencv versions had sometmes problems writing png or jpeg files, when there was no compression info supplied, so for png:

vector<int> flags; 
flags.push_back(CV_IMWRITE_PNG_COMPRESSION);
flags.push_back(9);  // [0-9]
imwrite("C:\\Frames\\frame.png",frame,flags);

or jpeg:

vector<int> flags; 
flags.push_back(CV_IMWRITE_JPEG_QUALITY);
flags.push_back(99); // [0-99] 
imwrite("C:\\Frames\\frame.jpg",frame,flags);

also, doublecheck if your frame was valid:

cap >> frame;
if ( ! frame.empty() )
{
     // save to disk
}
edit flag offensive delete link more

Comments

I have still the same issue adding compression info. Thanks anyway for advice.

Lucas gravatar imageLucas ( 2013-02-26 08:35:19 -0600 )edit

Moreover when I add flags I can't open a image with imread and save it to png anymore...

Lucas gravatar imageLucas ( 2013-02-26 09:31:19 -0600 )edit

Question Tools

Stats

Asked: 2013-02-26 07:14:53 -0600

Seen: 1,193 times

Last updated: Feb 26 '13