Home › ELEKTOR FORUMS › DigiButler (April & May 2008) › Another CAM for DigiButler

ELEKTOR FORUMS

Please log in to post a reply or subscribe / unsubscribe to topics

Topic: Another CAM for DigiButler

Author Post

tonaugustin

14 posts

Popping In
Popping In

Read post 08-02-2009 15:47

Great work from Henry Laidet on the DigiButler. Except that I could not get the camera. There is a very low cost MCA25 cam that can be used.
I got most of it working.
Also I added servo controlled pan and tilt for the camera.

Oh, and BTW, sw does not start without a cam connected...

AttachmentDigiButler software with MCA25 and RCServosTA080209.zip

HLaidet

61 posts

Frequent Visitor
Frequent Visitor

Read post 09-02-2009 19:30

Hi, Ton

fine work.
i order a mca25 to try.
when it works, i will incorporate your source code in mine.

i like 460k baudrate.
can you tell me how long is a grab ?

for the moment, i work on the DB as datalogger.
then i must find a good IOs organization because i need analog inputs (you reduced one bit more).
i have transfered SD connections ANA4-6 to TIN0-3.
is it possible to use GPT2 as camera reset (to recover all analog)?

Henri

tonaugustin

14 posts

Popping In
Popping In

Read post 09-02-2009 22:17

Hi Henri,

The total capture time is about 5 seconds from pushing the button to a new jpg in your browser.
Simon Schultz ( http://avr.auctionant.de/avr-ip-webcam/ ) used 6 preview grabs and then a grab with 640*480 resolution.
I changed that down to 3 preview grabs and a 320*240 resolution, to speed it up a bit.

The preview grabs are in 8 bit rgb. Converting that to 4 bit greyscale did not really work yet, 460K is very very fast,
there is not much time to convert. Also the format is EBMP instead of BMP which means you have to write the BMP backwards.

It would be best if the preview works in 8b RGB mode, and the capture is done in 640*480, but that would mean a BMP file of around 4K, and there is not enough memory for that

Changing the RST to GPT2 is no problem, I add sources with an RSTGPT2 switch.

AttachmentMCA25-GPT2.rar

HLaidet

61 posts

Frequent Visitor
Frequent Visitor

Read post 01-03-2009 12:26

Hi, Ton

i received the mca25
after:
- connecting mca25
- changing IP access mode in your code
- loading your site test on SD card
i can grab with mca25.

i did not tried the RC servos.

to merge your code in mine, i done some minor modifs:
- same filename to use C328R or MCA25
- same function called by http connection
- incorporate grabbing in a state machine to prepare a preview mode

i should modify html file to run with C328R or MCA25
the preview image must be refreshed every seconds

then it works.

i didn't find a datasheet(or technic user manual) like C328R.
i think mca25 is only for GSM
then i have problems to generate a preview image.


sources: http://pagesperso-orange.fr/HLaidet/Digibutler.htm

Henri

tonaugustin

14 posts

Popping In
Popping In

Read post 03-03-2009 21:41

Hi Henri,

Thanks for adding. I will check the changes. I did some upgrading in the mean time, I will send those, to stabilise the version. (For instance, the X-slide is panning in the wrong direction)

I have a problem with starting up in 100Mb mode, it keeps resetting for 30 minutes and finally gets stable. When I use 10Mb all is fine, so I changed your code back to 10Mb.

The documentation is really poor yes. MCA25 is designed to clip on a GSM. There is documentation about the AT commands, about the Multiplexer that is used on the serial port, but I did not find any documentation of the cam itself.

When the preview mode could be set to greyscale, and BMP format instead of EBMP, then a lot of issues would be solved.

Sylvain

7 posts

Popping In
Popping In

Read post 19-03-2009 13:27

Hello!

As I wrote to Henri, I'm very interested in using the MCA25 cam.
I order one too!.

But I'd like to know if one of you successfully used the preview mode?

I don't want to send images to any browser, I just want the embedded firmware to use them. I don't need detailed images, so preview would be fine for me.

Thank you very much for your work.

Sylvain

tonaugustin

14 posts

Popping In
Popping In

Read post 19-03-2009 21:33

Hi Sylvain,

you can grab a 60x80 preview image. It is 8bit rgb, so around 4800 bytes. It is in EBMP format, which is something like BMP upside down. They come in with 460K baud, so there is no time to process them on the fly. But once the image is in, you can process the image. When you can get enough memory free to store that 4800 bytes, you are ok.


What are you going to do with the images?

Sylvain

7 posts

Popping In
Popping In

Read post 20-03-2009 07:43

Thanks Ton.

Ok, I had a look to the original AVR site, it sounds good for me.

My application is a very special one.
I have 2 cats, a grey and a red.
The problem is that the red is always hungry, I can't let food for both of them, the red would eat all.

So I want to use a cam to recognise the cat which comes near the cam (in fact under the cam, it will look down), and deliver food if it's the grey one.

I've already think about the criterion to distinguish the two cats. A very simple one could be the number of coloured pixels in the picture.

If there's not cat, the cam see a wood board, which is a little red, so there are coloured pixel. If the grey cat comes under the cam, the number of coloured pixels will decrease.

I thought about other possibilities, but more complicated. I must use an algorithm as simple as possible!

I tried with the following samples. The first picture is with natural colours, in the second I removed the grey component, and amplified. As you can see, the grey cat becomes very dark.

Sylvain

tonaugustin

14 posts

Popping In
Popping In

Read post 20-03-2009 21:38

You could paint the wooden plank blue, so there is good contrast with the grey cat and the red cat. (I see that with a red cat the B component of the RGB values is always less than the R and G)

From the EBMP file, select some pixels that you want to sample.
When the cam is fixed, you know exactly which pixel is where on the wooden plank. That is handwork, but once you know the offset of those pixels in the file, you can sample their color easily.
Store the offset of the pixels you want to sample in a table and use that table to read the right pixels)

Then on a regular base, capture an EBMP file. From the stream of bytes, pick the right pixels (Offsets in the table) and store them.
You do not have to store the whole file, just pick your pixels.

Sample the pixels, maybe one by one, maybe add their RG and B components, so you know the RGB distribution.

simply said:
blue in RGB dominant: no cat,
blue in RGB minimal: Red cat, no food,
RGB evenly distributed: Grey cat, hungry, so food!

The trick would be in finding the right pixels to sample, and to eliminate brightness differences. When you decide on difference between RGB components, brightness would not make too much difference.

Oh and don't forget to manually feed the grey cat while you build this

Sylvain

7 posts

Popping In
Popping In

Read post 23-03-2009 14:06

Thanks Ton for these ideas!

It won't be possible to paint the wooden plank which is an old weighing machine. It would not be very nice!

But the idea to sample some relevant pixels in the picture is very good.

I had planned to use preview images to limit picture size, but it also would have limited the depth of colour.
Great!

I received the camera last week. I need the digibutler to start the tests.

Sylvain

Groen

10 posts

Popping In
Popping In

Read post 28-05-2009 10:39

Hi Sylvain,

Just to add on one of your previous posts (March 20): if want to have the picture independent of brightness you can change the color format from RGB into CIE-Lab. Here L=luminance and a, b are color components. Now a and b are independent of the brightness. For calculation details please check http://www.easyrgb.com/index.php?X=MATH.

By the way, has anyone tried the MCA30 camera? This should be the successor of MCA25.

Regards,
Bas

Schueler

1310 posts

Power User
Power User

Read post 03-09-2009 14:51

SylvainThanks Ton for these ideas!

It won't be possible to paint the wooden plank which is an old weighing machine. It would not be very nice!

But the idea to sample some relevant pixels in the picture is very good.

I had planned to use preview images to limit picture size, but it also would have limited the depth of colour.
Great!


I don't know if you already solved the problem ore not but...


As I can see on the picture, you are using natural light. So if the sun is shining or cloudy, this will give different results. If it is almost dark, the red cat will by detected as grey.

I suggest to convert the RGB to YUV. A better solution is to put the cam to YUV mode if possible. If not, convert it yourself by software.

Y  = + 0.299R + 0.587G + 0.114B
U  = 0.492(B - Y)
   = - 0.147R - 0.289G + 0.436B
V  = 0.877(R - Y)
   = + 0.615R - 0.515G - 0.100B


ones you have the YUV you can use th U and V to determine the colour. Y is only for luminance ( grey-level ) and is not in our interest. So, U and V stay pretty much the same level if the environment is light or dark.

Wikipedia YUV.


Ben

Sylvain

7 posts

Popping In
Popping In

Read post 14-09-2009 10:22

Some news about this project.

Most of the hardware is ready:
- a digibutler
- a custom PCB
- some switches, a 16x2 LCD, 3 white LED to light the cat in the night,
- an mca25 cam
- an SD_card

For the mca25, I use the source code of Henri Laidet & Ton. I made it a little more robust, on cam hangs I make a new reset. It occurs sometimes, I do no more receive any data from the cam (in the middle of a snapshot). I don't know why, perhaps because of buffer overflow.

I first tried to use preview image, but quality is really pour, I was not able to get usable color information.

So, I use JPG snapshots.
I found a lightweight JPG decoder that I'm porting to digibutler. The main trick to use as little memory as possible. The embedded web server is currently disabled, I don't need it.

We can’t expect very good pictures from a cam @ 10€. But it would be perfect to me if white balance were not sometimes so blue!

He is what the current software do:
1. six previews and then snapshot in JPG format, 320x240, stored on SD_card. I do 6 previews because pictures are more stable and more luminous than after only 3 previews.
2. The JPEG image is decoded into memory, I keep only averages on 8x8 pixels blocks, to reduce memory consumption, and to reduce noise
3. I compute min and max on RGB components, an I adjust each R an B levels, because of white balance problems.
4. then I do an RGB to HSL translation (Hue/Saturation/Luminosity).
5. with the colour space HSL, I can count pixels associated with the weighting machine, the cat, and some relevant objects. The Hue value is independent of the luminosity and represents the colour. 0 to 17 for the weighting machine, 18 to 40 for the red cat for example. Saturation can say if there’s colour in a pixel or not.
6. With these numbers I can try to say if a cat is present, and which one.

At the moment, only the first step runs on the digibutler. I test the others on PC. I don’t know if they are runnable in digibutler in this state. I will certainly have to make some optimisations!

This is the next step.

To be continued…

Please log in to post a reply or subscribe / unsubscribe to topics

Subscribe now

Subscribe to our free
E-weekly Newsletter!

Enter your Email address:

Follow Elektor

      

Act now!

Sponsored

FAQ

Before submitting questions, review our FAQ section!

Bestseller

Controller Area Network Projects

The aim of this book is to teach you the basic principles of CAN networks and in addition the development of microcontroller based projects using the CAN bus.

Package Deals

Elektor Bundles

Check our Package Deals and save money! Discounts up to 19% now available!

Price Slashed

Elektor OSPV

This Open Source People Vehicle is perfect for factory halls, warehouses, hospitals, colleges, schools etc.