正方形老是被识别成三角形。。。。。。其中页面中还识别出好多多余的+
2
2mdu
@2mdu
0
声望
12
楼层
210
资料浏览
0
粉丝
0
关注
2mdu 发布的帖子
-
RE: 矩形识别后,再识别颜色异常
import sensor, image, time from pyb import UART sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QVGA) sensor.skip_frames(time = 1000) sensor.set_auto_gain(False) sensor.set_auto_whitebal(False) clock = time.clock() thresholds = [(16, 71, 15, 102, -23, 97), # red_thresholds (11, 29, -33, -17, 0, 48), # green_thresholds (0, 42, -23, 16, -46, -5)] # blue_thresholds shape = 1 threshold_index =0 area = 0 uart = UART(3, 115200) def sending_data(cx,cy): global uart; data = ustruct.pack("<bbhhb", 0x2C, 0x12, int(cx), int(cy), 0x5B) uart.write(data); def receive_data(): global uart if uart.any(): tmp_data = uart.readline(); print("====接收===",tmp_data) return tmp_data; def detect_shape(shape): row_data=[-1,-1] global area # if shape==1: for r in img.find_rects(threshold=10000): area=(r[0], r[1], r[2], r[3]) statistics = img.get_statistics(roi=area) xq= r[2] / r[3] if 0<statistics.l_mode()<100 and 20<statistics.a_mode()<127 and 10<statistics.b_mode()<127 and 0.8<xq<1.2: row_data[0]= 1 elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<-23 and -128<statistics.b_mode()<127 and 0.8<xq<1.2: row_data[0]= 3 elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<127 and -128<statistics.b_mode()<-2 and 0.8<xq<1.2: row_data[0]= 2 row_data[1]=1 img.draw_rectangle(r.rect(), color = (255, 255, 255)) # elif shape==2: for c in img.find_circles(threshold =2000, x_margin = 10, y_margin = 10, r_margin = 10, r_min = 2, r_max = 100, r_step = 2): area = (c.x() - c.r(), c.y() - c.r(), 2 * c.r(), 2 * c.r()) statistics = img.get_statistics(roi=area) if 0<statistics.l_mode()<100 and -128<statistics.a_mode()<0 and 0<statistics.b_mode()<127:#红色 row_data[0]= 1 elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<0 and 0<statistics.b_mode()<127:#绿色 row_data[0]= 3 elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<127 and -128<statistics.b_mode()<-2:#蓝色 row_data[0]= 2 row_data[1]=2 img.draw_circle(c.x(), c.y(), c.r(), color = (255, 255, 255)) # elif shape==3: # for l in img.find_line_segments(roi=[60,40,150,150],merge_distance = 10, max_theta_diff = 10): # img.draw_line(l.line(), color = (0, 0, 255)) return row_data while(True): clock.tick() # data= receive_data(); img = sensor.snapshot() result =detect_shape(shape) print(clock.fps())