Hi Tim,
Novice alert! After trying may ways, finally your code is working like a charm. I wanted the led to be off if ‘unknown’ face is detected and led on if it recognized a face. So I added two lines of code:
‘if currentname != name:# =/
currentname = name
print(currentname)
led.on()
#Take a picture to send in the email
img_name = “image.jpg”
cv2.imwrite(img_name, frame)
print(‘Taking a picture.’)
if not True in matches:
led.off()’
Now, the LED is certainly switching off with “unknown”, however, this works only for one time. After switching off, even if a face is recognized, it does not switch on the LED again. I have to stop the program and restart it again and it again runs for only one time. No errors show up.
Would be super glad if you could help…Thanks anyway for your super code!
Hi Tim,
Is this forum still active? I’d really love your help!
Greetings
Heyya mate,
Totally active forum it has just been all hands on deck busy over here last week. I’ve had other people bring up GTK Backend problems before and it has always had to do with the libgtk2.0 package. Could you try for me typing and entering | apt-get install libgtk2.0-dev | into a new terminal window. I reckon that should fix you up right away.
Excellent effort troubleshooting up to this point, if that doesn’t fix you right up I have some other terminal commands that should do the job.
Kind regards,
Tim
Hey Darsh,
It’d be easier for me if I could see all of the script, perhaps you can add it as an attachment but happy to provide a general overview of whats probably going on. If you dont have a Loop in the Python script then the system will go through each lines One by One and stop once it reaches the end of the script. Here is a guide all about making Loops and Iterations inside Python Programming Language.
So I reckon your block of code is outside of the constantly looping section of the Face Recognition Script. With a little bit of code rearrangement + paying close attention to indentation, you will have a functioning script exactly the way you want .
Kind regards
Tim
Thanks for getting back to me!!
Unfortunately the command did not do the trick. It says it has already been installed on the system.
When trying to start run python facial_req.py.
Any other possible fixes?
Thank you in advance!
Hi tim, I hope you can answer me!!! How can I increase the fps of the camera on a rasbperry pi 3 ?
Hey Zo,
Let’s now take the Terminal commands up a level and start using Sudo privileges to force re-install some of the packages. Hopefully one of the two lines below will get your system working as it should.
| sudo apt-get install build-essential cmake pkg-config |
| sudo apt-get install libgtk2.0-dev |
It looks like this person ran into a similar issue as you - python - How to include libgtk2.0-dev and pkg-config in cmake when installing openCV on Ubuntu 16 - Stack Overflow. Potentially if the above doesn’t pay off the solution would be to go through the installation process again making sure to install all the required packages before starting the Cmake Process.
Fingers are crossed for you ,
Tim
Hey Vick,
In the Python script you can make the preview window have fewer pixels. That will result in instantly observable speed improvements but a lack of video quality. Also including fewer system-trained/identifiable people will result in higher FPS.
You can also incorporate new hardware to the system like the Oak-D Lite. Come check my guide on that if your are interested - Integrated Computer Vision Package - OAK-D Lite With Raspberry Pi Set Up - Tutorial Australia. Using that hardware will drastically improve the FPS of AI systems running with a Raspberry Pi.
Hope this helps,
Tim
Thank you very much, I’ll start to investigate right now… I hope it will work out.
Hi Tim,
I tried to make it work, but still receive the same error. Even re-entered all the commands to install CV. All commands worked but I still get stuck on the last command when trying to test out if the face recognition works.
I finally got i working using this a tip from this forum: python - Opencv works with raspberry pi locally but not thru network - Stack Overflow
It advised to enter ‘export DISPLAY=:0.0’ Which got it working right away.
So now I got it working! Thank you for all the help and quick reaction!!
I have one more question but don’t know if you have any expertise in this area. I’d like to set all of this up with home assistant. I found OpenCV - Home Assistant but get seem to get it working. If you do have any expertise how to integrate this I’d love your help!
Thanks again!!
Greetings Zoë
Heyya Zoë,
Ecstatic that you got your Face Recognition up and running thanks kindly for coming back and writing up how you fixed it. Immensely helpful.
Now I haven’t dived into OpenCV with Home Assistant but this fellow has set up Home Assistant with Face Recognition and written up a good forum post linked here - OpenCV Home Assistant - Share your Projects! - Home Assistant Community. That should provide a good outline of how to integrate these two systems together.
All the best,
Tim
hi tim,
great guide. I am waiting on a PiCam to be delivered. In the meantime do you think I could get the face recognition scripts to work with a USB WebCam.
if so what lines would I need to change in headshots_picam.py
Hey Alan,
You definitely can check the bottom of the Description chapter in the full article. I will link it here - Face Recognition With Raspberry Pi and OpenCV - Tutorial Australia
That will provide you with everything you need to know to get this system to work with a USB Web camera.
Kind regards,
Tim
thanks Tim , I didnt spot the following on the first read.
BTW. after installing OpenCV with the instructions below
when running python scripts using OpenCV I get the following errors repeatedly using different scripts from different folks
is this because I am using bullseye rather than buster or does it relate to a pip-wheel install issue. It looks like pip-wheel is running from a TMP folder.
Traceback (most recent call last):
File "/home/pi/VidCapture.py", line 7, in <module>
cv2.imUnshow('Imagetest',image)
cv2.error: OpenCV(4.5.3)
****/tmp/pip-wheel-**hwcmjluw/opencv-python_dc56ddd000dd4893b1f852d88d4a5959/opencv/modules/core/src/array.cpp:2494: error: (-206:Bad flag (parameter or structure field)) Unrecognized or unsupported array type in function 'cvGetMat'** ```
Hey Alan,
For the above tutorial to operate correctly it is crucial to use the earlier ‘Buster’ Raspberry Pi OS. Packages are constantly getting updated/upgraded but as you’ve experienced the compatiability isn’t quite there yet.
I’ve made a guide on flashing ‘Buster’ Raspberry Pi OS which you can find here - How to Flash the Old 'Buster' Raspberry Pi OS to a Micro-SD - Tutorial Australia
Hopefully that helps,
Tim
Could you solve your problem and could you share your full code?
Hi,
I recently tried this out and got it working (or at least partly). I run into an issue if I train the model. The training (train_model.py) always stops after 26 images without an error message or any indication as to why that is happening.
Anyone encountered that before or has an idea as to how to prevent it?
Cheers
Hey Artem,
I’ve only utilized 6 images in the Train model step. If you only want one person that should be more than enough. If you want multiple people to be recognised make sure to separate each person’s photo bunch in its own unique folder. I tend to name those folders after the person’s name.
With too many images to recognise it can cause the system to go slow.
Hopefully that helps,
Tim
Hi Tim,
Love the walk through, thanks so much for the effort to document this!
I followed your steps (flashed buster image, followed terminal steps up to
~/opencv/build $ cmake -D CMAKE_BUILD_TYPE=RELEASE
but got the error below.
pi@raspberrypi:~/opencv/build $ cmake -D CMAKE_BUILD_TYPE=RELEASE
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error: The source directory "/home/pi/opencv/build" does not appear to contain CMakeLists.txt.
Specify --help for usage, or press the help button on the CMake GUI.
I went to the open cv git and I see the CMakeLists.txt. file listed. I copied the file into build folder and then tried ~/opencv/build $ cmake -D CMAKE_BUILD_TYPE=RELEASE
again but got
pi@raspberrypi:~/opencv/build $ cmake -D CMAKE_BUILD_TYPE=RELEASE \
>
CMake Warning:
No source or binary directory provided. Both will be assumed to be the
same as the current working directory, but note that this warning will
become a fatal error in future CMake releases.
CMake Error at CMakeLists.txt:11 (message):
FATAL: In-source builds are not allowed.
You should create a separate directory for build files.
-- Configuring incomplete, errors occurred!
Any suggestions?
The error cause is that you have set the camera to pi camera if you are using pi camere in facial_req.py.
That is edit in
initialize the video stream and allow the camera sensor to warm up
Set the ser to the followng
src = 0 : for the build in single web cam, could be your laptop webcam
src = 2 : I had to set it to 2 inorder to use the USB webcam attached to my laptop
#vs = VideoStream(src=2,framerate=10).start()
vs = VideoStream(usePiCamera=True).start()
like above