// Captures from avi and builds a single image that is avarage of the avi. // Author: Baris Evrim Demiroz b.evrim[at]gmail.com #include #include #include #include #include #include int main( int argc, char** argv) { double pr,scale=0.004; int i,j,total=1,N,progress=0; char* filename= argc == 2 ? argv[1] : (char*)"zardoz.avi"; IplImage *result = 0,*frame = 0,*out=0; CvCapture* capture = 0; capture = cvCaptureFromFile( filename ); if( !capture ) { fprintf(stderr,"Could not initialize capturing from avi...\n"); return -1; } // grab the empty frame frame = cvQueryFrame( capture ); frame = cvQueryFrame( capture ); if( !frame ) { fprintf(stderr,"Could not capture from avi...\n"); return -1; } N = frame->nChannels; result = cvCreateImage( cvGetSize(frame), IPL_DEPTH_32F, N); cvConvertScale(frame,result,scale,0); cvNamedWindow("X",1); while( frame = cvQueryFrame(capture) ){ pr = cvGetCaptureProperty( capture, CV_CAP_PROP_POS_AVI_RATIO); if( (float)pr*100-progress > 1){ progress = pr*100; printf("[%d%%]\r",progress); } cvShowImage("X",result); cvWaitKey(1); for(i=0;iheight;i++){ for(j=0;jwidth;j++){ CV_IMAGE_ELEM( result, float, i, N*(j) + 0 ) = (float)(CV_IMAGE_ELEM( result, float, i, N*(j) + 0 )*total+CV_IMAGE_ELEM( frame, uchar, i, N*(j) + 0 )*scale )/(total+1); CV_IMAGE_ELEM( result, float, i, N*(j) + 1 ) = (float)(CV_IMAGE_ELEM( result, float, i, N*(j) + 1 )*total+CV_IMAGE_ELEM( frame, uchar, i, N*(j) + 1 )*scale )/(total+1); CV_IMAGE_ELEM( result, float, i, N*(j) + 2 ) = (float)(CV_IMAGE_ELEM( result, float, i, N*(j) + 2 )*total+CV_IMAGE_ELEM( frame, uchar, i, N*(j) + 2 )*scale )/(total+1); } } total++; } out = cvCreateImage( cvGetSize(result), IPL_DEPTH_8U, N); cvConvertScale(result,out,1/scale,0); cvSaveImage("zardoz.png",out); cvReleaseCapture(&capture); return 0; }