Go Down

Topic: Experimental: ESP32CAM Tracking of a colorful ball using hue (Read 177 times) previous topic - next topic


this is not a completed project but more somewhat like a experimental stage. But as there seem to be not yet many sources on the net it might be an interesting starting point for others.
(Some people seem to have difficulties with the camera, mine is running fine, if I provide power to the 5V input.)

It is a hack of the CameraWebServer example which is provided and running with the ESP32CAM. This Example sends streams of pictures over a wlan, which is very useful, as you can see, what the camera is seeing.

The trick of this very simple tracking is not to use some kind of shape recognition but to have a ball that has a color, which does not occure elsewhere in the picture. The average position of all pixels, which have this color is given as the result. So if you have two balls of this color, you get a result between them.

"Hue" is part of a color model, that consists of 3 dimensions "Hue=color", intensity, brightness. See wikipedia for a better definition. This model has the advantage, that this number "hue" will not change, if there is more ore less light available.

The hack is done inside the function stream_handler in app_httpd.cpp. If you activate "face detect" on the web site, in line 548 find_col(...) is called or markmitte(...). Serial is used to give results.

These two functions use the picture in the format "rgb888" which means that the color model here is a byte for each of the colors red green and blue for each pixel. From this the hue value is calculated for each pixel separately.

At the moment the range of hue is hard coded (red) and you have to change comments to use markmitte(...) to find different hue values as a teach mode. (I want to use the switch at GPIO0 to switch to teach mode but for some reason function process_find(...) does not work. Can't you use GPIO0 after booting?)

For example color line following or color sorting should be not too difficult. As I understand, you can use the ports 4, 2, 14, 15, 13, 12 if you don't attach a SD card.

Comments, suggestions?
Happy experimenting! Christof

Go Up