A webcam virtual try-on for glasses and hats, written in Python.
MediaPipe Face Mesh finds facial landmarks each frame. The distance between landmarks sets the size of the accessory, its position follows the face, and the PNG (with transparency) is blended onto the frame with OpenCV.
test.py: the core: loads the accessory images, runs face mesh, scales and positions the overlay.ui,py: the PyQt5 front end that shows the camera view and switches accessories (the filename has a typo from when I created it).
In the OpenCV view: g cycles glasses, h cycles hats, q quits.
pip install opencv-python mediapipe numpy PyQt5
python test.pyYou need your own transparent PNGs named in the glasses_paths and hats_paths lists at the top of test.py. They are not included.
More accessory types, and recommending styles based on face shape.