简体   繁体   English

python,opencv错误cv.rectangle SystemError:旧样式的getargs格式使用了新功能

[英]python, opencv error cv.rectangle SystemError: old style getargs format uses new features

I am writing a code to detect faces in python using openCV. 我正在编写代码以使用openCV在python中检测人脸。

The python version I use is Python 2.7.15 and openCV 2.2 我使用的python版本是python 2.7.15和openCV 2.2

def find_faces(image_path):

    image = cv.imread(image_path)

    color_img = image.copy()

    filename = os.path.basename(image_path)

    gray_img = cv.cvtColor(color_img, cv.CV_BGR2GRAY)
    haar_classifier = cv.CascadeClassifier('D:\haarcascades\\haarcascade_frontalface_default.xml');

    eye_cascade = cv.CascadeClassifier('D:\haarcascades\\haarcascade_eye.xml');

    faces = haar_classifier.detectMultiScale(gray_img,1.3,6);

    print('Number of faces found: {faces}'.format(faces=len(faces)))

    for (x, y, width, height) in faces:
      print(x);print(y);print(x+width);print(y+height);
      cv.rectangle(color_img, (x, y), (x+width, y+height), (0, 255, 0), 3,8,0)

      roi_gray = gray_img[y:y+height, x:x+width]

      roi_color = color_img[y:y+height, x:x+width]

      eyes = eye_cascade.detectMultiScale(roi_gray)

      for (ex,ey,ew,eh) in eyes:

        cv.rectangle(roi_color,(ex,ey),(ex+ew,ey+eh),(0,255,0),2)

    cv.imshow(filename, color_img)

    cv.waitKey(0) 

    cv.DestroyAllWindows()

The code works fine and print faces count. 该代码工作正常并且打印面计数。 But when I try to draw rectangle on images, the code gives me error 但是当我尝试在图像上绘制矩形时,代码给了我错误

cv.rectangle(color_img, (x, y), (x+width, y+height), (0, 255, 0), 3,8,0) SystemError: old style getargs format uses new features cv.rectangle(color_img,(x,y),(x + width,y + height),(0,255,0),3,8,0)SystemError:旧样式的getargs格式使用了新功能

How can I fix this. 我怎样才能解决这个问题。 I tried various solutions but they didnt gave me expected results. 我尝试了各种解决方案,但它们并没有给我预期的结果。

This error typically means a datatype is wrong (not necessarily a tuple). 此错误通常表示数据类型错误(不一定是元组)。 I suspect the error is that the x, y and width, height values are floats -- try the following: 我怀疑错误是x, ywidth, height值是浮点型的-请尝试以下操作:

cv.rectangle(color_img, (int(x), int(y)), (int(x+width), int(y+height)), (0, 255, 0), 3,8,0) 

Try this: 尝试这个:

cv.rectangle(color_img, x, y, x+width, y+height, (0, 255, 0), 3,8,0)

Even if this doesn't work, you have to First upgrade the opencv version (as already recommended in some comments) to cv2. 即使这行不通,您也必须首先将opencv版本(如某些注释中所建议)升级到cv2。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python 错误:SystemError: new style getargs format but argument is not a tuple - Python error: SystemError: new style getargs format but argument is not a tuple SystemError:新样式getargs格式但参数不是OpenCV中的元组 - SystemError: new style getargs format but argument is not a tuple in OpenCV 错误在哪里? “ SystemError:新样式的getargs格式,但参数不是元组” - Where is the error? “SystemError: new style getargs format but argument is not a tuple” SystemError:新样式的 getargs 格式但参数不是元组? - SystemError: new style getargs format but argument is not a tuple? 获取 SystemError:新样式 getargs 格式,但参数不是元组。 我在使用 cv2.putText 时遇到了这个问题。 如何修复此错误? - Getting SystemError: new style getargs format but argument is not a tuple. Facing this issue when I was using cv2.putText. How to fix this error? 使用cv2.blur时,“系统错误:新样式的getargs格式,但参数不是元组” - “System error: new style getargs format but argument is not a tuple” when using cv2.blur 使用Python将OpenCV cv.Rectangle(img,pt1,pt2)转换为NumPy数组 - Converting OpenCV cv.Rectangle(img, pt1, pt2) into NumPy array with Python ImageDraw.draw.line():SystemError:新型getargs格式,但参数不是元组 - ImageDraw.draw.line() : SystemError: new style getargs format but argument is not a tuple “新型getargs格式,但参数不是元组”枕头图像粘贴错误 - “New style getargs format but argument is not a tuple” Pillow image paste error cv.rectangle显示在错误的位置 - cv.rectangle showing in wrong position
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM