I'm updating samples/c/motempl.c to OCV 2.3 and I'm a bit puzzled by the cv::updateMotionHistory() method. I create the history following what I've seen in motempl.c:
history = cv::Mat::zeros(640, 480, CV_32FC1);
Then, I call updateMotionHistory() like so:
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);
Seems ok, but it's always throwing 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 history to CV_8U which gets me:
OpenCV Error: Unsupported format or combination of formats () in cvUpdateMotionHistory
Following on the sample, where there's this:
mhi = cvCreateImage( size, IPL_DEPTH_32F, 1 );
I get why the history needs to be a float image, I'm just not sure how to call this method with matrices rather than IplImage instances. Thanks!
Ok, so I figured this out, right after making this a bounty and I figured I should post the answer, not sure what the etiquette on that is. History needs to be CV_32FC1:
history = cv::Mat::zeros(480, 640, CV_32FC1);
The rows/cols initializing Mat are a little unintuitive too:
cv::Mat diff = cv::Mat::zeros(480, 640, CV_8UC1); // not 640,480
Then:
cv::updateMotionHistory( diff, history, getElapsedSeconds(), MHI_DURATION);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With