Monday, 3 December 2018

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.

The python version I use is Python 2.7.15 and 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

How can I fix this. I tried various solutions but they didnt gave me expected results.



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

No comments:

Post a Comment