openmv/scripts/unittest/tests/regression.py
iabdalkader 4b1837f72e scripts: Update unit tests.
Co-authored-by: Kwabena W Agyeman <kwagyeman@users.noreply.github.com>
Signed-off-by: iabdalkader <i.abdalkader@gmail.com>
2025-10-18 17:14:36 +02:00

32 lines
949 B
Python

def unittest(data_path, temp_path):
import image
# Create test image with a line of white pixels
img = image.Image(100, 100, image.GRAYSCALE)
# Fill with black
for y in range(100):
for x in range(100):
img.set_pixel(x, y, 0)
# Draw a line at roughly 30 degrees using draw_line
# Draw from (10, 10) to (90, 56) - this is approximately 30 degrees
img.draw_line(10, 10, 90, 56, color=255, thickness=5)
# Get linear regression on white pixels
line = img.get_regression([(200, 255)], invert=False,
area_threshold=10, pixels_threshold=10)
# Verify regression found the line
if line is None:
return False
# Line at 30 degrees from horizontal should have theta around 120 degrees
theta = line.theta()
# Allow generous tolerance since exact angle detection varies
if abs(theta - 120) > 30:
return False
return True