简体   繁体   中英

Python - OpenCV, detectMultiScale output doesn't have commas separating x,y,h,w values

I'm relatively new to programming in Python and using OpenCV (and using stackoverflow), however I can't seem to find anyone else who has encountered this issue. I am trying to write a basic face recognition program, based on various tutorials, however, I am having an issue with the output of detectMultiScale in this portion of code.

for image_path in image_paths:
    predict_image_pil = Image.open(image_path).convert('L')
    predict_image = np.array(predict_image_pil, 'uint8')
    faces = faceCascade.detectMultiScale(predict_image)

    for (x, y, w, h) in faces:
        nbr_predicted, conf = recognizer.predict(predict_image[y: y + h, x: x + w])
        nbr_actual = int(os.path.split(image_path)[1].split(".")[0].replace("subject", ""))

I was repeatedly getting a "TypeError: 'int' object is not iterable" error whenever I ran the program, this caused me to check that "faces" was in fact a list of separate values. After running this slightly modified piece of code it became obvious that this was not the case.

for image_path in image_paths:
    predict_image_pil = Image.open(image_path).convert('L')
    predict_image = np.array(predict_image_pil, 'uint8')
    faces = faceCascade.detectMultiScale(predict_image)
    print faces

Printed this to the console

[[108  55 154 154]]
[[116  62 152 152]]
[[ 95  76 139 139]]
[[118  57 152 152]]
[[107  53 152 152]]
[[ 32  59 153 153]]
[[101  84 137 137]]
[[ 92  53 152 152]]
[[ 85  77 141 141]]
[[ 96  55 156 156]]
[[108  69 145 145]]
[[ 94  47 159 159]]
[[112  83 137 137]]
[[ 56  68 149 149]]
[[103  77 142 142]]

It appears to be printing the XYWH coordinates without any commas seperating them, would this be the cause of the TypeError?

If not what would be causing this issue? There may be some really obvious thing that I'm missing. To get the faces module I did have to build opencv from source using cmake and visual studio, however, I'm not sure if that could somehow be the cause.

I'm running WinPython 64bit 2.7.10.3 and the latest (stable) OpenCV version built from source.

It appears that the issue was with acquiring the confidence of the predict function. Once I removed the ", conf" from my code the issue was resolved.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM