I am currently learning machine learning and am doing the project on object detection.
My problem is that the put_text()
isnt working properly in my for loop. Here is my code:
‘
classIds, confs, bbox = net.detect(img, confThreshold=0.5)
if len(classIds) != 0:
for classId, confidence, box in zip(classIds.flatten(), confs.flatten(), bbox):
cv2.rectangle(img, box, (255, 0, 0), thickness=2)
cv2.putText(img, classNames[classId-1].upper(), (box[0]+10, box[1]+30),
cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0), 2)
But here is what I got:
‘
File "C:UsersUserprojectsopencvObjectDetector.py", line 31,
in <module>
cv2.putText(img, classNames[classId-1].upper(), (box[0]+10, box[1]+30),
~~~~~~~~~~^^^^^^^^^^^
IndexError: list index out of range
‘
I was expecting it to show an window with the camera and a box around it that specifys the objects name, but it just showed the error. How do I resolve this?
New contributor
Subbsos is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.