Image comparison using arduino

Hello, I was wondering if it could at all be possible to have a camera snap random pictures, then within the arduino, process them and see if any of the pictures look the same as preloaded pictures. That may be a little vague, but I will list more info below. By the way I am not using an official arduino, I am using the RedBoard, from sparkfun. It is programmed the same as the UNO though.

If you have any questions please ask, and thanks in advance!

Similar questions have been asked, but I haven't seen any solutions.

Do you have any idea in how it could be done? Could I ask another smaller question?

Is it possible to take a picture store it on an sd card located on my arduino then write a program that could compare it? So in short is it possible to add an sd card to an arduino?

So in short is it possible to add an sd card to an arduino?

Yes this is possible.

Now the only way I can see this being done is if you can some how see the byte array of your screen, (each and every pixel on it) and compare the screen data with the picture data. I have never seen this done, or even know if it can be done on the Arduino. The Arduino can not process images but that doesn't mean it can't compare the bytes or byte arrays from two things.

With that said, it may just be easier if you use a regular computer to compare the images.

So, would there be a shield for an sd card storage? Is it possible to have the arduino capture images and save them to the sd card? Thanks for the replies!

What size of image do you want to capture?

Pete

I don't care what res it is, I am thinking I might just use a low res camera scaling it down to 64 x 64 and comparing the bytes. I don't really know how to do that, so if anyone does know could you please tell me?

Well, with Arduino, OpenCV, & Processing, you can do face-tracking...

http://vimeo.com/adambd/pinokio

But, I don't think that's quite what you had in mind. Check Adafruit.com for what you need — SD SHIELD, code to use it, tutorials, et al...

I wrote some code using a serial JPG camera that determines if the image is EXACTLY the same or not. Minor changes count as the same, but if any large object moves, it's different. A bug moving, a laser dot, or even a shift of the entire camera would still be the same. Slow moving shadows are also the same. It's quite practical! Only a few lines of code on Arduino.

That would be most excellent, and gives me an idea for another project. Do you have soluable code?

I cheated. It's a simple hack. I simply look at the size of the JPG image without transferring any data to the Arduino at all. Look for changes in size, not the size itself. It's less sensitive with more compression. More sensitive with less. There is some small variation even when no objects or light move at all due to noise. This is why you can't detect a bug moving, a laser dot, or a small panning shift of the camera. Surprisingly, it doesn't work in the dark to look for an IR laser hitting a target or not. It cannot detect the presence or absence of a dot in the dark, due to the noise and compression of "dark". It works better with an IR light detecting a new large object coming into the scene, day or night. Questions?

sbright33 the method you are using will class all jpgs of the same size as being the same, which is obviously false. It sounds like it works for images of the same scene (presumably take close together in time) but then it gets spoilt by this statement;

This is why you can't detect a bug moving, a laser dot, or a small panning shift of the camera.

If you can pan the camera even a small amount but the images are classed as being the same its not really a very good test. Presumably ambient light changes will flag up images as being different?

I suppose if the objective is to say "has this scene definitely changed" it will work though you will get false negatives where scenes may have changed quite a bit but are not detected.

radman: but then it gets spoilt by this statement;

You seem to be missing the point that doing the job accurately is not feasible - sbright33 is suggesting crude comparisons which are feasible and give useful information, even though they are far from perfect. If you want to do image comparison properly, don't do it on an Arduino.

Hello PeterH. sbright33 was being a bit of a tease when he first wrote

I wrote some code using a serial JPG camera that determines if the image is EXACTLY the same or not.

In fact his technique will tell you if two images are not exactly the same. It will not tell you that two images are exactly the same.

Still the idea of photographing the same scene close in time and then using the file size difference to gauge the amount change between the images is not a bad idea.

@Radman- Think of it as a hash function. If I have an image with a specific size, within 100 bytes, you could not possibly find an image with the same size. Not by starting with a new scene. It would take you 100’s of guesses to do it. So of course there’s no guarantee it’s the same. But I’d give you 100 to 1 odds that it’s similar. Not counting a laser dot or a bug that moved. The small panning only works if it’s a carpet background for example, and the only subject is still completely framed. In this case it ignores movement of the subject or panning. This is a Feature not a Bug! Shadows moving as the sun moves thru a window change the size gradually over hours time.

It depends where you set your criteria. If you want to be able to say “definitely changed”, then use a wide range of sizes. If you want to be able to say “deinitely the same”, then use a narrow range. Both work! You choose.

@PeterH- Yes it is crude. You’re right it is also useful. What is properly? Certainly it can’t recognize a face or not if it’s the first time seeing a scene. I believe this is the proper way to detect a change. Because it ignores the things I want to ignore which change. And catches the things I want to catch. If you have different needs, it will likely work by simply changing the range parameter.

Again it can be used to tell if there was a significant change only. Or by changing the parameter it can detect a tiny change. The only limitation is that it cannot detect a dot like a bug moving. Why would you want to do this anyway? If it’s bigger than 5 pixels, and it’s not square it will detect its addition to the frame.

It can do 5 FPS with Uno. I can detect the presence or absence of an IR laser during the daylight without noise, but not in the dark. The trick is to modulate and move the beam. Specifically what would you like it to do? I’ll try it. It would take much effort and a fast CPU to write your own algorithm at 30 FPS.

It sounds wonderful! $)

If I have an image with a specific size, within 100 bytes, you could not possibly find an image with the same size. Not by starting with a new scene. It would take you 100's of guesses to do it.

@sbright33. I looked at the size of 95 random jpegs. If I divided the file size in bytes by 1000 several images had the same size. If divided the file size by 100 none of the images had the same size.

Whilst I think different pictures will have the same size more frequently than you do you clearly have something which you use so there is no arguing with that.

sbright33: What is properly?

By 'properly' I mean based on an analysis of the pixel values i.e. conventional image processing.

In 100 words or less, how would you look at the pixel values to see if anything "moved"?

I thought one could evaluate the pixel array, one-by-one, to see if a particular pixel value has changed. I think smarter algorithms are able to identify pixel groups and track their movement through the array.

That is quite oversimplified.