def contour_match(self, img):
'''
Returns 1. Image with bounding boxes added
'''
# get filtered contours
contours = self.get_filtered_contours(img)
detection = Detection()
height,width,channel = img.shape
mean_color = (15,253,250)
for i, (cnt, box) in enumerate(contours):
# plot box and label around contour
x,y,w,h = box
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,"cone", (x,y), font, 1,mean_color,4)
cv2.rectangle(img,(x,y),(x+w,y+h), mean_color,2)
if i == 0:
detection.x = x
detection.y = y
detection.w = w
detection.h = h
detection.error_center = 0.5 - (x/float(width))
detection.error_size = (self.DESIRED_AREA-w*h)/float(width*height)
cv2.putText(img,"center:%.2f, distance: %.2f" % (detection.error_center, detection.error_size), (x-w,y-h/2), font, 1,mean_color,4)
# return the image with boxes around detected contours
return img, detection
评论列表
文章目录