Ask Your Question

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?


Naval Gandhi

image description

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

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 :

edit flag offensive delete link more

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

Another place to look is, which is the java equivalent of the C version;

edit flag offensive delete link more

Question Tools

1 follower


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

Seen: 7,915 times

Last updated: Nov 09 '14