How to call cv :: updateMotionHistory () in OpenCV

I am updating samples / c / motempl.c to OCV 2.3 and I am a bit puzzled by the cv :: updateMotionHistory () method. I am creating a story following what I saw in motempl.c:

history = cv::Mat::zeros(640, 480, CV_32FC1); 

Then I call updateMotionHistory () as follows:

 cv::Mat diff = cv::Mat::zeros(640, 480, CV_8U); if(prevFrame.size().width != 0) { cv::absdiff(currentFrame, prevFrame, diff); } else { return; } cv::updateMotionHistory( diff, history, getElapsedSeconds(), MHI_DURATION); 

Everything seems to be in order, but he always throws the following:

 OpenCV Error: Sizes of input arguments do not match () in cvUpdateMotionHistory 

Both matrices are the same size, 640, 480, but just for fun, I tried changing the history to CV_8U, which gets me:

 OpenCV Error: Unsupported format or combination of formats () in cvUpdateMotionHistory 

Following the example where it is:

  mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 ); 

I understand why the story should be a floating image, I'm just not sure how to call this method using matrices, not IplImage instances. Thanks!

+7
source share
1 answer

Well, that’s why I understood this right after I made it generous, and I decided that I should publish the answer, but I’m not sure what etiquette is. History should be CV_32FC1:

 history = cv::Mat::zeros(480, 640, CV_32FC1); 

The lines / cols initializing Mat are also a bit unintuitive:

 cv::Mat diff = cv::Mat::zeros(480, 640, CV_8UC1); // not 640,480 

Then:

 cv::updateMotionHistory( diff, history, getElapsedSeconds(), MHI_DURATION); 
+6
source

All Articles