0

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]

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:

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. Thank you for any help or suggestions

1
  • Did you get the answer to your question? Commented May 1, 2017 at 21:13

1 Answer 1

0

detectMultiScale returns a list of rectangles.

[[247 101 237 237]] would be a single one, as in an array with one rectangle/array.

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.

If you only want the first rectangle, just access it by index:

faces[0]
Sign up to request clarification or add additional context in comments.

1 Comment

sorry, for the late response! but yes, this helped a lot! Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.