矩形识别后,再识别颜色异常
-
为啥识别到矩形了,但是没有进颜色值的范围判断。是什么原因呀
代码如下:
row_data=[-1,-1,-1,-1]
global area
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 0<statistics.a_mode()<127 and 0<statistics.b_mode()<127:
row_data[0]= 1
img.draw_rectangle(r.rect(),color = (255, 255, 255))
elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<-23 and -128<statistics.b_mode()<127:
row_data[0]= 3
img.draw_rectangle(r.rect(),color = (255, 255, 255))
elif 0<statistics.l_mode()<100 and -128<statistics.a_mode()<127 and -128<statistics.b_mode()<-2:
row_data[0]= 2
img.draw_rectangle(r.rect(),color = (255, 255, 255))
row_data[1]=1
-
如果涉及代码,需要报错提示与全部代码文本,请注意不要贴代码图片
-
statistics 怎么获取范围值,比如图中 的红色和蓝色啊
-
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())
-
识别视频中的形状率极低,这样情况怎么处理啊
-
你的代码我运行没有报错,你的问题是什么?
-
@kidswong999 识别不出来矩形
-
-
-
我看代码没有差别,找不到什么原因导致得。