Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 samples/dnn/object_detection.py. OpenCV-tutorial on YOLOv3 does not work #12349

Closed
NobuoTsukamoto opened this issue Aug 30, 2018 · 4 comments

Comments

@NobuoTsukamoto
Copy link
Contributor

System information (version)
  • OpenCV => 3.4.2
  • Operating System / Platform => Fedora 28
  • Compiler => GCC 8.1
  • Python3 => 3.6.6
Detailed description

I tried to do the Python3 OpenCV-Sample on yolov3.
I executed opencv/samples/dnn/object_detection.py. (https://github.com/opencv/opencv/blob/3.4.2/samples/dnn/object_detection.py)
But it did not work with errors(TypeError: integer argument expected, got float).

I executed the following command.
"""python3 object_detection.py --input=./test.jpg --model=./yolov3.weights --config=./yolov3.cfg --classes=./object_detection_classes_coco.txt --scale=0.00392 --width=416 --height=416
"""

All errors are below.
'''Traceback (most recent call last):
File "object_detection.py", line 196, in
postprocess(frame, outs)
File "object_detection.py", line 162, in postprocess
drawPred(classIds[i], confidences[i], left, top, left + width, top + height)
File "object_detection.py", line 73, in drawPred
cv.rectangle(frame, (left, top), (right, bottom), (0, 255, 0))
TypeError: integer argument expected, got float
'''

I guess that in Python 3 the following operation result is a floating point number, not an integer.
https://github.com/opencv/opencv/blob/3.4.2/samples/dnn/object_detection.py#L145-L146

@alalek
Copy link
Member

alalek commented Aug 30, 2018

Perhaps this should work:
cv.rectangle(frame, (int(left), int(top)), (int(right), int(bottom)), (0, 255, 0))

@dkurt
Copy link
Member

dkurt commented Aug 30, 2018

Or these two lines:

left = int(center_x - width / 2)
top = int(center_y - height / 2)

@NobuoTsukamoto
Copy link
Contributor Author

NobuoTsukamoto commented Aug 30, 2018

I fixed object_detection.py. And it worked fine.

left = int(center_x - width / 2)
top = int(center_y - height / 2)

I would like to send a pull request.

Thank you very much.

@alalek
Copy link
Member

alalek commented Aug 30, 2018

Perhaps this work too (// - integer division):

left = center_x - width // 2

Feel free to prepare PR into 3.4 branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants