Hey! So I built this facial recognition app that actually works pretty well. It uses OpenCV's LBPH algorithm and can recognize faces with around 85-92% accuracy once you've fed it some good samples. No crazy compilation steps needed β just Python and you're good to go!
- β¨ Pretty Accurate: Gets it right 85-92% of the time with the LBPH algorithm (just make sure to give it quality samples)
- π₯ Live Recognition: Pulls from your webcam and recognizes faces on the fly
- π€ Easy Setup: Adding new faces is super straightforward
- πΈ Smart Sampling: Grabs 10 photos of each person to really learn their face
- πΎ Remembers Everyone: Stores everything in a SQLite database
- π₯οΈ Clean Interface: Built with Tkinter, so it's simple and works everywhere
- βοΈ Manage Profiles: Add people, remove them, or start fresh whenever you want
- π§ IntelliJ Friendly: Works great in IntelliJ IDEA if that's your jam
- Python 3.7+ β The brain of the operation
- OpenCV-contrib β Handles all the face recognition magic
- NumPy β For crunching numbers
- Tkinter β Nice and simple GUI
- SQLite β Keeps track of all the face data
- Python 3.7 or newer
- A webcam (or any camera, really)
- Windows, Linux, or macOS β doesn't matter
Head over to python.org and download Python 3.7+.
Pro tip: When installing, make sure you tick "Add Python to PATH" β trust me, it'll save you headaches later!
Pop open your terminal or command prompt in the project folder and run:
# First, let's make sure pip is up to date
python -m pip install --upgrade pip
# Now install everything we need
pip install -r requirements.txtShould only take a minute or two!
python -c "import cv2; print('All good to go!')"If you see "All good to go!", you're set!
-
Get the Python Plugin:
- Open
File > Settings > Plugins - Search for "Python"
- Install it and restart IntelliJ
- Open
-
Connect Your Python:
- Go to
File > Project Structure > SDKs - Hit
+then pick "Add Python SDK" - Find your Python installation (probably something like
C:\Python310\python.exe) - Click OK
- Go to
-
Link It to Your Project:
- Head to
File > Project Structure > Modules - Select that Python SDK you just added
- Hit Apply and you're done
- Head to
- Open
main.pyin IntelliJ - Right-click anywhere in the file
- Click
Run 'main'
Or if you prefer the terminal:
python main.pyJust run:
python main.py- Hit "βΆ Start Camera" to turn on your webcam
- Type their name in the Name box
- Click "Register New Face"
- Look at the camera β the system will snap 10 photos automatically
- Move your head around a bit between shots (helps with accuracy!)
- That's it β they're in the system!
Want the best results?
- Good lighting is your friend
- Look straight at the camera
- If you wear glasses, maybe register both with and without?
- Watch out for shadows on your face
- Slight head movements (tilt, turn) help it learn better
- Make sure the camera's on
- When someone registered shows up, you'll see a green box with their name and how confident the system is
- Unknown folks get a red box β sorry, stranger!
- View Registered Persons: See everyone who's in there and how many samples you got
- Delete Person: Remove someone (maybe they left the team?)
- Clear All Data: Nuclear option β wipes everyone (be careful with this one!)
FacialRecogniton/
βββ main.py # The main app with the GUI
βββ face_recognition_engine.py # Where the recognition magic happens
βββ database_manager.py # Talks to the SQLite database
βββ camera_handler.py # Handles the camera stuff
βββ requirements.txt # All the Python packages you need
βββ face_recognition.db # The database (appears on first run)
βββ README.md # You're reading it!
βββ src/ # Old Java code (just gathering dust now)
This thing uses LBPH (Local Binary Patterns Histograms) from OpenCV:
- Finds Your Face: Uses Haar Cascades to spot faces in the frame
- Analyzes It: Breaks your face down into local patterns
- Creates a Fingerprint: Makes a unique histogram for your face
- Compares: When it sees a face, it compares the histogram to what it knows
- Decides: If it's close enough, it's a match!
Why LBPH is cool:
- Doesn't need a ton of computing power
- Pretty forgiving with lighting changes
- Works even if you're at a slight angle
- Fast enough for real-time recognition
- Gets better with more samples (hence the 10 photos!)
- Snaps 10 photos from different angles
- Creates a unique pattern for each one
- Saves it all to the database
- More samples = better recognition later
- Spots a face in the camera
- Creates its pattern
- Compares it to everyone in the database
- If the difference is small enough (default threshold: 50), it's a match!
- Shows you the name and how confident it is
- Is it actually plugged in and working?
- Close Zoom, Teams, or anything else hogging the camera
- Try a different camera by editing
camera_handler.pyline 22:CameraHandler(camera_index=1)
pip uninstall opencv-python opencv-contrib-python
pip install opencv-contrib-python- Try re-registering them with better lighting
- Get more varied angles when taking the 10 samples
- You can tweak the threshold in
face_recognition_engine_opencv.pyβ lower numbers are stricter, higher are more lenient
- Lower the camera resolution in
camera_handler.py:self.cap.set(cv2.CAP_PROP_FRAME_WIDTH, 320) self.cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 240)
You can adjust how picky it is by editing the threshold in face_recognition_engine_opencv.py:
confidence = int(100 * (1 - (label_distance / 300))) # Play with that 300!Lower = more strict, higher = more forgiving
Want more or fewer photos during registration? Edit main.py:
self.target_samples = 15 # Or whatever number you wantMore samples generally = better accuracy (but takes longer to register)
Here's how this stacks up against the old Java version I had:
| What | Old Java Version | This Python Version |
|---|---|---|
| Accuracy | ~70-80% | ~85-92% |
| Algorithm | LBPH (basic) | LBPH (optimized) |
| Setup | Painful | Super easy |
| Code | 712 messy lines | ~400 clean lines |
| Dependencies | Native libs (ugh) | Just pip packages |
| Maintenance | Nightmare fuel | Actually pleasant |
- OpenCV for doing the heavy lifting
- The folks behind NumPy for fast math
- Tkinter for making GUIs bearable
- SQLite for being a solid little database
This is just a learning project β feel free to use it however you want!
If something's not working:
- Check the troubleshooting section above
- Make sure you installed everything properly
- Verify your camera has permissions
- Try better lighting β seriously, it makes a huge difference!
That's about it! If you run into issues or have questions, feel free to dig into the code or hit me up. Happy face recognizing! π