2

I am following a youtube tutorial (https://www.youtube.com/watch?v=pQvkoaevVMk), My camera isn't activating once the code is run, i tried googling answer but cant seem to figure it out. I am new to deepface and opencv-python.

here is my code

import threading

import cv2
from deepface import DeepFace

cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)

cap.set(cv2.CAP_PROP_FRAME_WIDTH, 640)
cap.set(cv2.CAP_PROP_FRAME_HEIGHT, 480)

counter = 0

reference_img = cv2.imread("img.png")  # use your own image here

face_match = False


def check_face(frame):
    global face_match
    try:
        if DeepFace.verify(frame, reference_img.copy())['verified']:
            face_match = True
        else:
            face_match = False
    except ValueError:
        face_match = False


while True:
    ret, frame = cap.read()

    if ret:
        if counter % 30 == 0:
            try:
                threading.Thread(target=check_face, args=(frame.copy(),)).start()
            except ValueError:
                pass
        counter += 1
        if face_match:
            cv2.putText(frame, "MATCH!", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 255, 0), 3)
        else:
            cv2.putText(frame, "NO MATCH!", (20, 450), cv2.FONT_HERSHEY_SIMPLEX, 2, (0, 0, 255), 3)

        cv2.imshow('video', frame)

    key = cv2.waitKey(1)
    if key == ord('q'):
        break

cv2.destroyAllWindows()

any ideas?

I made sure I installed all the correct packages (opencv-python and deepface).

hakopian_
  • 21
  • 2
  • 2
    what's your os? what're versions of used packages? what's python version? – Marcin Orlowski Apr 13 '23 at 22:15
  • @MarcinOrlowski Mac, deepface 0.0.79, opencv-python 4.5.5.62, python 3.9 – hakopian_ Apr 14 '23 at 00:56
  • Appearantly DSHOW is Windows only. This topic here has an answer regarding that, but the alternatives are only for Linux. https://stackoverflow.com/questions/69558539/cv2-videocapture0-cv2-dshow-returns-none – T F Apr 14 '23 at 12:08

0 Answers0