18 Jul 2019
Opencv 3 installation, Difference between Frames and Averaging Frames
Opencv 3 installation on windows 10 and configure with visual studio 2012
Step1:Download windows version of opencv from www.opencv.org
Step2: Extract into a folder
Step3: Configure opencv with Visual studio
Set envirenment Vairable variable name: OPENCV3_DIR value: D:\\development\opencv\build\x86\vc11 Set Path: %OPENCV_DIR%\bin
Configure visual studio for opencv project C/C++
additional include directories $(OPENCV3_DIR)\..\..\include
linker additional include directories $(OPENCV3_DIR)\lib
Input opencv_world300d.lib opencv_world300.lib opencv_ts300.lib opencv_ts300d.lib
Find difference between frames
The following openCV code will help you to check changes between two frames and display result in a window.
CvCapture* capture; Mat pFrame; Mat cFrame; capture = cvCaptureFromAVI("video.avi"); cvNamedWindow( "video", CV_WINDOW_AUTOSIZE ); if( capture ) { while( 1 ) { pFrame = cFrame.clone(); cFrame = cvQueryFrame( capture ); if( pFrame.empty() ){ pFrame=cFrame.clone(); } if(cFrame.empty()) break; Mat diff = cFrame-pFrame; imshow( "video", diff ); waitKey(1); } } cvDestroyWindow("video");
Averaging Specified Number of Frame in OpenCV
The following OpenCV code helps you to find average frame model for background subtraction purpose. This code is tested on EWAP pedestrian data set. An average frame is extracted and upload below.//Add source of video and name VideoCapture cap("myVid.avi"); if(!cap.isOpened()){ cout<<"Capture Not Opened"<<endl; } //Number of frames to take average of int count = 0; const int width = cap.get(CV_CAP_PROP_FRAME_WIDTH); const int height = cap.get(CV_CAP_PROP_FRAME_HEIGHT); Mat frame, frame32f; Mat resultframe = Mat::zeros(height,width,CV_32FC3); while(1) { cap>>frame; if(frame.empty()){ cout<<"Capture Finished"<