LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 03-23-2012, 09:11 AM   #1
wana
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Rep: Reputation: Disabled
Read an Image as array in java


Hello every body,

I want to make an application for a web cam:

The camera will capture 2 consecutive images of the scene and a java code i want to write must subtract the second image from the first so the result must be zero since they are the image of the same scene.

In order to subtract the 2 images from each other, I want to connect the camera to java and read the images (which are composed of pixels) as an array in java in order to subtract them cell by cell ( the array is composed of cells).

Any body can give me a hint in this step please ?

thank you
 
Old 03-24-2012, 04:17 AM   #2
j-ray
Senior Member
 
Registered: Jan 2002
Location: germany
Distribution: ubuntu, mint, suse
Posts: 1,591

Rep: Reputation: 145Reputation: 145
Maybe you find some useful information here:

http://www.javalobby.org/articles/ultimate-image/
 
Old 03-26-2012, 06:25 PM   #3
wana
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thanks, the link helped me a lot.

Do you know what is the command to subtract a pixel from another
 
Old 03-26-2012, 06:48 PM   #4
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
This maybe is helpful: http://docs.oracle.com/cd/E17802_01/...escriptor.html

EDIT: By the way, the resulting image will almost never have all pixels exactly zero. Depending on the quality of your camera, more or less noise will be in the pictures that will lead to slightly different images.

Last edited by TobiSGD; 03-26-2012 at 06:50 PM.
 
Old 03-31-2012, 06:15 AM   #5
wana
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
You are right..while writing the code the result didn't give zero unless i loaded the same picture twice..My goal is that if the image changed it means that somebody entered the room so the alarm must turn on and a graph illustrating the trace of the intruder's movement is drawn and some other secure effects. I stick on the condition i want to write to make the camera realize the change of image by subtracting the two pictures from each other because even if the image didn't change the result of subtracting will not be zero. Any idea ?
 
Old 03-31-2012, 06:26 AM   #6
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
May be motion is the thing you want.
 
Old 03-31-2012, 08:04 AM   #7
wana
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
The Motion depends on Linux which I am not familiar with. I get an idea, what if i changed the pictures taken by the camera to black and white before subtracting them. So if no one entered the room the result of subtracting will be zero ?
 
Old 04-01-2012, 08:27 AM   #8
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
It doesn't matter if you convert the images before doing the subtraction. The noise is in the original images, so it also will be in any image that is based on them.
 
Old 04-03-2012, 11:11 PM   #9
wana
LQ Newbie
 
Registered: Mar 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
If noise is in each image taken of the scene how I will let the code assume they are similar.Is the code taking the same color of the scene different in the two images? If so how can I face this problem ? What if I make the condition to assume the two images the same is not that the RGB of the pixels are equal, but I make the condition that the RGB of the pixels of the first image minus the RGB of the pixels of the second image <5 for example ?
 
Old 04-04-2012, 06:15 AM   #10
TobiSGD
Moderator
 
Registered: Dec 2009
Location: Germany
Distribution: Whatever fits the task best
Posts: 17,148
Blog Entries: 2

Rep: Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886Reputation: 4886
Yes, if you assume that noise is (if you have a somewhat decent cam) only a minimal change in the pictures, then ignoring minimal differences should work. It also may help to break down the images in smaller chunks. For example, if you have only a difference in one or two pixels in a 10x10 pixel block then it is unlikely that there was a motion, it is more likely that the differences are simply noise. The size of the pixel blocks should be dependent on the size of the original images. It wouldn't make much sense to use 50x50 pixel blocks with an image that is 320x240, but may be with an image that is 1920x1080.

Last edited by TobiSGD; 04-04-2012 at 10:59 AM. Reason: fixed typo
 
Old 04-04-2012, 10:49 AM   #11
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
It seems very improbable that your simplistic approach will ever be successful, due to a number of real-world factors. The imaging device will never be noise-free, and is subject to variations in sensitivity to various spectra due to temperature, possibly humidity, aging, noise coupled from power sources and noise from other electrical sources, etc. The optics of the imaging system will also be subject to long term changes. The image itself will change due to variations of lighting, mechanical vibrations of the imaging device, and other environmental factors.
To have any sort of reliable detection of movement, you will need to do more analysis than frame-by-frame comparison. You will probably need some form of image-recognition analysis, which is able to identify gross components within images, and then compare those on a frame-by-frame, or frame-series basis. There are packages available to assist with this, although I have no first-hand experience with any. I am given to believe that most higher quality packages are commercial products.
You may be able to glean some techniques from code that performs motion video compression. As I understand it, much of the compression technique is to compare frames, and then store only differences between sequential frames. At the root level, this sounds like what you are attempting to do, followed by some quantization of the frame-to-frame differences. There should be an abundance of open-source code that performs MPEG and other forms of motion video compression for your your scrutiny.

--- rod.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Array's.... Making An array bigger??? Tru_Messiah Programming 11 08-17-2016 01:45 PM
Image array mukhram Linux Mint 1 10-19-2010 02:16 PM
Read Write access to a iso9660 filesystem..mount a .iso image as read write ceazar123 Linux - General 2 08-26-2010 03:32 PM
Converting Image to Byte Array (Java) megabot Programming 2 03-17-2007 09:49 AM
how to write an image from a data array aw_wolfe Programming 4 05-05-2005 05:53 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration