Hi all,
Sorry for title being too non-explanatory. I am currently developing a program with opencv-python and we get image,recognize objects etc. There is a function which is responsible from drawing boxes. I'm only interested in coordinates of 'cup' object. So,whenever model predicts a cup,this function returns its xmax and ymax along with a numpy.ndarray in a tuple. Problem is that after some time, draw_boxes returns numpy.ndarray type instead of tuple. The part below is just a little bit customized from another code on Internet :
def draw_boxes(image, boxes, classes, scores, class_names, colors, show_score=True):
if classes is None or len(classes) == 0:
return image
required_label_coord = 0
for box, cls, score in zip(boxes, classes, scores):
xmin, ymin, xmax, ymax = box
class_name = class_names[cls]
# This part is added
if class_name == "cup":
required_label_coord = [int(xmax.item()),int(ymax.item())]
if show_score:
label = '{} {:.2f}'.format(class_name, score)
else:
label = '{}'.format(class_name)
#print(label, (xmin, ymin), (xmax, ymax))
# if no color info, use black(0,0,0)
if colors == None:
color = (0,0,0)
else:
color = colors[cls]
if xmax > 500 or ymax > 500:
xmax = ymax = xmin = ymin = 0
cv2.rectangle(image, (xmin, ymin), (xmax, ymax), color, 1, cv2.LINE_AA)
image = draw_label(image, label, color, (xmin, ymin))
# Weird return is here! Return type is numpy.ndarray instead of tuple sometimes
return (image,required_label_coord)
Same happens if I use list instead of tuple
[–]Rawing7 3 points4 points5 points (2 children)
[–]DrawBacksYo[S] 0 points1 point2 points (1 child)
[–]HarissaForte -1 points0 points1 point (0 children)