Face Recognition With Raspberry Pi + OpenCV + Python
Вставка
- Опубліковано 2 сер 2024
- Subscribe For More!
Article with All Steps - core-electronics.com.au/tutor...
Teach your Pi to spot human faces, train it to know your face and run code so that it will successfully identify you when it sees you. Then use your face to control the GPIO!
Make sure to use the Previous Raspberry Pi 'Buster' OS with this Guide.
Related Information
Flashing 'Buster' OS onto a Raspberry Pi - core-electronics.com.au/tutor...
Face and Movement Tracking Pan-Tilt System For Raspberry Pi - core-electronics.com.au/tutor...
Object and Animal Recognition with a Raspberry Pi - core-electronics.com.au/tutor...
Hand Tracking & Gesture Control With Raspberry Pi - core-electronics.com.au/tutor...
Speed Camera with Raspberry Pi - core-electronics.com.au/tutor...
Control Your Raspberry Pi Remotely Using Your Phone (RaspController Guide) - core-electronics.com.au/tutor...
I will show you exactly how to have your Raspberry Pi credit card sized computer be able to spot human faces, how to train it to know your face and run code so that it will successfully identify you when it sees you. Then I'll take it another step and show you how you can use your face to control a servo attached to the Raspberry Pi. Open Source Software and Raspberry Pi go together hand in hand. Two excellent examples of this are OpenCV which provides a huge free resource to solve real-time computer vision problems and the Python Face Recognition Package which computes bounding boxes around a face in real-time. With it working we can do so many things with this now. Simply to start can now jump into the folders with the Python code and alter some lines of code so that every time a known face is seen it will send out signals via the GPIO pin of the Raspberry Pi. These GPIO pins can be used to control an almost endless amount of sensors and mechanisms. In this video I will get a servo to rotate when the Raspberry Pi system sees my face. If it sees someone else face or nobody's face it will not activate the servo. Huge thanks go to the Open-CV and Facial Recognition Package teams that work on the amazing machine learning software that we have running on the Raspberry Pi. Both are really good Open Source software. Also a huge thank you to Caroline Dunn whose created the amazing software that makes these two systems work so well together. There is just so much potential with this software to take projects to amazing places.
If you have any questions about this content or want to share a project you're working on head over to our maker forum, we are full time makers and here to help - coreelec.io/forum
Core Electronics is located in the heart of Newcastle, Australia. We're powered by makers, for makers. Drop by if you are looking for:
Raspberry Pi Official Camera Module V2 (used here): core-electronics.com.au/catal...
Raspberry Pi 4 Model B (4GB) Ultimate Kit Bundle (AVALIABLE!) - core-electronics.com.au/raspb...
Raspberry Pi 4 Model B 8GB: core-electronics.com.au/catal...
Makeblock 9g Micro Servo Pack (used here): core-electronics.com.au/catal...
Raspberry Pi High Quality Camera (Version 3): core-electronics.com.au/catal...
Raspberry Pi 4 Power Supply: core-electronics.com.au/catal...
0:00 Intro
0:10 OpenCV and Face Recognition Package Overview
0:33 Video Overview
0:54 What You Will Need
1:30 Set Up and Training The Model
4:30 Its Working!
4:50 Experimentation with Facial Detection
5:18 Where to Now? (Face Controlled Servo)
6:08 Demonstration
6:38 Acknowledgments
7:02 Outro
That was one of the best information instructional videos pertaining to The raspberry PI I have ever seen. You nailed it mate.
Is there any potential towards object recognition?
If so please make a video
Thank you very much, we do have a guide on object recognition in the works, keep an eye out. 😄
Got you sorted - ua-cam.com/video/iOTWZI4RHA8/v-deo.html
Great tutorial and the article comment section was so informative and helpful when I had issues. Can't wait for more awesome videos from you Tim!
Sweeet 😊 and new videos all the time!
Cool stuff, this was my disertation project! Face Recognition with Pan & Tilt tracking using two servo motors! :D Tip: use traditional machine learning like Histogram of Orianted Gradient or Haarcascade instead of Deep Neural Nets because they are soooo much faster! Also a good thing to look at is a PID controller. Cheers!
What a brilliant dissertation project 😊 here is how I tackled doing Face Tracking with a Pan-Tilt HAT system - ua-cam.com/video/T_892SKVNf4/v-deo.html
PID Control is definitely a worthy pursuit however as we are pushing the hardware to its full capacity there seems to be one that naturally occurs.
Awesome , great tutorial. I now have this running on my Pi4, MacBookAir and iMac.. Easy to follow and all links etc. provided. Thanks again. 10/10
Hi Steve and Tim,
I have installed the OS Pi Buster as you guided but in my PI File I didn't get 'Facial_Recognition' folder.
Thanks in advance for suggestions
Thank you so much for making these videos. They deserve so many views. You're awesome!
Very kind mate 🙂 I get excited making these videos, hope that comes through + lots left to explore.
Awesome project, Thanks for the steps to install open cv libraries.
Very happy to of helped 😄
Wow this is a great and very smooth tutorial!!!
Do you have both object and face detection with audio output???
Cheers mate 😊 If you like this you should check out Oak-D Lite with Raspberry Pi - ua-cam.com/video/7BkHcJu57Cg/v-deo.html
You can also definitely include Audio Output to the Python Scripts I have provided here.
People that live outside of the city need a version of this that can detect wildlife; bears, cougars, & alligators so they know if it is safe to open their door, doubly true if they have small kids or dogs that want to play in the yard & not be eaten.
Thanks mate I
it was one of the best info
Lot of your vids has helped me
Keep it up 👍👍
Hey, great video. I’m a little new to this and I was wondering how to get these li and facial recognition folders. I have python downloaded on my raspberry pi, but don’t have any of these folders. Thanks.
hello! can it be done with a photo?
i got an external source which saves images in a folder in my rpi overwriting it when it detects a face.
i want to run face recognition on that picture.
is there a way to use my image instead of the live streaming?
Awesome! I had some troubles along the way with the install but your support on the website is amazing. Thank you Tim!
Hello, great video man keep it going. I have a raspberry pi 3b+ and whenever i execute the code there is a 10-15 second delay. I tried both cameras like python one and a webcam and same result. When i try running a simple code there is no delay. What can i do?
Thank you so much !
Thank you man!
You're a beast mate, thanks for the video
Haha much appreciated, hope it helps you on a rad project 😄
You explain very well thanks
Glad it was helpful!
Hi! Would it be possible have the Raspberry Pi adjust the exposure so that the face is always properly exposed? If so, any idea how I can achieve this? Thank you!
Can anyone elaborate on the compatibility issues for OPEN-CV with the new Raspberry Pi ‘Bullseye’ OS mentioned in the article?
hi tim, i just want to ask how to make your motor servo back to 0 degrees if its not detecting any objects thankss
How far is the camera can scan face? If this use as CCTV camera that need to place so much far like around 3-4 meters from people, does it recognize the face as well?
I am very new and how different it is from bookworm? Also Picamera is no longer available now it is libcamera do you have a tutorial with libcamera. ALso is it possible to avoid pip since we have to create venv . Thanks a lot for your help.
Awesome Project
Is it the same with using the high quality camera?
the best tutorial in its field :)
I have one problem only, that is my devices doesn't support picamera, it support picamera instead, so that VideoStream method is not working
Well done. :)
Hello! Great tutorial! Is there a way where we can improve the frame rate? The program is able to recognize my face but the frame rate is very low. I am not using a raspberry pi camera, just a random USB webcam.
Also, I am facing an issue where another person comes into frame, instead of showing "unknown", it displayed my name instead. I tried taking 40 images instead of 10 but the result is still the same. Please let me know if you have any way to solve this. Thank you!
Can I ask which Raspberry Pi you are using? Using the highest Spec Pi possible is always my first recommendation. Using a TPU accelerator like the Google Coral edge TPU will also provide some signification FPS gains.
Also it surprises me that it isn't identifying correctly, potentially providing it with fewer than 10 images will yield better results in your particular use case. Hope this helps!
wonderful
My code needs to use the values from the pickle file so cd myfolder must be used before it can run. Is there a way to write a script run? Please.
Brilliant, thx!
You're welcome!
I had done this using arduino in 2020 . I had use led bulb instead of servo motor
hai! Nice video, Can you tell me what Is the accuracy like and how many I can train? As I had a few face recognition project experiences there is very little accuracy and i have tried using various libraries like face recognition using python in my raspberry pi.
Hi, For that camera does it detect human even in the dark, smoke or in fire
My robot projects are about to get WAAAAAAAAAAAAY creepier. I love it.
Have fun and use your new found computer superpowers for good 😊
Hey Timmy,
Thanks a lot the video is great.
We are actually looking how to close the servo motor back after it opens .
Can you please help us out.?
Thank you!
Heyya, everything you need to understand exactly how to do that you can find here 😊 - core-electronics.com.au/guides/control-servo-raspberry-pi/
How can i use regular usbwebcam for this?
How i can setup it using esp cam and live object recognition and its should give output in speaker
This a major help for me ... great tutorial .. One question though .. is there a way to unlearn a face .. so the systme does not recognise it any more
Absolutely, just delete that folder where you have those photos that it has trained on. That should be enough to stop it knowing someone (without having to go through the installation process again)
@@Core-Electronics yeah was messing around and understood that could be done .. 😁🫡 .. thank you so much 😁
Great, thanks, is there a pan and tilt motion tracking mode available??
Heyya John Holland come check out this video I did on exactly that - ua-cam.com/video/T_892SKVNf4/v-deo.html
It'll get you right into the thick of it 🙂
Am I wrong in assuming that the project can't run standalone, e.g. with a power supply and no connections to a computer once the program has been uploaded? Or will it always need to be "plugged" in? Thanks for the great video!
You can run face detection without a display. So if you can remotely/headlessly start the Python Script (using your phone like this guide here is a good way to do that - core-electronics.com.au/guides/raspcontrol-raspberry-pi/) it'll run just like normal.
So if you ran that servo script, if you showed it your face it'll work as it should and activate that servo, with or without a display.
Hope that helps 😊
@@Core-Electronics Hi, the link you provided is not available :(
I have this project :
"Design of Driver Awareness system depending on Eye and Face Feature and Discrimination"
Can I use ESP32 instead of Raspberry Pi? Please answer
Can this project can be considered under iot hardware project?
Can you use Microsoft Azure face api on this and use it for unlocking the gate using solenoid lock.
is there any way to improve the fps when it's searching live for faces?
Please tell me , which algorithm is used for facial recognition.
name?
BTW love your videos.🔥❤️
Viola Jones Algorithm is what your looking for. If it was just Haar-Cascade Detection you wouldn't be able to identify different faces as easily.
Hi did this images wasn't the folder do you rename the photos folder ?
Hi Tim, can we run our face recognition program and live stream on local host at same time? if yes , can you please guide me?
You can definitely live stream the camera results out of the Raspberry Pi so long as your internet its up to the task. It will slow down the Raspberry Pi slightly however. Come jump onto our forums if you need a hand with any project 😊
Could I be able to get it to play an audio file instead, and how would I go about implementing that into the script?
you can just google how to play sound in python, and put that code instead of the 3 lines for the servo
Hey! can you please leave a link for the preinstalled opencv image? Would help a lot
Wish I could. I did make an image for it but there is no good way of distributing the large image file in a manner which is future proof.
It will take some time but I have proofread each step to install OpenCV and the dependencies from scratch, so you absolutely won’t run into any errors, it just takes a little time to do so.
very good project bro, do you think I can use a usb webcam, as a camera instead of the raspberry one???
Absolutely mate! Just check the bottom of the | Demonstration | chapter to see how to modify one line of the script to do so 😊
Hello!
What if I were running OpenCV code from the Pycharm IDE. How would pair the raspberry pi camera instead of the webcam that I am using for the code?
Pycharm IDE is just a Python interpreter software just like Thonny IDE, so all the scripts here will work in either. If your using a Pi Camera all the scripts talked about here will work straight away, you will need to alter some values in the script if your using a USB webcam.
How do I reduce the quality of my camera? It defaults to 4056x3040 which is way too large and it drops my frames like crazy. I have the RPI 4 8GB RAM
In the main script you will find this line of code | frame = imutils.resize(frame, width=500) |. Edit that 500 to be a smaller number to increase your FPS 😊
tnx , love u 🤩🤩🤩
You're welcome 😊
what are all the software used for this to work?
Hey can you iris recognition with raspberry pi?
can this also work with an IR camera for night vision?
I haven't run this exact machine learnt system with an IR camera but it should work fine 😊
hi tim
after putting the cd facial_recognition (4.00)
my raspi keeps saying ;
bash: cd: facial_recognition: No such file or directory
Did I need a different program for the pi as the link you have provided is for pan and tilt system of witch I don't intend to use ?
Not quite sure what you mean but the full article (with everything you need for this video) can be found here - core-electronics.com.au/tutorials/face-identify-raspberry-pi.html
@@Core-Electronics So I'm now setting up my pi with the full article and just added the terminal line (cmake -D CMAKE_BUILD_TYPE=RELEASE \) but it looks like it has crashed I pressed return and I have the following symbol > this is the second time this has happened help
Hey mate, is totally okay seeing that | > | symbol. Just continue on with the next terminal line | -D CMAKE_INSTALL_PREFIX=/usr/local \ | and so forth. Then once you get to | -D BUILD_EXAMPLES=OFF .. | it will return to normal terminal command lines without the | > |. Hope this help!
Hi there, we downloaded open cv in diff path, we are trying to run your code but face this prob
-> _model.py
Traceback (most recent call last):
File "/home/pi/raspberry-pi-opencv/facial_recognition/train_model.py", line 5, in
import face_recognition
ModuleNotFoundError: No module named 'face_recognition'
Anyone help!
Would definitely recommend going through the process outlined in the Written article. I ran into all kinds of problems trying to download Open-CV and getting it to run using different methods/paths.
can i open the face recognition with node red?
how to stream the content to other local device
video on that pls
Is the redbarry pi fecial recognition triggered by physical photo's? Or is it smart enough to distinguish real humans and photos?
I reckon you'd be able to trick it with a photograph.
hello does this python code work on raspberry pi 3 model b+
Hi I am getting an error when I try to increase the swap size. when I enter sudo nano /etc/dphys-swapfile
After pressing enter, the error appears saying [error reading lock file /etc/.dphys-swapfile.swp: nog enough data read]
what is causing this?
I think your swapfile is corrupted. Give yourself a treat and flash yourself a new fresh version of Raspberry Pi 'Buster' OS and tell me if that problem happens again 🙂
TNice tutorials
when building make -j$(nproc)
it freezes at 99% at Built target opencv_perf_superres
any solution tried twice froze at same spot
What algorithm did you use for face recognition?
A number of parts all come together to make this possible. I link some of the most important packages here - pypi.org/project/face-recognition/ opencv.org/ pypi.org/project/imutils/
Can you please share the gpio connection to servo motor wire connection to which gpio number?
Come check out this guide which will have everything you need to know 🙂 - core-electronics.com.au/tutorials/control-servo-raspberry-pi.html
Hello, I'm trying to follow the tutorial but I can't find the folder ''facial_recognition''. How do I find her?
Yo can we use a raspberry pi 0w for this project
Do you have coding for confidence value that can put in facial_req.py ?
Have a look at this fellows work in regards to confidence values - pyimagesearch.com/2018/09/24/opencv-face-recognition/
can i do this with rasphberry pi 3b+ without any issues? can anyone reply to this ASAP.
Timmy, are you still assisting individuals with questions or if they run into a problem with your video?
My man absolutely I am 😊! Usually the best place for more complicated questions would be at the bottom of the full written up article in the comment section (because you can add photos/screen caps) and I'm guaranteed not to miss them - core-electronics.com.au/guides/face-identify-raspberry-pi/
great lesson but may i have for train and recognize script of python please
core-electronics.com.au/guides/object-identify-raspberry-pi/ There you go mate 😊
typo on website : Facial Recogonition, why the Q in facial_req.py ?
Cheers for pointing that out mate 😊 and that's just how the Python script has been named in reference to this script requiring faces that it has trained with to identify people.
Hi, when I try to execute python facial_req.py I get the following error [ WARN:0@5.322] global /home/pi/opencv/modules/videoio/src/cap_v4l.cpp (902) open VIDEOIO(V4L2:/dev/video2): can't open camera by index. Is this an issue with the OpenCV installation?
Come jump onto the Full written up article and check the comment section. A lot of successful trouble shooting can be found there.
This is a Camera Index setting that you just need to make a quick adjustment in the Python code. I talk about it explicitly in the bottom paragraph of the Demonstration section - core-electronics.com.au/guides/face-identify-raspberry-pi/#Demon
I dont have a facial recognition folder in my home/pi folder
If you type the below line of code it will give you the required folder.
git clone github.com/carolinedunn/facial_recognition
Hey, can this be done with a wsb webcam?
USB Web cameras definitely work. Come check the full written up article to see how to 😊
Dear,I can not use opencv with thony ,can you explain me how to install opencv matplot to run on thony ?thank
Jump to the full write up article and you'll find both troubleshooting in the comments and a full step-by-step process to install the face recognition software.
I can't find the setup link you mentioned we need to download?
Here are the set up terminal commands - core-electronics.com.au/guides/face-identify-raspberry-pi/#Long - Follow through exactly and you'll be good to go 😊
How can i add a door lock sistem with a solenoid using facial recognition ?
You can use a majority of this script and customise it with knowledge from this guide - core-electronics.com.au/guides/solenoid-control-with-raspberry-pi-relay/
I also created a similar system using Biometric control in this guide here - core-electronics.com.au/guides/raspberry-pi/fingerprint-scanner-raspberry-pi/
hi i have problem with the train part there is a error shown that no module named imutils can i know how to solve it
Come check the comment section at the bottom of the full written up article. There will be a solution for you there 😊
Hi Tim when I write this part ( make -j$(nproc) )
this error jump to me
(error: unrecognized command-line option ‘-param=ipcp-unit-growth=100000’; did you mean ‘-param=ipa-cp-unit-growth=’?)
what should I do
Need some help, please
Double check everything you have written before is correct. Re-type | make -j$(nproc) | and if you keep running into issues come jump into the forum/comments in Written Article. A lot of successful troubleshooting there and I'll be better able to help you until we get it working 🙂
After running in thonny following errors come " ImportError: numpy.core.multiarray failed to import"
could you mention,where are gpio pin numbers in code?
In answer to both questions you can find the GPIO control that I added in | TimServo.py | at the top of the code (around line 12 and lower down in the looping section (around line 96). Happy coding 😊
What if I want the data of detected persons to be stored in the memory, and the second part is that Can I detect objects and save them with the data of a specific person who detected the object in the camera?
You can definitely alter the code so that it takes a snapshot/video recording every time a face is seen. In regards to object detection I've put together a guide on doing just that, linked in the description.
Combining both Object and Face detection as a single system is doable, something I'd love to pursue.
@@Core-Electronics ok man thanks would try
I've downloaded opencv but I still get an error of "no module named cv2", and I'm not sure how to fix it?
Come jump onto the comment section of the written article. A lot of successful troubleshooting has happen there and if the solution to your problem isn't there I'll help you out until we get your system running 😊
Hi guy. Fps in my project is less than 1. Can you instruct me to increase fps to recog faster? Thank you very much
All depends on the hardware that you are using. If you want some real fast Facial Recognition that can get fed into a Raspberry Pi check out this product here - core-electronics.com.au/luxonis-oak-d-depthai-hardware.html
Hi, will this face recognition project work properly on Raspberry Pi 5 with the latest official camera v3 as well?
Not this guide specifically sorry. The packages for this guide were designed to work on Buster OS which the Pi 5 cannot run. We do have some new Pi 5 vision guides in the works though!
Not working I installed all libraries but i still getting errors. Some errors I fixed but i can´t fix: "AttributeError: 'NoneType' object has no attribute 'shape'
" maybe you can make full tutorial with installing all libraries etc.
The full article does go through the whole process of installing Open-CV but it would definitely be worthwhile making a video guide on the process, particularly once Open-CV and the new 'Bullseye' Raspberry Pi OS release has full compatibility.
In regards to fixing your issue, it is important to run the old 'Buster' Raspberry Pi OS as this currently is the only compatable OS with Open-CV. Here is a guide on how to do that - core-electronics.com.au/tutorials/flash-buster-os-pi.html.
If you still run into issues open up a forum topic and I'll help you through the whole process there 😊
hello mate, I got the same error, did you manage to fix it ?
Can you do a full guide on how to get it to work in the Magic mirror Please.
I love that idea, we do have a very sweet project creating a Magic Mirror here to base some ideas from. core-electronics.com.au/projects/smart-mirror-with-raspberry-pi
It would be epic for it to provide a different UI depending on who it sees in front of the mirror. Let me see what I can do 😃
@@Core-Electronics i also have MMM-Google assistant v3 on my magicmirror (without mirror) that has Spotify and youtube with voise control as well as MMM-pages so i can ask GA to go to my calendar and it go to a page with it as a full screen this make the mirror capable of holding more Modules but i like the idea that the screen only turns on once face recognition pick my face as well only opens my calander when i stand in front and if someone else stands in front it opens there calander.
I'm doing the same project as well and require face detection/recognition to work in the mirror. However I couldn't find a good article/video that explain how to do it in detail.
Hi. Is it possible to create a GUI that can link this python script? If yes, what language can I use?
Absolutely. I talked a little bit about GUI in my Python Workshop, I will link to it here - core-electronics.com.au/guides/python/Tkinter-Python/
There are also many different ways to create GUI, Java is a very common language to do so.
if i use a usb webcam does the camera still work? sorry newbie.
Absolutely it will work - some things will need to be altered in the Scripts and a different script needs to be used to take the initial images that it learns from but everything you need is provided in the written up guide 🙂
Can I use a webcam instead of the camera module ?
Absolutely you can use a USB powered web camera. Check the bottom of the demonstration section in the Full Written Up article to see how - core-electronics.com.au/guides/face-identify-raspberry-pi/#Demon
I want to increase fps. Its not usable at present.
Using raspi 3b.
If you interested on running Face Recognition on the edge (with your current hardware) I highly recommend checking out the OAK-D Lite - core-electronics.com.au/guides/oak-d-lite-raspberry-pi/
Your FPS will be through the roof!
Heyya mate, can it control several servos?
You absolutely can. Check out this guide for controling one or two servos core-electronics.com.au/guides/control-servo-raspberry-pi/ - and this one for controlling heaps of Servos with a Raspberry Pi - core-electronics.com.au/guides/servo-hat-raspberry-pi/.
the facial_recognition folder is not forming after multiple attempts
I pressed the Q key but the cam window won’t close ? Please help
Hey Bro, Don't talk down to yourself like that. believe in yourself and don't let nobody change your mindset of that!
Can you help me with my project?