bearsprogrammer / real-time-deep-face-recognition

using facenet algorithm
MIT License
233 stars 100 forks source link

list index out of range for multi-faces #4

Closed rouyunpan closed 7 years ago

rouyunpan commented 7 years ago

It can work. when It detect multi-faces, I sometime encounter a error "IndexError: list index out of range" as below

[log] Corrupt JPEG data: 2 extraneous bytes before marker 0xd1 Detected_FaceNum: 1 face is inner of range! Corrupt JPEG data: 3 extraneous bytes before marker 0xd6 Detected_FaceNum: 2 face is inner of range! Traceback (most recent call last): File "realtime_facenet_git.py", line 107, in cropped[i] = facenet.flip(cropped[i], False) IndexError: list index out of range

bearsprogrammer commented 7 years ago

@rouyunpan I think this is an error in Opencv itself. Do these problems occur frequently?

rouyunpan commented 7 years ago

hi I found this bug. if Face0 is out of range, you will skip face0,and face0 doesn't be appended in the list "cropped" . When skipping face0 and appending face1 , the index should be 0 in the list "cropped". Then, you call facenet.flip() and access the list with index 1, you will encounter "IndexError: list index out of range"

[code section] if bb[i][0] <= 0 or bb[i][1] <= 0 or bb[i][2] >= len(frame[0]) or bb[i][3] >= len(frame): print('face is inner of range!')
continue

cropped.append(frame[bb[i][1]:bb[i][3], bb[i][0]:bb[i][2], :]) cropped[i] = facenet.flip(cropped[i], False)

B.R.

bearsprogrammer commented 7 years ago

@rouyunpan First, I acknowledge my mistake. When debugging the point you pointed out in my code, I found that I had accessed the wrong idx. I have accepted your suggestion and committed(5f20f3d) the code again, and I am very grateful for your contribution.

farzadhallaji commented 6 years ago

i add

 try : 
    .
    .
    .
 except IndexError :
     print("Oops! IndexError : list index out of range for multi-faces")

in for loop so it work correctly.