@18800120366 # 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...
THRESHOLD = (0, 100) # Grayscale threshold for dark things...
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
from pyb import UART
uart = UART(3, 9600)
clock = time.clock()
img = sensor.snapshot().binary([THRESHOLD]) if BINARY_VISIBLE else sensor.snapshot()
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"))