小车巡线,theta角怎么获得?
-
# Fast Linear Regression Example # # This example shows off how to use the get_regression() method on your OpenMV Cam # to get the linear regression of a ROI. Using this method you can easily build # a robot which can track lines which all point in the same general direction # but are not actually connected. Use find_blobs() on lines that are nicely # connected for better filtering options and control. # # This is called the fast linear regression because we use the least-squares # method to fit the line. However, this method is NOT GOOD FOR ANY images that # have a lot (or really any) outlier points which corrupt the line fit... #设置阈值,(0,100)检测黑色线 THRESHOLD = (0, 100) # Grayscale threshold for dark things... #设置是否使用img.binary()函数进行图像分割 BINARY_VISIBLE = True # Does binary first so you can see what the linear regression # is being run on... might lower FPS though. import sensor, image, time sensor.reset() sensor.set_pixformat(sensor.GRAYSCALE) sensor.set_framesize(sensor.QQVGA) sensor.skip_frames(time = 2000) clock = time.clock() while(True): clock.tick() img = sensor.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else sensor.snapshot() # Returns a line object similar to line objects returned by find_lines() and # find_line_segments(). You have x1(), y1(), x2(), y2(), length(), # theta() (rotation in degrees), rho(), and magnitude(). # # magnitude() represents how well the linear regression worked. It goes from # (0, INF] where 0 is returned for a circle. The more linear the # scene is the higher the magnitude. #函数返回回归后的线段对象line,有x1(), y1(), x2(), y2(), length(), theta(), rho(), magnitude()参数。 #x1 y1 x2 y2分别代表线段的两个顶点坐标,length是线段长度,theta是线段的角度。 #magnitude表示线性回归的效果,它是(0,+∞)范围内的一个数字,其中0代表一个圆。如果场景线性回归的越好,这个值越大。 line = img.get_regression([(255,255) if BINARY_VISIBLE else THRESHOLD]) if (line): img.draw_line(line.line(), color = 127) print("FPS %f, mag = %s" % (clock.fps(), str(line.magnitude()) if (line) else "N/A")) # About negative rho values: # # A [theta+0:-rho] tuple is the same as [theta+180:+rho]. 这个例程里,怎么获得直线的theta角,这个算法的思想是什么啊 ?新手求教,万分感谢
-
theta角就是最后的画出来的line的角度,可以通过查阅中文文档来获取。
line-中文文档
get_regression函数就是对视野内的直线进行拟合,快速线性回归,得到一条最合适的线,控制小车(或飞控)追踪这条线,来达到巡线的目的。
具体请参考: