Archive Video Episode

Xvid
Mov

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <iostream>
#include <cstdlib>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "cv.h"
#include "highgui.h"
 
int main(void)
{
 
//buffered frame and result
IplImage* pictureBuffer;
IplImage* pictureResult;
 
CvCapture* capture = cvCaptureFromCAM( CV_CAP_ANY );
//CvCapture* capture = cvCaptureFromAVI("infile.avi");
 
if( !capture ) {
  std::cout<< "ERROR: capture is NULL" << std::endl;
  getchar();
  return -1;
}
 
//Create a window in which the captured images will be presented
cvNamedWindow( "mywindow", CV_WINDOW_AUTOSIZE );
IplImage* frame = cvQueryFrame( capture );
 
//initialize the picture
pictureBuffer = cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
pictureResult = cvCreateImage(cvSize(frame->width,frame->height),IPL_DEPTH_8U,3);
 
//buffer the previous frame. Use cvCopy instead of cvCloneImage. Clone Image will cause a memeory leak
cvCopy(frame,pictureBuffer);
 
//Show the image captured from the camera in the window and repeat
while( 1 ) {
 
  //Get one frame
  IplImage* frame = cvQueryFrame( capture );
 
  if( !frame ) {
    std::cout<< "ERROR: frame is null..." << std::endl;
    getchar();
    break;
  }
 
  //Subtract the new frame from the previous frame
  cvAbsDiff(frame, pictureBuffer, pictureResult);
 
  cvShowImage( "mywindow", pictureResult );
  //Do not release the frame!
 
  //If ESC key pressed, Key=0x10001B under OpenCV 0.9.7(linux version),
  //remove higher bits using AND operator
  if( (cvWaitKey(10) & 255) == 27 ) break;
}
 
//Release the capture device
cvReleaseCapture( &capture );
cvDestroyWindow( "mywindow" );
return 0;
}