简体   繁体   中英

Saving video as series of images opencv

This question is in continuation of error-in-opencv-code-for-motion-detection . The editted code works without any errors but the output video is not created,it is of zero bytes!What is wrong in this?Also,the bounding box created for motion detection never really captures the motion that is, it does not do what it originally claimed to do.Am I misunderstanding something about the objective of thie code?So, here are my questions:

  1. How to rectify the creation and save the video?
  2. What needs to be modified to detect motion and track it?
  3. How to convert the video to a series of numbered jpg images from each frame and vice-versa.

Here is the code which you can work with to frame a video as a set of images.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "cv.h"
#include <highgui.h>
#include "cxcore.h" 

int main( int argc, char** argv )
{    
     CvCapture *capture = cvCaptureFromAVI("E:\\Myvideo.avi");
             if(!capture) 
    {
        printf("!!! cvCaptureFromAVI failed (file not found?)\n");
        return -1; 
    }

    int fps = (int) cvGetCaptureProperty(capture, CV_CAP_PROP_FPS);

    printf("* FPS: %d\n", fps);

    IplImage* frame = NULL;
    int frame_number = 0;
    char key = 0;   

    while (key != 'q') 
    {
        // get frame 
        frame = cvQueryFrame(capture);       
        if (!frame) 
        {
            printf("!!! cvQueryFrame failed: no frame\n");
            break;
        }       




        // quit when user press 'q'
        key = cvWaitKey(1000 / fps);
    }

    // free resources
    cvReleaseCapture(&capture);

    return 0;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM