Question regarding OpenCV's motion detection functions

Ask questions on using Emgu CV with C++
Post Reply
Sodrohu
Posts: 2
Joined: Wed Jul 08, 2009 2:49 am

Question regarding OpenCV's motion detection functions

Post by Sodrohu » Wed Jul 08, 2009 4:20 am

I'm a beginner starting on OpenCV, and right now I'm toying with the motion representation, doing some codings using UpdateMotionHistory andCalMotionGradient. Currently what I want to do is, from a thermal video, do image thresholding and detection of humans.

The thresholding is easier, or at least not a greater concern now. What I'm stuck with right now is using the UpdateMotionHistory and CalMotionGradient functions.

From what I understand, videos are just a sequence of images. I don't want to process videos first (neeed to learn how to first) so for the time being I tested the functions on five images, already thresholded and depicting motion.

The problem is that, when using UpdateMotionHistory the five images appear as intended, but the faded out images in each window are not there. It's like the thresholding has no gradual value, differentiating between only black and white.

Can anyone please look up my program and see what's wrong?

I'm using Microsoft visual C++ 2005 BTW.

Code: Select all

#include "cxcore.h"
#include "conio.h"
#include "iostream"
#include "stdafx.h"
#include "ipl.h"
#include "cv.h"
#include "highgui.h"
#include <fstream>
#include "ipl.h"
#include "cv.h"
#include "highgui.h"

IplImage* image1;
IplImage* image2;
IplImage* image3;
IplImage* image4;
IplImage* image5;
IplImage* image6;
IplImage* image7;

IplImage* thresh;
IplImage* mhimage;
IplImage* mask;
IplImage* orient;

//double time = 1000;
double duration = 5;
//double MAX_TIME_DELTA;
//double MIN_TIME_DELTA;

int silhouette();
int mhi1();
int mhi2();
int mhi3();
int mhi4();
int mhi5();

int main ()
{
	image1 = cvLoadImage("image5.jpg",0);
	image2 = cvLoadImage("image6.jpg",0);
	image3 = cvLoadImage("image7.jpg",0);
	image4 = cvLoadImage("image8.jpg",0);
	image5 = cvLoadImage("image9.jpg",0);
	image6 = cvLoadImage("image1.jpg",0);
	image7 = cvLoadImage("image2.jpg",0);

	thresh = cvCreateImage(cvSize(image7->width, image7->height), IPL_DEPTH_8U, 1);

	mhimage = cvCreateImage(cvSize(image1->width, image1->height), IPL_DEPTH_32F, 0);
	mask = cvCreateImage( cvSize(image1->width, image1->height), IPL_DEPTH_8U, 1 );
	orient = cvCreateImage( cvSize(image1->width, image1->height), IPL_DEPTH_32F, 1);

	
	cvNamedWindow( "Silhouette", 1);
	cvShowImage( "Silhouette", thresh);
	cvSaveImage( "Silhouette.jpg", thresh);	

	mhi1();
	mhi2();
	mhi3();
	mhi4();
	mhi5();
	
	cvWaitKey (0);

	return (0);
}


int mhi1()
{
	cvUpdateMotionHistory (image01, mhimage, 10, duration);
	cvNamedWindow( "MHI1", 1);
	cvShowImage( "MHI1", mhimage);
	//cvSaveImage( "MHI1.jpg", mhimage);	
	return 1;
}

int mhi2()
{
	cvUpdateMotionHistory (image02, mhimage, 20, duration);
	cvNamedWindow( "MHI2", 1);
	cvShowImage( "MHI2", mhimage);
	//cvSaveImage( "MHI2.jpg", mhimage);	
	return 1;
}


int mhi3()
{
	cvUpdateMotionHistory (image03, mhimage, 30, duration);
	cvNamedWindow( "MHI3", 1);
	cvShowImage( "MHI3", mhimage);
	//cvSaveImage( "MHI3.jpg", mhimage);
	return 1;
}

int mhi4()
{
	cvUpdateMotionHistory (image04, mhimage, 40, duration);
	cvNamedWindow( "MHI4", 1);
	cvShowImage( "MHI4", mhimage);
	//cvSaveImage( "MHI4.jpg", mhimage);
	return 1;
}

int mhi5()
{
	cvUpdateMotionHistory (image05, mhimage, 50, duration);
	cvNamedWindow( "MHI5", 1);
	cvShowImage( "MHI5", mhimage);
	//cvSaveImage( "MHI5.jpg", mhimage);
	return 1;
}

canming
Site Admin
Posts: 1036
Joined: Thu Feb 28, 2008 4:16 pm

Re: Question regarding OpenCV's motion detection functions

Post by canming » Thu Jul 09, 2009 10:29 pm

If you download the SouceAndExample.zip file from sourceforge, there is a C# MotionDection example.

To see it in action, see this video posted by Paul.K
http://www.youtube.com/watch?v=2ZbDbbkp51I

Sodrohu
Posts: 2
Joined: Wed Jul 08, 2009 2:49 am

Re: Question regarding OpenCV's motion detection functions

Post by Sodrohu » Sun Jul 12, 2009 8:30 pm

canming wrote:If you download the SouceAndExample.zip file from sourceforge, there is a C# MotionDection example.

To see it in action, see this video posted by Paul.K
http://www.youtube.com/watch?v=2ZbDbbkp51I
Thanks. I couldn't find the links however.
I can look at the code and try to understand it, but I'm no good in C# programming. Can you or anyone post examples of motion detection using C++ algorithm?

EDIT: got the links and code, but still don't understand it.

Wendy88
Posts: 1
Joined: Wed Jan 29, 2014 2:03 am

Re: Question regarding OpenCV's motion detection functions

Post by Wendy88 » Wed Jan 29, 2014 2:54 am

This information is very constructive for correct planning. I like your work for providing information to the other.
I’ve been researching this topic for a few hours and found this post pretty helpful. Thanks for compiling the info in one spot.

Marie441
Posts: 1
Joined: Thu Nov 05, 2015 12:56 am

Re: Question regarding OpenCV's motion detection functions

Post by Marie441 » Thu Nov 05, 2015 12:58 am

I'm a beginner starting on OpenCV, and right now I'm toying with the motion representation, doing some codings using UpdateMotionHistory andCalMotionGradient. Currently what I want to do is, from a thermal video, do image thresholding and detection of humans.

Post Reply