read successive frames OpenCV using cvQueryframe

前端 未结 3 1694
囚心锁ツ
囚心锁ツ 2020-12-06 08:08

I have a basic question in regards to cvQueryFrame() in OpenCV.

I have the following code:

IplImage *frame1,*frame2;
frame1 = cvQueryFrame(capture         


        
3条回答
  •  清歌不尽
    2020-12-06 08:59

    ok following from Laurent's answer: I believe the key is cvCloneImage(). cvCloneImage creates a new copy of the original image including the header, ROI, imageData etc. and then points frame2 to this new data.

    Since cvQueryFrame is a wrapper for cvGrabFrame & cvRetrieveFrame together I didn't want to split up the functions, so with a small modification I can still use cvQueryFrame.

    Below is my modified solution.

    
    IplImage *frame = cvQueryFrame(capture); //to read properties of frame.
    IplImage *frame2 = NULL;

    while (1){ if(frame2) frame = cvCloneImage(frame2); // copy image to allow grabbing next frame frame2 = cvQueryFrame(capture); //read next frame if(!frame2) break; //if frame cannot be read, EOF so break from loop }

    I hope you understand what I've done here. Feel free to ask any more questions.

提交回复
热议问题