This is a React-based face detection application that uses the @mediapipe/tasks-vision library to detect faces from a webcam feed. The application captures an image from the webcam, checks if the face is straight, and allows the user to download the captured image.
- Detects faces in real-time using the webcam.
- Captures a square image of the detected face.
- Ensures that the captured face is straight and centered.
- Allows downloading the captured image.
To run this application, follow these steps:
-
Clone the repository:
git clone https://github.com/your-username/face-detection-app.git cd face-detection-app -
Install the dependencies:
npm install
-
Start the development server:
npm start
- Open the application in your browser. You should see a button to open the camera.
- Click the "Open camera" button to start the webcam feed.
- Ensure your face is centered and straight in the camera view.
- Click the "Capture Image" button to capture an image of your face.
- If the captured face is straight, the image will be displayed below the webcam feed.
- Click the "Download Image" button to download the captured image.
cameraOpen: A boolean state to toggle the camera on and off.faceLandmarker: Stores the initialized FaceLandmarker object.faceResult: Stores the result of the face detection.isVideoReady: A boolean state to check if the video feed is ready.capturedImage: Stores the captured image.
Webcam: React component for accessing the webcam feed.useRef: A hook to reference the webcam component.useEffect: A hook to initialize the FaceLandmarker and handle side effects.
initializeFaceLandmarker: Asynchronously initializes the FaceLandmarker.detectFaces: Detects faces in the webcam feed using the FaceLandmarker.handleVideoReady: Sets the video ready state when the webcam feed is ready.isFaceStraight: Checks if the detected face is straight based on blendshapes.cropToSquare: Crops the captured image to a square.captureImage: Captures an image from the webcam, checks if the face is straight, and stores the cropped image.downloadImage: Downloads the captured image.
- A button to toggle the camera.
- The webcam feed container.
- Buttons to capture and download the image.
- Displays the number of detected faces.
- Displays the captured image if available.
react: JavaScript library for building user interfaces.@mediapipe/tasks-vision: Mediapipe library for vision tasks.react-webcam: React component for accessing the webcam.
This project is licensed under the MIT License.