只识别下面和右面两个ROI区域,但是结果是只要目标物体出现在set_windowing内,就显示已经识别到
-
THRESHOLD = (0, 45, 19, -100, -24, 27) # Grayscale threshold for dark things... roi1= [(0,0,80,60), (26,45,25,11),#down (61,27,16,8)]#right n=0 a=0 import sensor, image, time from pyb import LED #LED(1).on() #LED(2).on() #LED(3).on() sensor.reset() #sensor.set_vflip(True)#垂直翻转 #sensor.set_hmirror(True)#打开水平镜像 sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) # 80x60 (4,800 pixels) - O(N^2) max = 2,3040,000. sensor.set_windowing([0,0,80,60]) sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds clock = time.clock() # to process a frame sometimes. while(True): clock.tick() down_flag=right_flag=0 img = sensor.snapshot().binary([THRESHOLD])#阈值进行二进制 line = img.get_regression([(100,100)], robust = True)#线性回归计算 for rec in roi1: img.draw_rectangle(rec, color=(255,0,0))#颜色 if (line): rho_err = abs(line.rho())-img.width()/2 if line.theta()>90: theta_err = line.theta()-180 else: theta_err = line.theta() img.draw_line(line.line(), color = 127)#画线 #print(rho_err,line.magnitude(),rho_err) if img.find_blobs([(0, 45, 19, -100, -24, 27)],roi=(26,45,25,11)): down_flag=1 n=1 print(n) if img.find_blobs([(0, 45, 19, -100, -24, 27)],roi=(61,27,16,8)): right_flag=1 a=2 print(a)
-
没看懂你的代码。又有直线又找色块的。