diff options
author | lonkaars <loek@pipeframe.xyz> | 2023-06-07 10:22:02 +0200 |
---|---|---|
committer | lonkaars <loek@pipeframe.xyz> | 2023-06-07 10:22:02 +0200 |
commit | c537c7ad294107b1804975c4e7ed0dc9886990cf (patch) | |
tree | cfd9a105e259829dcc6ec849a25de06cab7997ee | |
parent | 7118317a18e3024b341d14e72a9e741a7b14b2e5 (diff) |
better road detection
-rw-r--r-- | nicla/downscale.py | 19 | ||||
-rw-r--r-- | nicla/road.py | 4 |
2 files changed, 22 insertions, 1 deletions
diff --git a/nicla/downscale.py b/nicla/downscale.py new file mode 100644 index 0000000..738b4bb --- /dev/null +++ b/nicla/downscale.py @@ -0,0 +1,19 @@ +import sensor, image, time, math + +sensor.reset() +sensor.set_pixformat(sensor.RGB565) +sensor.set_framesize(sensor.HVGA) +sensor.skip_frames(time = 2000) +sensor.set_vflip(True) +sensor.set_hmirror(True) +clock = time.clock() + +def main(): + img = sensor.snapshot() + img.to_grayscale() + img.scale(copy_to_fb=True, x_size=100) + +if __name__ == "__main__": + while(True): + main() + clock.tick() diff --git a/nicla/road.py b/nicla/road.py index ceabc3b..20863cc 100644 --- a/nicla/road.py +++ b/nicla/road.py @@ -10,6 +10,8 @@ clock = time.clock() WIDTH = 480 HEIGHT = 320 +MAX_AREA = WIDTH * HEIGHT / 10 +MIN_AREA = 40 HORIZON = 150 STRETCH = 40 @@ -35,7 +37,7 @@ def main(): for blob in img.find_blobs([(ROAD_MIN_BRIGHTNESS, 0xff)], pixels_threshold=100): img.draw_rectangle(blob.rect()) - area_weight = blob.area() + area_weight = MIN_AREA + min(MAX_AREA, blob.w() * blob.h()) # limit max area_weight so small blobs still have impact horizontal_pos = (blob.x() + blob.w()/2) / WIDTH offset_sum += horizontal_pos * area_weight offset_count += area_weight |