954,518 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Motion detection with Java

Hi,

I am trying to write a simple java application that detects motion. The application gets its images from a webcam with the address:

http://studiocam1.disp.duke.edu/jpg/image.jpg

(you can watch the live video feed at: http://studiocam1.disp.duke.edu/view/index.shtml )

My current plan is: (I have little experience, so it may be wrong)

1. I obtain an image from the webcam at http://studiocam1.disp.duke.edu/jpg/image.jpg and store it as a BufferedImage.

2. I call getRGB() on the BufferedImage, which loads the pixel data into an int[] array)

3. One second later, I obtain a second image from the webcam (at the same address) and store that as a BufferedImage as well. I call getRGB() on the second image as well.

4. Now I have two int[] arrays. One array represents the "before" picture, one array represents the "after" picture. If I compare the two arrays, and I notice significant difference, then my program signals that "motion is detected."

5. I would also like my application display the constant sequence of images that it is reading in a window. Basically, the window would show the live video feed from the camera.

My problem is here:
- I don't know how to display the images in a continuous video-like fashion

* the only way I have ever displayed an image is by loading an ImageIcon, and then adding that ImageIcon into a JLabel, and then adding that JLabel into a JPanel, and then adding that JPanel into a JFrame

* I tried creating the illusion of video by constantly updating my ImageIcon in a while-loop. However, that produces VERY choppy and poor quality video

- I have a great degree of uncertainty. Is there a package or a class that was especially designed for dealing with video, frame-by-frame?


Help would be greatly appreciated. Thanks in advance.

I'm sorry that I have no code to show you. All the code that I have written works fine. But regarding my problem, I don't even know where to start--so I have nothing to show.

crowleykg
Newbie Poster
2 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

Take a look at the Java Media Framework . Some of the demo solutions here http://java.sun.com/products/java-media/jmf/2.1.1/solutions/index.html may be useful.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

Ezzaral, thank you for your speedy reply. I am looking at some code examples now. I would really appreciate it if you could stay tuned to this thread, since I am sure I will have some follow-up questions soon.

Again, thank you.

crowleykg
Newbie Poster
2 posts since Mar 2008
Reputation Points: 10
Solved Threads: 0
 

hello Ezzaral,

do u know a simple source code for motion detection written in Java.
it would really helpful to start off with my project.

Please HELP

LASERTITO
Newbie Poster
2 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Hi crowlegkg,

Can u plz share ur code
coz it would be helpful for my project ideas
n better understanding of java

LASERTITO
Newbie Poster
2 posts since Feb 2009
Reputation Points: 10
Solved Threads: 0
 

Do not hijack old threads. Post your questions in a new thread.

Drop the "IM speak" as well. This is not a chat room nor an IM service. If you are too lazy to type properly, don't expect others to spend much time trying to help you.

Ezzaral
Posting Genius
Moderator
15,986 posts since May 2007
Reputation Points: 3,250
Solved Threads: 847
 

In addition to what Ezzaral said, you should also state which platform we talking about as motion detection can be done through Java SE (Standard Edition - as desktop application) or Java ME (Microedition - for mobile and embedded devices).

peter_budo
Code tags enforcer
Moderator
15,436 posts since Dec 2004
Reputation Points: 2,806
Solved Threads: 902
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You