Use CV to determine relative angle to moving object?

I hope I am posting this in the right place. I am absolutely new to CV so I am not even sure where to start and I suspect what I want to do has already been done, probably many times, and I see no point in reinventing the wheel if I don't have to. I have done a couple of searches but have not found what I am looking for. (Or maybe I found it but in my ignorance didn't recognize it?)

The project:
I have an ESP32_Cam and have been toying with the idea of using it to determine the relative direction (e.g. X,Y coordinates or similar) of the largest/closest moving object. Then use that info to move a set of eyes that way (maybe digital display or servos to move physicals eyes...have not decided yet). It seems like it might be fairly easy to implement with the right library, but like I said I am not even sure where to start.
I would prefer to write it in C++ (arduino IDE) but would use MicroPython if necessary.

TIA

I am probably being dim, but what is "CV" in the context of Arduino projects ?

That requires a "camera model" which includes the characteristics of the lens (focal length, e.g. wide angle versus telephoto, etc.) and "camera calibration" to reduce distortions.

If you are considering using OpenCV, start with the documentation and introductory tutorials.

Rather than an ESP32, you will have a much better experience using a laptop with a camera, running a modern operating system. Plenty of tutorials are available.

Computer Vision.

Hi @amatbrewer ,

Here is a page that gives some information regarding ESP32 and Open CV

https://www.hackster.io/news/eric-n-shows-how-opencv-can-squeeze-onto-an-espressif-esp32-using-joachim-burket-s-shrunken-fork-8c73520a6b81#:~:text=%22It's%20working%20as%20a%20stand,on%20ESP32%20is%20really%20cool.%22

but!!!

What N. has put together, in fact, is not a full port of the entire OpenCV library bundle — an impossibility, given the relatively meagre resources available on an ESP32 compared to the devices that would normally host OpenCV — but a cut-down version, forked from the original

Other sources use the ESP32_CAM as an image server and do the job on a PC with sufficient resources.

A different approach would be to use a Raspberry Pi (3+ or 4 are usually sufficient for OpenCV). I used a Pi 3 in the past with quite good results (target tracking, filtering etc.) with OpenCV and Python.

Good luck!

Yet another option is to use a 3D camera, like those from Luxonis. I'm quite happy with the Oak-D-Lite, which is inexpensive.

Since all the image calculations happen on the camera processor, a very small and cheap RPi, like the Pi Zero W (or Zero 2 W) is all you need. Both run the full Linux OS, with full OpenCV, and can also be connected to an inexpensive camera module with much higher quality than that on the ESP32-CAM.

Thanks that is useful.
I was considering using the esp32_cam as I like the small form factor and I have been trying to find some use for the one I have. But I should have a Pi3 with a camera in a box someplace (used it for an automated greenhouse project years ago) and it may be a much better platform for this.

Much appreciated!

This is just a project I have been tinkering with to use stuff I already have on hand. It's not worth spending any $ on. But thanks for the suggestion.

The ESP32_cam gave me the idea to try this but it is just something to tinker with. The suggestion by ec2021 about using a Pi is a direction I could go (because I already have one someplace) but this is not worth investing any more hardware than that.
But i appreciate the suggestion.

You may start with your existing equipment. If it's not sufficient you may follow @jremington 's suggestions...

That's fine. To get directions to object in the image, the first step is to calibrate the camera. That is, find scale factors that relate a point on an image in memory to a direction in reality, relative to the direction the camera is pointing.

This may give you some ideas

https://github.com/automaticdai/rpi-object-detection

It's titled

Raspberry Pi Real-Time Object Detection and Tracking

1 Like

That looks like it is something I can work with.
Much appreciated!

You're welcome...

Python makes using OpenCV very easy, if you prefer C++ this might be of assistance

https://qengineering.eu/opencv-c-examples-on-raspberry-pi

Link above is broken.

Thanks @jremington ,

seems this website does not support copied links...

However, if you follow the link you can navigate to the pages using the Hamburger menu:

  • Open the menu
  • Click on
    • Raspberry Pi
    • Raspberry Pi 4
    • Various
    • Code::Blocks

This is for a Pi 4.

If you use Google with "install opencv raspberry pi" you'll get a link to this page

that works for me but cannot just be copied.

Regards
ec2021

The link on Google looks like this

This might be even more interesting:

There is a comprehensive GitHub repository from
Qengineering

https://github.com/Qengineering

(Link double-checked :wink: )

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.