识别矩形时识别对象不稳定,经常框到图像边缘
-
# Untitled - By: Misaki - 周六 12月 19 2020 import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) #sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() def find_max(rects): max_size=0 max_rect=rects for rect in rects: if rect[2]*rect[3] > max_size: max_rect=rects max_size = rect[2]*rect[3] return max_rect def find_max_rects(img): rects=img.find_rects(threshold=12000) for max_rect in find_max(rects): img.draw_rectangle(max_rect.rect(), color = (255, 255, 255)) #img.draw_edges(max_rect.corners(), color = (255, 255, 255)) return max_rect else: return 0 while(True): clock.tick() img = sensor.snapshot().gaussian(1).find_edges(image.EDGE_CANNY,threshold=(50, 90)) print(find_max_rects(img)) '''for c in img.find_circles(threshold = 2500, x_margin =10, y_margin = 10, r_margin = 10,r_min = 50, r_max = 200, r_step = 2): img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255)) print(c) for l in img.find_line_segments(merge_distance = 0, max_theta_diff = 0): img.draw_line(l.line(), color = (255, 0, 0)) print(l)''' print(clock.fps())
-
你这个是img.find_circles啊,也不是矩形啊。