Skip to main content

Load a Video in OpenCV


#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include<opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>

int main(int argc, char *argv[])
{
IplImage *frame;
int key = 'a';
/* supply the AVI file to play */
if(argc<2){
printf("Usage: main <video-file-name>.avi\n\7");
exit(0);
}

/* load the AVI file */
CvCapture *capture = cvCaptureFromAVI( argv[1] );
/* always check */
if( !capture ) return 1;

/* get fps, needed to set the delay */
int fps = ( int )cvGetCaptureProperty( capture, CV_CAP_PROP_FPS );
/* display video */
cvNamedWindow( "video", 0 );
while( key != 'q' ) {

/* get a frame */
frame = cvQueryFrame( capture );
/* always check */

if( !frame ) break;
/* display frame */
cvShowImage( "video", frame );
/* quit if user press 'q' */
cvWaitKey( 1000 / fps );
}

/* free memory */
cvReleaseCapture( &capture );
cvDestroyWindow( "video" );
return 0;
}

To Run Main write the filename.extension in the arguments. make sure that the AVI file is in RAW VIDEO form. see this link for conversion using FFMPEG the same process works for OPEN


Update:
http://opencv.willowgarage.com/wiki/VideoCodecs

using command line tool mencoder
mencoder.exe testReal.avi -ovc raw -vf format=i420 -o out.avi -nosound

Comments

Popular posts from this blog

Computing Entropy of an image (CORRECTED)

entropy is a measure of the uncertainty associated with a random variable. basically i want to get a single value representing the entropy of an image. 1. Assign 255 bins for the range of values between 0-255 2. separate the image into its 3 channels 3. compute histogram for each channel 4. normalize all 3 channels unifirmely 5. for each channel get the bin value (Hc) and use its absolute value (negative log is infinity) 6. compute Hc*log10(Hc) 7. add to entropy and continue with 5 until a single value converges 5. get the frequency of each channel - add all the values of the bin 6. for each bin get a probability - if bin 1 = 20 bin 2 = 30 then frequency is 50 and probability is 20/50 and 30/50 then compute using shannon formula  REFERENCE: http://people.revoledu.com/kardi/tutorial/DecisionTree/how-to-measure-impurity.htm class atsHistogram { public:     cv::Mat DrawHistogram(Mat src)     {      ...

Template Matching using OpenCV internal function

For this example we need to add the following to the linker dependencies: opencv_core220d.lib opencv_highgui220d.lib opencv_imgproc220d.lib Code: #include <stdlib.h> #include <stdio.h> #include <math.h> #include <string.h> #include<opencv2\opencv.hpp> #include <opencv2\highgui\highgui.hpp> int main(int argc, char *argv[]) { IplImage *img; IplImage *tpl; IplImage *res; CvPoint minloc, maxloc; double minval, maxval; int img_width, img_height; int tpl_width, tpl_height; int res_width, res_height; /* check for arguments */ if( argc < 3 ) { printf( "Usage: template_match <reference> <template>\n" ); return 1; } /* load reference image */ img = cvLoadImage( argv[1], CV_LOAD_IMAGE_COLOR ); /* always check */ if( img == 0 ) { printf( "Cannot load file %s!\n", argv[1] ); return 1; } /* load template image */ tpl = cvLoa...

Nose Tracking using Kalman Filter and Viola and Jones Classifier

class atsKalman { public:     atsKalman()     {         KalmanFilter KF(4, 2, 0);         Mat_<float> state(4, 1); /* (x, y, Vx, Vy) */         Mat processNoise(4, 1, CV_32F);         Mat_<float> measurement(2,1);         measurement.setTo(Scalar(0));         KFs = KF;         measurements = measurement;     }     void setKalman(int x, int y)     {         KFs.statePre.at<float>(0) = x;         KFs.statePre.at<float>(1) = y;         KFs.statePre.at<float>(2) = 0;         KFs.statePre.at<float>(3) = 0;       ...