大佬请问为什么二值化之后找线段在正对矩形的时候找的到 歪了就不行
-
import pyb from pyb import LED #导入LED from machine import UART import sensor, image, time, math, os, tf uart = UART(1, baudrate=115200) sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QVGA) sensor.set_auto_exposure(False, 1000) sensor.__write_reg(0x03,0x04) sensor.__write_reg(0x04,0x05) sensor.__write_reg(0xB2,0x40) sensor.__write_reg(0xB3,0x00) sensor.__write_reg(0xB4,0x40) sensor.__write_reg(0xB5,0x00) sensor.__write_reg(0x03,0x03) sensor.__write_reg(0x5B,0x60) sensor.__write_reg(0x03,0x08) sensor.set_auto_whitebal(False, (0x80,135,0x80)) sensor.set_brightness(500) sensor.set_auto_gain(False) sensor.skip_frames(time = 2000) clock = time.clock() Large_area=[0,0,320,180] min_degree = 45 max_degree = 135 i=0 yzb=[0,0] he=[] ypj=[] yjd=[] lbypj=[] lbyjd=[] suibian=[] red_threshold = (0,150) def get_pj(point): point_1 = point[0] point_2 = point[1] he = int((point_1+ point_2)/2) return he while(True): img = sensor.snapshot() img.binary([red_threshold]) #img.draw_rectangle(Large_area, color = (255, 0, 0)) for l in img.find_line_segments(roi=Large_area,merge_distance = 10, max_theta_diff = 10): #if (min_degree <= l.theta()) and (l.theta() <= max_degree): img.draw_line(l.line(), color = (255, 0, 0)) #print(l.line()) yzb = [l.y1(),l.y2()] #yjd= [l.theta()] ypj = get_pj(yzb) if(i<5): lbypj.append(ypj) #lbyjd.append(yjd) i=i+1 if (i==5): #suibian=lbypj ypjmax=max(lbypj) juliy=240-ypjmax img.draw_line([0,ypjmax,320,ypjmax], color = (255, 0, 0)) #zuidixian=suibian.index(max(suibian)) #outjd =lbyjd[zuidixian] print(juliy) lbypj=[] #lbyjd=[] i=0
-
-
-
你的这个代码,我没办法拍出黑色的矩形。你改成正常的二值化的代码,我再测试。