1

I am trying to create a face detection model using OpenCV, Python. This is the code:

import cv2
import sys

# Get user supplied values
imagePath = "elon_musk.jpg"
cascPath = "haarcascade_frontalface_default.xml"

# Create the haar cascade
faceCascade = cv2.CascadeClassifier(cascPath)

# Read the image
image = cv2.imread(imagePath)
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

# Detect faces in the image
faces = faceCascade.detectMultiScale(
    gray,
    scaleFactor=1.1,
    minNeighbors=5,
    minSize=(30, 30),
    flags = cv2.cv.CV_HAAR_SCALE_IMAGE
)

print("Found {0} faces!".format(len(faces)))

# Draw a rectangle around the faces
for (x, y, w, h) in faces:
    cv2.rectangle(image, (x, y), (x+w, y+h), (0, 255, 0), 2)

cv2.imshow("Faces found", image)
cv2.waitKey(0)
print("Found {0} faces!".format(len(faces)))

I am facing this error while running:

Traceback (most recent call last):   File "[PATH]", line 21, in
<module>
 flags = cv2.cv.CV_HAAR_SCALE_IMAGE AttributeError: module 'cv2' has no attribute 'cv'

Can anyone help?

toyota Supra
  • 3,181
  • 4
  • 15
  • 19
John Mathew
  • 11
  • 1
  • 1
  • 1
    try without cv part? – rv.kvetch May 27 '22 at 15:17
  • 1
    No.., its not working! It throws up an error that "module 'cv2' has no attribute 'CV_HAAR_SCALE_IMAGE'" – John Mathew May 27 '22 at 15:18
  • 1
    Does this answer your question? [Where is \`CV\_HAAR\_SCALE\_IMAGE\` in OpenCV 3.1.0 with Python 3.5?](https://stackoverflow.com/questions/41341409/where-is-cv-haar-scale-image-in-opencv-3-1-0-with-python-3-5) – Cris Luengo Aug 30 '22 at 14:07

0 Answers0