Ask Your Question
1

Motion detection using Java

asked 2013-09-26 02:45:31 -0600

Naval gravatar image

updated 2013-09-27 04:04:45 -0600

Hi, I am new to OpenCV and as a first target application, i have decided to get motion detection working.

I have an another application which keep on capturing images from a fixed source in half second and stores it on file system. So I am passing two images to the opencv application and it will process them to detect motion between two frames.

I am performing the following steps to detect motion:-

  1. Subtract Image1 from Image2 using Core.subtract(Image1, Image2, diffFrame);
  2. The diffFrame[x][y] will be have a zero value if Image1[x][y] - Image2[x][y] = 0, i.e. no difference at this pixel.
  3. Then I calculate the number of nonZeroValue of diffFrame using Core.countNonZero(diffFrame);
  4. Then I calculate percent of changedPixels i.e. nonZeroValue(diffFrame) by applying this formula

     float motionPercent = (nonZeroValue(diffFrame)/nonZeroValue(Image1)) X 100;
    
  5. And If this motionPercent is more than some certain value, i consider it as motion.

But the problem with this way of solving is that it fails if object is moving too slow as the diff in not more than my threshold values.

Is there any better way of doing this?

Regards,

Naval Gandhi

image description

http://paxcel.net/blog/

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2014-11-09 17:26:22 -0600

Hi, I don't know if you are still working on this topic , here is a simple implementation of motion detection with JAVA OPENCV :

http://ratiler.wordpress.com/2014/09/08/detection-de-mouvement-avec-javacv/

edit flag offensive delete link more
0

answered 2013-11-16 05:57:40 -0600

Will Stewart gravatar image

I'm beginning to look at motion detection in java as well. There are a lot of powerful tools in OpenCV that can get you there rather quickly, as described at http://tech-lightenment.blogspot.com/2012/05/implementing-motion-detection-using.html

Another place to look is motempl.java, which is the java equivalent of the C version; https://gist.github.com/b95505017/6862032

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2013-09-26 02:45:31 -0600

Seen: 8,162 times

Last updated: Nov 09 '14