├── LICENSE ├── README.md ├── face_detection.py └── haarcascade_frontalface_default.xml /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Charles Calapini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Simple Facial Recognition with OpenCV and Raspberry Pi 4 2 | This repository contains a simple facial recognition system using OpenCV and Raspberry Pi 4. The system uses the Haar cascade classifier for facial detection and the Raspberry Pi's Picamera for video capture. 3 | 4 | The full tutorial is in: http://bit.ly/3ldDkj0 5 | 6 | 7 | ## Prerequisites 8 | Raspberry Pi 4 9 | Picamera 10 | OpenCV 11 | 12 | ## Installation 13 | Check that your Picamera is working properly by running the following command: 14 | ```libcamera-hello``` 15 | 16 | Update and upgrade your Raspberry Pi by running the following commands: 17 | ``` 18 | sudo apt-get update 19 | sudo apt-get upgrade 20 | ``` 21 | 22 | Install the required libraries by running the following command: 23 | ``` 24 | sudo apt-get install libjpeg-dev libtiff5-dev libjasper-dev libpng12-dev 25 | sudo apt-get install libavcodec-dev libavformat-dev libswscale-dev libv4l-dev 26 | sudo apt-get install libxvidcore-dev libx264-dev 27 | sudo apt-get install qt4-dev-tools 28 | ``` 29 | Install OpenCV by running the following command: 30 | ``` 31 | pip install opencv-python 32 | ``` 33 | 34 | ## Usage 35 | Clone the repository by running the following command: 36 | ``` 37 | git clone https://github.com/calapsss/face_detection_tutorial.git 38 | ``` 39 | 40 | Run the code by using the following command: 41 | ``` 42 | python face_detection_tutorial.py 43 | ``` 44 | 45 | ## Conclusion 46 | With this project, you can now build your own facial recognition system and get a hands-on experience in computer vision and machine learning. If you encounter any issues or have any questions, feel free to reach out to us through the GitHub repository. Our team will be happy to assist you in resolving any issues and answering any questions you may have. 47 | 48 | ## License 49 | This project is licensed under the MIT License. -------------------------------------------------------------------------------- /face_detection.py: -------------------------------------------------------------------------------- 1 | 2 | import cv2 3 | 4 | from picamera2 import Picamera2 5 | 6 | face_detector = cv2.CascadeClassifier("haarcascade_frontalface_default.xml") 7 | cv2.startWindowThread() 8 | 9 | picam2 = Picamera2() 10 | picam2.configure(picam2.create_preview_configuration(main={"format": 'XRGB8888', "size": (640, 480)})) 11 | picam2.start() 12 | 13 | while True: 14 | im = picam2.capture_array() 15 | grey = cv2.cvtColor(im, cv2.COLOR_BGR2GRAY) 16 | faces = face_detector.detectMultiScale(grey, 1.3, 5) 17 | 18 | for (x, y, w, h) in faces: 19 | cv2.rectangle(im, (x, y), (x + w, y + h), (0, 255, 0)) 20 | 21 | cv2.imshow("Camera", im) 22 | 23 | 24 | --------------------------------------------------------------------------------