1

so, I'm trying to code face detection but its not working. this is my code:

import cv2
import sys

cascPath = sys.argv[0]
faceCascade = cv2.CascadeClassifier(cascPath)

video_capture = cv2.VideoCapture(0)

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

    gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)

    faces = faceCascade.detectMultiScale(
        gray,
        scaleFactor=1.1,
        minNeighbors=5,
        minSize=(30, 30),
        flags=cv2.cv.CV_HAAR_SCALE_IMAGE
    )

    for (x, y, w, h) in faces:
        cv2.rectangle(frame, (x, y), (x+w, y+h), (0, 255, 0), 2)

    cv2.imshow('Video', frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

video_capture.release()
cv2.destroyAllWindows()

I'm very new to coding so I don't know if I'm missing something obvious

rioV8
  • 24,506
  • 3
  • 32
  • 49
  • You could refer to the method of this link: [OpenCV 4.0.0 SystemError: returned a result with an error set](https://stackoverflow.com/questions/54273050/opencv-4-0-0-systemerror-class-cv2-cascadeclassifier-returned-a-result-with/64238945) – Jill Cheng Apr 19 '21 at 02:20

1 Answers1

0

Change your code as follows:

faceCascade = cv2.CascadeClassifier(cv2.data.haarcascades + cascPath)

This worked for me.

Isha Shaw
  • 64
  • 1
  • 7