Image processing question/ object detection

I am working on a project using an Arduino Mega with SRam and a latch for addressing the SRam.

I know the Arduino cannot do image processing on its own. But if i take the image off the camera at ~15MHz and put it into the SRam which can write as fast if not faster than that I think i can process it one pixel at a time???

I dont need this to happen super quick but i should be able to go through the array and check the data one at a time after the data is in the SRam???

The camera sends out a RGB442 signal so i was looking at a 1Mx8 or a 512kx8 to hold the data while processing.

My main question is: do you think that i could detect a colored X made out of wood on a white background using this method with a 0.3MP camera or would i need to upgrade to a 1.3MP? I will be about 4-8 Ft from the object and shooting the picture at a right angle to the object. It will either be there or it wont and it will not be moving.

But i am not sure of the granularity of the picture i need to detect this will be good enough.

I am thinking that if i make 1.310^6 pixel comparisons assuming a CPI of 5 clock cycles a piece i can get through 1.3MP : (51.3106^6)/ 15 Mhz = 97s which is reasonable. I might be able to bump up the speed if need be. If i can get away with a 0.3 MP camera, however, it becomes (50.307*10^6)/ 15 MHz = 22s which is WAY better.

thank you for any input you have. I hope that i can make this all work :slight_smile:

cameras similar to what i am looking at:

Why not use a Raspberry Pi for image processing?

Very good question. I have looked at ARM chips as well as the Pi.

I didn't mention because i was on the Arduino forum but this will be on a He balloon floating 4-8 feet above the ground....SO the Pi is a little weighty where the Mega i can fab a custom PCB and save some weight (i thought?? may not be true). I went back and forth about going with the Pi.

Do you think it would be that much faster/easier to do with the Pi? I could eliminate the latch and SRam if i do PI but then i have to try and procure a Pi as well :slight_smile: :slight_smile: I searched and search and i did some that Pi seems to be somewhat preferred

Plus then i would have an extra pi floating around thats never a bad thing.

But if i take the image off the camera at ~15MHz and put it into the SRam which can write as fast if not faster than that I think i can process it one pixel at a time???

You can directly access what is called dual ported RAM with the video and access it slowly with the arduino. However, this is expensive for the ammount you need.
I am not sure what you plan to compair with what, where you will put the result and how you will decide you have a match. Do you have an algorithm for detecting a cross?

Gut feeling is that you're flogging a dead horse here and the Arduino has nowhere near the resources you need to do the image processing, even assuming you manage to get the image into storage in the first place. I suggest that you research the image processing side and prove me wrong before you worry about how to get the image off the camera. If you need to adopt a more powerful platform to do the analysis then the problem of capturing the image on an Arduino becomes irrelevant.

Thank you for the replys.

@ Grumpy_Mike
Since i know the background i would tell the system look for a blue/green/red cross.
The camera will take a picture and load it into ram.
The uC will then pull data from the ram and when it sees a change it will log that into a bit array of the size of the floor.
Then using vectors(just see if the lines are offset at each increasing row) to see if a line can be seen to form. If the two lines cross with opposite slopes it forms an x.
This will be more pipelined in the system to be able to pull off multiple bits as to not wait for data hazards.
I will look into dual ported memory as well.
Thank you

@PeterH
I have a very very limited amount of power(around 400mA avg and 700mA peak) so that is why i bypassed the Pi in favor of something like the Mega or the ARM cortex-M3 (may lean that way with 50Mhz and much more ram) but i like working with Arduino.

The link below is someone who did it with a black and white game boy color camera. He is still using grey scale shading at 8 bits but the image size is much smaller so he uses 32k x 8.
So i will be using a larger size image hence a large SRam and a longer compare time but i think something similar can be done.

I honestly just have little experience with cameras and everyone seems to be using super low res/ black and white cameras. I want to be able to detect colors so i can take the 8 bits and change them for color instead of grey scale, i hope.

ARM is an ok solution for me but i want to try Arduino before i throw up my hands if you think its anyway possible?
Thanks for your input i will take it into consideration.

It's all very well saying:-

i would tell the system look for a blue/green/red cross.

but how would you do that?
Get the language processing, import a still image and then write something that will find a cross.

Can i not do something similar to
bitarray = array[1024][256] //8192 addresses in 8 bit sizes by 

for(int j=0;j<256;j++){
    for(int i=0;i<1024;i++){
        getDataFromAddress(i);
        int r = pin2&&pin3&&pun4&&pin5;
        int g = pin6&&pin7&&pin8;
        int b = pin 9&&pin10;
        if(checkingForRed){
          if (r>threshold){
             bitarray [i][j]=true;
          }else if(...){}
          else if(...){}
        }

    }
}//end of for
//traverse array and see if an x
for(i to 1024){
for(j to 256){
if(bitarray[i][j]==true){
if(bitarray[i-1][j-1]||bitarray[i-1][j+1]){
//start of an x keep checking
}
}
}

just to give you an idea i dont have the whole code just pseudo. If i want red i look at first 4 bits, if i want blue look at next 2 if i want green look at last 2. if i want something in between mix them etc. Why would something like this not work?

Why would something like this not work?

You seem to be concentrating on the easy bit. Yes you can get a colored pixel, that is no problem.
But the line
//traverse array and see if an x
I can't see working. How is this going to find an X?

As I said try it in Processing before you go to the bother of adding complexity and getting it to work on the arduino.

The line

bitarray = array[1024][256]

is going to take 256K of memory

I see what you were saying. I have done image processing but on a desktop where i was not worried about that size but on a uC i see that it would be a problem.
Thank you for point that out i will need to fix that indeed.

Instead of doing that I could see if i find a pixel of that color then get the next diagonal pixel from memory thus freeing myself up from needing an array at all. It would take a little longer but i think it would have a much smaller footprint. I will get some image and play around with them on my desktop for now.

I dont have that low of a resolution camera but i think i can use something to push the resolution down possible.

Thanks again

computerman2013:
I have a very very limited amount of power(around 400mA avg and 700mA peak) so that is why i bypassed the Pi in favor of something like the Mega or the ARM cortex-M3 (may lean that way with 50Mhz and much more ram) but i like working with Arduino.

The fact you don't have any options doesn't make this feasible. I think you're going to find that image processing is harder than you think and needs more resources than you expect. IMO the most sensible approach would be to get the image processing side working any way you can, find out what resources it is consuming and then see whether it's feasible to optimise it to work within the resources available on an Arduino. Even if the answer is 'No', at least that gives you a handle on the platform requirements.

This will give you more RAM using external S-RAM for Arduino mega

I could see if i find a pixel of that color then get the next diagonal pixel from memory thus freeing myself up from needing an array at all.

You can do that but you are still thinking like a human and not a machine.

So you find a red pixel and go off diagonally to the upper left after 10 pixels it stops being red, Going lower left after 8 pixels it stops being red. Going lower right it stops being red in 5 pixels. Going upper right it stops being red in 12 pixels.
What is your conclusion?

  1. You have found a red cross
  2. You have found a red square
  3. You have found a red square that is rotated
  4. You are just on one arm of a cross and haven't hit on the middle
  5. It is some other red object

Object recognition is a lot harder than it at first seems.

So you find a red pixel and go off diagonally to the upper left after 10 pixels it stops being red, Going lower left after 8 pixels it stops being red. Going lower right it stops being red in 5 pixels. Going upper right it stops being red in 12 pixels.
What is your conclusion?
1)...

...or your white balance is off.

Object detection is much harder than you think, beside algorithms, just the preprocessing of image is going to be a challenge, even for a desktop machine with moderate CPU and memory. For example different lighting conditions will give you a lot of trouble, different contrast, brightness, noise from webcam . . . etc, etc.

If it were done on a desktop, and say using OpenCV, quite few processes have to be done before you can analyze image captured. One thing I can think of now is adaptive thresholding (look up OpenCV for such function) which will give you a cleaner bitmap of image, then you can apply some algorithm to recognize a cross.

I have not seen an OpenCV ports to Arduino platform, if anyone knows there is such thing, please let me know.

I have not seen an OpenCV ports to Arduino platform,

There is are two very good reasons for that.
Memory and processing speed.

Grumpy_Mike:

I have not seen an OpenCV ports to Arduino platform,

There is are two very good reasons for that.
Memory and processing speed.

Very true, most vision algorithms are CPU and memory intensive!

For reference of what can be done using an 8 Mhz atmega, you might look at the AVRcam.
Business is now defunct from the looks of it, but source code is open-source and still available.
For a lot of things, you don't need super high-resolution, or huge frame buffers. Eg,

Track up to 8 different objects of up to 8 different user-defined colors, at 30 frames/second

http://www.jrobot.net/Projects/AVRcam.html
http://www.jrobot.net/Download.html

Tracking is a whole lot easer than object recognition.

Yep, you can take the image off form the camera, and load the image into a image processing software to processing the image, this will be much easier i believe.