简体   繁体   English

元组索引超出范围/ int对象不可迭代

[英]tuple index out of range / int object is not iterable

the following problem occours: I'm trying to detect faces and call a function with the specific index values 出现以下问题:我正在尝试检测面孔并使用特定的索引值调用函数

 faces = face_cascade.detectMultiScale(gray, 1.3, 5)
            facesCopy = faces
            print("faces at 0")
            print(faces)
            if(len(faces) >= 1):
            for (i) in range(len(faces)):
                  #call function with values of faces at specific index(i)
                  detectFace(self, faces[i])

faces returns this: [[247 101 237 237]] facesCopy the same, but faces[i] returns [247 101 237 237] faces返回此:[[247 101 237 237]] facesCopy相同,但是faces [i]返回[247101237237]

how do I get the inner array? 我如何获得内部数组? faces[0] returns truple out of range or any variation of faces[0][0] or [0][0][0][0] returns in a for loop int object is not iterable: faces [0]返回truple超出范围,或者faces [0] [0]或[0] [0] [0] [0]的任何变化在for循环int对象中都是不可迭代的:

for (x,y,w,h) in faces[0]:#do stuff

What am I missing or to blind to see? 我缺少什么或看不见的东西? I'm guessing it has something to do with the packed array? 我猜想它与压缩数组有关吗? The values are x and y postion and width and height of the face. 值是x和y位置以及脸部的宽度和高度。 Thank you for any help or suggestions 感谢您的帮助或建议

detectMultiScale returns a list of rectangles. detectMultiScale返回矩形列表。

[[247 101 237 237]] would be a single one, as in an array with one rectangle/array. [[247 101 237 237]]将是一个,如具有一个矩形/阵列的阵列。

for face in faces:
    print(face)

Outputs: 输出:

[247, 101, 237, 237]

If you want to unpack the array into variables: 如果要将数组解压缩为变量,请执行以下操作:

x, y, w, h = face

I'm not sure what arguments detectFace requires thought. 我不确定detectFace需要考虑哪些参数。

If you only want the first rectangle, just access it by index: 如果只需要第一个矩形,则按索引访问它:

faces[0]

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

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