【问题标题】:python, opencv error cv.rectangle SystemError: old style getargs format uses new featurespython, opencv 错误 cv.rectangle SystemError: old style getargs format uses new features
【发布时间】:2019-05-02 23:17:59
【问题描述】:

我正在编写一个代码来使用 openCV 在 python 中检测人脸。

我使用的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()

代码工作正常,打印面数。但是当我尝试在图像上绘制矩形时,代码给了我错误

cv.rectangle(color_img, (x, y), (x+width, y+height), (0, 255, 0), 3,8,0) SystemError:旧式 getargs 格式使用新功能

我该如何解决这个问题。我尝试了各种解决方案,但都没有给我预期的结果。

【问题讨论】:

  • 你不是说 Python 2.7.15 吗?以及为何如此古老的 OpenCV 版本(超过 8 年)
  • @DanMašek 是的。 python版本更正。将尝试一次新的 python cv 版本
  • 有必要使用2.2版本吗?据此引起。 github.com/ros-perception/image_pipeline/issues/124 你可以通过更新opencv来解决这个问题。导致这个错误可能是由于opencv版本不匹配造成的
  • 更新简历即可解决问题

标签: python opencv


【解决方案1】:

此错误通常意味着数据类型错误(不一定是元组)。我怀疑错误是 x, ywidth, height 值是浮点数 - 请尝试以下操作:

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

【讨论】:

    【解决方案2】:

    试试这个:

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

    即使这不起作用,您也必须先将 opencv 版本(在某些 cmets 中已经推荐)升级到 cv2。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-01-13
      • 1970-01-01
      • 1970-01-01
      • 2018-04-26
      • 2015-08-09
      • 2012-10-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多