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


(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.

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.

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

Hi crowlegkg,

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

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.

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).

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.