Skip to content

chiragn28/Smart_basket

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Recognition with YOLO

This is a Python script that performs face recognition using the YOLO (You Only Look Once) object detection algorithm. It utilizes the cv2, dlib, and face_recognition libraries to accomplish the task.

Prerequisites

Before running the script, make sure you have the following requirements installed:

  • Python 3.x
  • OpenCV (cv2)
  • dlib
  • face_recognition
  • YOLO weights (yolov3.weights) and configuration (yolov3.cfg) files
  • Dlib face recognition model (dlib_face_recognition_resnet_model_v1.dat)
  • Input video file (ronaldo_singapore.mp4) or adjust the code to use a different video source

Setup

  1. Install Python 3.x if it's not already installed on your system.

  2. Install the required Python libraries using pip:

    pip install opencv-python dlib face_recognition
  3. Put or download the YOLO weights (yolov3.weights) and configuration (yolov3.cfg) files from the official YOLO website or other trusted sources.

  4. Put or download the Dlib face recognition model (dlib_face_recognition_resnet_model_v1.dat) from the official Dlib repository or other reliable sources.

  5. Prepare your known faces for recognition by adding their encodings and names to the script. Update the following code block with your own images and corresponding names:

    known_face_encodings = []
    known_face_names = []
    known_face_encodings.append(face_recognition.face_encodings(face_recognition.load_image_file("ronaldo1.jpeg"))[0])
    known_face_names.append("Ronaldo")
    known_face_encodings.append(face_recognition.face_encodings(face_recognition.load_image_file("ronaldo2.jpeg"))[0])
    known_face_names.append("Ronaldo")
    known_face_encodings.append(face_recognition.face_encodings(face_recognition.load_image_file("ronaldo3.jpeg"))[0])
    known_face_names.append("Ronaldo")

Usage

  1. Place the script file (face_recognition_yolo.py) in the same directory as the downloaded YOLO and Dlib model files.

  2. Adjust the file paths in the script to match the locations of the YOLO and Dlib model files:

    net = cv2.dnn.readNet("yolov3.weights", "yolov3.cfg")
    face_model = dlib.face_recognition_model_v1("dlib_face_recognition_resnet_model_v1.dat")
  3. If you're using a different video file for input, update the following line in the script:

    cap = cv2.VideoCapture("ronaldo_singapore.mp4")

    Replace "ronaldo_singapore.mp4" with the path to your video file.

  4. Run the script:

    python face_recognition_yolo.py
  5. The script will open a window showing the video with face recognition results. Detected faces will be labeled with their respective names if recognized, or as "Unknown" otherwise. Bounding boxes are drawn around the detected faces.

  6. To exit the script, press 'q' while the video window is in focus.

Note: The script processes every fifth frame of the video for face recognition. You can adjust this behavior by modifying the following line in the script:

if i % 5 != 0:
    continue

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages