10/17/2012

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("Origin");
    cvNamedWindow( "t");  
 cvNamedWindow( "t-1");   
   
    
 int one_zero=0;
    
    while(1) {   


  //capture a frame form cam   
        if( cvGrabFrame( capture ) == 0)
   break;
  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
  one_zero++;
  if( (one_zero%DELAY_T) == 0)
  {   
   one_zero=0;
  }

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

    //close the window   
    cvDestroyAllWindows();   

 //release Images
 cvReleaseImage(&image1);
 cvReleaseImage(&image2);

}

Thank you.


No comments:

Post a Comment