#pragma package <opencv>
#endif
+#define CV_NO_BACKWARD_COMPATIBILITY
+
#ifndef _EiC
// motion templates sample code
#include "cv.h"
double count;
double angle;
CvPoint center;
- double magnitude;
+ double magnitude;
CvScalar color;
// allocate images at the beginning or
buf = (IplImage**)malloc(N*sizeof(buf[0]));
memset( buf, 0, N*sizeof(buf[0]));
}
-
+
for( i = 0; i < N; i++ ) {
cvReleaseImage( &buf[i] );
buf[i] = cvCreateImage( size, IPL_DEPTH_8U, 1 );
cvReleaseImage( &orient );
cvReleaseImage( &segmask );
cvReleaseImage( &mask );
-
+
mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
cvZero( mhi ); // clear MHI at the beginning
orient = cvCreateImage( size, IPL_DEPTH_32F, 1 );
silh = buf[idx2];
cvAbsDiff( buf[idx1], buf[idx2], silh ); // get difference between frames
-
+
cvThreshold( silh, silh, diff_threshold, 1, CV_THRESH_BINARY ); // and threshold it
cvUpdateMotionHistory( silh, mhi, timestamp, MHI_DURATION ); // update MHI
cvCvtScale( mhi, mask, 255./MHI_DURATION,
(MHI_DURATION - timestamp)*255./MHI_DURATION );
cvZero( dst );
- cvCvtPlaneToPix( mask, 0, 0, 0, dst );
+ cvMerge( mask, 0, 0, 0, dst );
// calculate motion gradient orientation and valid orientation mask
cvCalcMotionGradient( mhi, mask, orient, MAX_TIME_DELTA, MIN_TIME_DELTA, 3 );
-
+
if( !storage )
storage = cvCreateMemStorage(0);
else
cvClearMemStorage(storage);
-
+
// segment motion: get sequence of motion components
// segmask is marked motion components map. It is not used further
seq = cvSegmentMotion( mhi, segmask, storage, timestamp, MAX_TIME_DELTA );
{
IplImage* motion = 0;
CvCapture* capture = 0;
-
+
if( argc == 1 || (argc == 2 && strlen(argv[1]) == 1 && isdigit(argv[1][0])))
capture = cvCaptureFromCAM( argc == 2 ? argv[1][0] - '0' : 0 );
else if( argc == 2 )
if( capture )
{
cvNamedWindow( "Motion", 1 );
-
+
for(;;)
{
- IplImage* image;
- if( !cvGrabFrame( capture ))
+ IplImage* image = cvQueryFrame( capture );
+ if( !image )
break;
- image = cvRetrieveFrame( capture );
- if( image )
+ if( !motion )
{
- if( !motion )
- {
- motion = cvCreateImage( cvSize(image->width,image->height), 8, 3 );
- cvZero( motion );
- motion->origin = image->origin;
- }
+ motion = cvCreateImage( cvSize(image->width,image->height), 8, 3 );
+ cvZero( motion );
+ motion->origin = image->origin;
}
update_mhi( image, motion, 30 );
return 0;
}
-
+
#ifdef _EiC
main(1,"motempl.c");
#endif