def draw_contours(self):
""""""
# contours all the objects found
# (findContours changes the source image,
# hence copy)
contours, _ = cv2.findContours(self.mask.copy(),
cv2.RETR_TREE,
cv2.CHAIN_APPROX_SIMPLE)
# rectangles
for contour in contours:
size = cv2.contourArea(contour)
if size > self.threshold: # only larger objects
ret_x, ret_y, ret_w, ret_h = cv2.boundingRect(contour)
cv2.rectangle(self.display, (ret_x, ret_y),
(ret_x+ret_w,
ret_y+ret_h),
(0, 255, 255), 2)
评论列表
文章目录