我是初学者,在使用Python OpenCV时遇到了错误。
我的代码:
import cv2
import numpy as np
front_cascade = cv2.CascadeClassifier('../haarcascade_frontalface_default.xml')
img = cv2.imread('mimika-1024x572.jpg')
faces = front_cascade.detectMultiScale(
scaleFactor=1.1,
minNeighbors=5,
minsize=(30,30)
)
#for (x, y, w, h) in faces:
# cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 155), 3)
print (faces)
cv2.imshow('frame', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
和错误:
Traceback (most recent call last):
File "C:/cv/test2.py", line 12, in <module>
minsize=(30,30)
TypeError: Required argument 'image' (pos 1) not found
如何解决此错误?
detectMultiScale
需要一个图像作为第一个参数,但你忘记传递它。
尝试:
faces = front_cascade.detectMultiScale(
img, # don't forget this!
scaleFactor=1.1,
minNeighbors=5,
minsize=(30,30)
)