THRESHOLD = (15, 48, -42, 33, -48, 71)# Grayscale threshold for dark things...
import sensor, image, time #引入感知、视觉、时间模块
import pyb #引入pyb模块
from pyb import Servo #引入舵机模块
k=0.1 #角度的调整系数,是调快还是调慢
s1 = Servo(1) # P7
s2 = Servo(2) # P8
n=40
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,20,80,40])
sensor.skip_frames(time = 2000) # WARNING: If you use QQVGA it may take seconds
clock = time.clock() # 引入时钟对象
roi=(0,0,160,20)
while(True):
clock.tick()
img = sensor.snapshot().binary([THRESHOLD])
line = img.get_regression([(100,100,0,0,0,0)],roi, robust = True)
if (line):
line_theta=line.theta()
print("%f" % line_theta)
img.draw_line(line.line(), color = 127)
![0_1538657260206_2TUD16@LYTK3%P_)]9T_IJV.png](https://fcdn.singtown.com/2e196a2e-85f3-46ec-850d-b5287876fc49.png)
img.get_regression(roi=(10,10,100,100))
你好,get_regression是上面的格式,image.get_regression(thresholds[, invert=False[, roi[, x_stride=2[, y_stride=1[, area_threshold=10[, pixels_threshold=10[, robust=False]]]]]]])
thresholds 必须是元组列表。 [(lo, hi), (lo, hi), ..., (lo, hi)] 定义你想追踪的颜色范围。也就是上图中的【(100,100,0,0,0,0)】也就是黑色部分。现在我想在这个基础上加入roi 是感兴趣区域,如上图的roi=(0,0,160,20)。也就是说既要感兴趣的颜色,又要感兴趣的区域。
get_regression的格式我没看懂,你给的答案是只有感兴趣的区域。
希望你的回复既有感兴趣的颜色,又有感兴趣的区域。
img.get_regression(thresholds=[(100,100),(0,0),(0,0)], roi=(10,10,100,100))