Ask Your Question
0

how to close and reopen videoCapture

asked 2015-03-03 03:23:15 -0500

LBerger gravatar image

updated 2015-03-04 01:45:21 -0500

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

edit retag flag offensive close merge delete

Comments

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.

theodore gravatar imagetheodore ( 2015-03-03 09:44:17 -0500 )edit

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.

LBerger gravatar imageLBerger ( 2015-03-04 01:49:58 -0500 )edit

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.

theodore gravatar imagetheodore ( 2015-03-04 04:47:38 -0500 )edit

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

LBerger gravatar imageLBerger ( 2015-03-04 06:33:50 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2016-04-10 11:46:31 -0500

Merl1n gravatar image

You can try my experience. I disabled JPEG and it solved the issue.

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2015-03-03 03:23:15 -0500

Seen: 1,432 times

Last updated: Apr 10 '16