Make 2 frame having time interval in video using OpenCV(Example source code)

This code is example source code that made 2 frame having time interval.
For example : this code made 2 images t time and t-x time in video stream.

This images shows origin image(Left), T time Image(center), T-x time Image(right)

This is example source code
You can control time delay frame using DELAY_T macro variable.

#define DELAY_T 30

void main()

  //image class      
    IplImage* image = 0;   
 IplImage* image1 = 0;    
 IplImage* image2 = 0;    

    //camera point   
 CvCapture * capture = cvCreateFileCapture("RunF.avi"); //cvCaptureFromCAM(0); //cvCreateFileCapture("1.avi");

 //make window   
    cvNamedWindow( "t");  
 cvNamedWindow( "t-1");   
 int one_zero=0;
    while(1) {   

  //capture a frame form cam   
        if( cvGrabFrame( capture ) == 0)
  image = cvRetrieveFrame( capture );

  if(image2 == 0)   
   //image = cvRetrieveFrame( capture );
   image1  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);  
            image2  = cvCreateImage(cvSize(image->width, image->height), image->depth, image->nChannels);   

  //show window   
  cvShowImage( "Origin", image);

  if(one_zero == 0 )
   //copy to image class
   memcpy(image2->imageData, image1->imageData, sizeof(char)*image->imageSize );
   //image = cvRetrieveFrame( capture );
   memcpy(image1->imageData, image->imageData, sizeof(char)*image->imageSize );

   //show window   
   cvShowImage( "t", image1 );
   cvShowImage( "t-1", image2 );


  //Time Delay
  if( (one_zero%DELAY_T) == 0)

        if( cvWaitKey(10) >= 0 )   
    //release capture point   
    cvReleaseCapture( &capture );

    //close the window   

 //release Images


Thank you.


Popular posts from this blog

OpenCV Stitching example (Stitcher class, Panorama)

(OpenCV Study) Background subtractor MOG, MOG2, GMG example source code (BackgroundSubtractorMOG, BackgroundSubtractorMOG2, BackgroundSubtractorGMG)

Example source code of extract HOG feature from images, save descriptor values to xml file, using opencv (using HOGDescriptor )

Real-time N camera stitching Class.

8 point algorithm (Matlab source code) / The method to get the Fundamental Matrix and the Essential matrix

Optical Flow sample source code using OpenCV

Video Stabilization example source code, (using cvFindHomography, cvWarpPerspective functions in openCV)

(OpenCV Study) calcOpticalFlowFarneback example source code ( dense optical flow )

yuv422(YUYV) to RGB and RGB to yuv422(YUYV), (Using OpenCV and TBB)

(C, C++) TinyXML , xml read & write