Chapter7 When I click take snapshot button, I take type error.

44 views
Skip to first unread message

ibrahim...@gmail.com

unread,
May 13, 2017, 1:06:37 PM5/13/17
to OpenCV with Python Blueprints
Hi Michael
I'm taking this fault when I running chapter7.py
Additionally, do not save my face pictures into dataset folder.
Can you help me please as soon as possible.
Best regards.

C:\Python2713\python.exe C:/Users/ibrahim/Downloads/Compressed/opencv-python-blueprints-master/opencv-python-blueprints-master/chapter7/chapter7.py
Warning: Testing is disabled
Could not find data file  datasets/faces_preprocessed.pkl
Traceback (most recent call last):
  File "C:/Users/ibrahim/Downloads/Compressed/opencv-python-blueprints-master/opencv-python-blueprints-master/chapter7/chapter7.py", line 234, in _on_snapshot
    success, head = self.faces.align_head(self.head)
  File "C:\Users\ibrahim\Downloads\Compressed\opencv-python-blueprints-master\opencv-python-blueprints-master\chapter7\detectors.py", line 99, in align_head
    left_eye_region = head[0.2 * height:0.5 * height, 0.1 * width:0.5 * width]
TypeError: slice indices must be integers or None or have an __index__ method


Michael Beyeler

unread,
May 16, 2017, 7:49:38 PM5/16/17
to OpenCV with Python Blueprints
Hi Ibrahim,

Python 2 can be a bit finicky when it comes to slicing arrays: It wants the indices to be integers, whereas "0.2 * height" might evaluate to float. I have uploaded a fix to the GitHub's master branch that basically does the following:

left_eye_region = head[int(0.2 * height): int(0.5 * height),
                       
int(0.1 * width): int(0.5 * width)]

...and the same for right_eye_region. This should fix the problem.

To get the fix into your code, you can either download the zip file again or pull the latest state of the master branch into your own fork.

Best,
Michael
Reply all
Reply to author
Forward
0 new messages