Face and Movement Tracking Pan-Tilt System with Raspberry Pi and OpenCV

Hey Corey,

Yeah you were spot on with your previous comment, if you change the sign out the front of the x variable it should work😁

1 Like

:frowning_face: I appreciate the help & direction but unfortunately, this has not worked as of yet. I was able to adjust YOUR code and am happy with how it works but really want to try and get the patrol/sentry portion working.

I tried changing multiple portions of +/- and even >/< to see where the inversion could happen.

1 Like

Heyya mate,

So are the face tracking and the movement detection levels working correctly? Because in that case, it will be a + or - symbol needed in just the right place of the | def pan_search(x. y): | section of the code. If all of the layers are not targetting correctly (say identifying a face then pointing the camera away from it) the section you want to add that + or - is in the | def pan_goto(x,y) | section of the code. Trial and Error is an excellent method to brute force the solution.

Out of curiosity are you installing the Pimoroni HAT on the roof so it is upside-down?
Kind regards,
Tim

1 Like

I have been interacting directly with Claude about his code. I think we (he) have identified a solution. Thanks!

I’ll post it if it works!

1 Like

So I tried Claude’s suggestions but I think he may have been referring to a different code. I went back through and using your more focused suggestion, found what I needed (or at least it seems to work now).

def pan_goto( x, y):
""" Move the pan/tilt to a specific location."""
if x < pan_max_left:
x = pan_max_left
elif x > pan_max_right:
x = pan_max_right
pan(-(int(x-90))) # added '-' to invert
time.sleep(pan_servo_delay)
# give the servo's some time to move
if y < pan_max_top:
y = pan_max_top
elif y > pan_max_bottom:
y = pan_max_bottom
tilt(-(int(y-90))) # added '-' to invert
1 Like

To answer the latter question, I 3D printed a base & platform to mount the servos based on an idea I had. I later added the pimoroni HAT so I had not concept of servo l/r & u/d direction beforehand.

1 Like

Hey Tim,
I followed the guide carefully, it doesn’t always detect my face and makes sudden and big movements that put me out of focus. What could have gone wrong?

1 Like

Hello! So sorry to bother you! I am having difficulty when using the “cmake -D CMAKE_BUILD_TYPE=RELEASE / ETC” command on the Face and Movement Tracking tutorial. It says the cmake list is not found and -d is not recognized. I am doing this from the build directory, thank you! Have a great day!

1 Like

Hey mate,

Sounds like you are very close to a very successful tracker. If you jump to the |Config.py| file you will see settings like THRESHOLD_SENSITIVITY = 25 and BLUR_SIZE = 10. If you lower some of these values it won’t jump around when it shouldn’t be.

My bad for the slower reply, I had this response saved as a draft and must’ve forgotten to click the Reply button.

Kind regards,
Tim

Hey Harry

Just want to double-check first that you are using the older ‘Buster’ OS. Here is a guide to install it if not - How to Flash the Old 'Buster' Raspberry Pi OS to a Micro-SD - Tutorial Australia

If you are doing that just double check for me that you entered this line | sudo apt-get install build-essential cmake pkg-config | and that it runs correctly. That one has all the important information regarding cmake.

Kind regards,
Tim

Hi Tim! Just double checked the install line and it is all good there. I have a version of Buster installed but it is not that version, is that the issue? and if so, once I install that version do I need to not run any update commands to keep it at that version? Thanks, Harry

1 Like

Hey mate,

Update commands are perfectly fine it’s the upgrade commands ones to be wary of :blush:. Give it another run-through with a fresh version of ‘Buster’ OS and if that doesn’t work I’ll set up a version over here and figure out what is going on.

No matter what we will have your system up and running soon.

Kindest regards,
Tim

Sounds good, downloading version now and will let you know. Thank you for your quick and helpful replies Tim! Looking forward to letting you know soon!

1 Like

Hi again! I installed the older buster and it still doesn’t let me get past the cmake command, what should I do now? Is there anything I can do to help diagnose? Thanks, Harry

1 Like

Hey Harry,

I can see you are in the thick of it and currently I’m in the thick of doing a YouTube video. I have a feeling something weird is going on with the cmake package.

Until I can help you 100% (setting up your gear exactly the same here) come take a look at the original work by Claude that I based a lot of this content on. You can find it here - GitHub - pageauc/face-track-demo: Raspberry Pi python PiCamera, OpenCV Face and Motion Tracking using pan/tilt assembly via servo controller or gpiozero pwm - You will need to run the scripts I provided at the bottom of the page so that it works with the Pimoroni HAT but that will GitHub page will get all the Open-CV stuff up and running with his Curl Command.

Also pop through the exact specs of your hardware, and an image of what you are working with. Type History into your terminal command and pop a screen shot of that through as well.

Kind regards,
Tim

1 Like

I’m sorry Tim I don’t want to bother you in the middle of your video. I looked at the GitHub but unfortunately I can’t make much sense of it, I am new. Here is an image of what is happening and the history.

I hope I am not inconveniencing you, thank you, Harry.

Hi Harry,

The terminal tends to take things you blindly paste into it literally. When text goes to the next line, there’s a newline character in there that the terminal interprets as you hitting enter, without having entered the whole command.

Try typing that last command manually, or pasting each line individually making sure that no newlines are hitting enter for you prematurely.

That “no cmakelists.txt” error is a bit concerning, but try the above to see if that sorts you out, and the errors are related

2 Likes

This fixed it! I was doing it wrong the entire time. I completed the setup but now when trying to run the face tracking I get this error.

Thank you all for your help! Have a wonderful day.

1 Like

Hey Harry,

Excellent job progressing! You are very, very close now.

Someone earlier in this comment section ran into the same problem as you here. I got him to type and enter in the following terminal command which fixed it up for him:

| sudo apt-get install python-opencv python3-opencv opencv-data |

If that fixes your system then I’ll add that to the list of terminal commands.

Kind regards,
Tim

1 Like

Hi
Can this project be done without the PAN-TILT hat, with only two servo motors with the corresponding servo motor control board?

1 Like