how to close and reopen videoCapture
Hi,
I want to open and close and open again VideoCapture. I have modify example starter_video.cpp :
int main(int ac, char** av) {
if (ac != 2) {
help(av);
return 1;
}
std::string arg = av[1];
{ // First open
VideoCapture capture(arg);
if (!capture.isOpened())
capture.open(atoi(arg.c_str()));
if (!capture.isOpened()) {
cerr << "Failed to open the video device, video file or image sequence!\n" << endl;
help(av);
return 1;
}
process(capture);
} // First Videocapture must be destroyed here
{//Second Open new object videocapture is allocated here
VideoCapture capture(arg);
if (!capture.isOpened())
capture.open(atoi(arg.c_str()));
if (!capture.isOpened()) {
cerr << "Failed to open the video device, video file or image sequence!\n" << endl;
help(av);
return 1;
}
return process(capture);
}
I can see capture in a window for first opening. For second I have got an error message. Warning and Error message for program :
VIDEOIO ERROR: V4L/V4L2: VIDIOC_S_CROP
press space to save a picture. q or esc to quit
Corrupt JPEG data: 1 extraneous bytes before marker 0xd7
Corrupt JPEG data: 1 extraneous bytes before marker 0xd4
Corrupt JPEG data: 2 extraneous bytes before marker 0xd5
... Corrupt JPEG data: 2 extraneous bytes before marker 0xd7
I press ESC Here
VIDEOIO ERROR: V4L2: Pixel format of incoming image is unsupported by OpenCV
press space to save a picture. q or esc to quit
VIDIOC_STREAMON: Bad file descriptor
Unable to stop the stream.: Bad file descriptor
What's wrong in my program or may be in my linux mint with cinamon install?
Version control: 3.0.0-beta-21-g4b97e8c Thanks for yours helps
I do not really get what you want to do, but before you open the VideoCapture again the second time I think you should close the first one.
Thanks for yours answers. . I have insert some comments in source code. I think that first object videocapture is destroyed. It must be released so. I have run this code on windows 7 64 bit and 32 bit. there is no problem. Have you run this code on linux? If you have done it on linux and there is no problem may be my linux install is not very good.
I run your code in linux and it does not give the errors that you get, so maybe you are right about some fault in your linux installation. Do you have the v4l packages installed, it seems to be related. As for how to release a VideoCapture, it is simple as it sounds just call the .release() attribute on the created object.
Thanks for yours tests v4l is installed because I can see video in a regular window. I have to check my linux installed now. Thanks again