mirror of
https://github.com/openmv/openmv.git
synced 2025-11-04 14:49:50 +08:00
The old code did not actually implement the errode anhd dilate kernels correctly. However, it migh have been a little faster because it avoided the boundary problem. In the future we can optimize all the kernel code to have different loops for doing the edges of image versus the center. But, for now, this is good enough. QVGA color tracking with kernels will be slow, but, the speed can be improved with QQVGA resolution. Using a 3x3 kernel is plenty fast. Larger ones are slower. I also added the ability for you to set the threshold for erode and dialte. This lets you make the kenrel a little bit smarter so that it won't errode or dilate a pixel unless the threshold is met. Meaning, you'll be able to use erode to erode an image down to 1 pixel wide lines.
25 lines
713 B
Python
25 lines
713 B
Python
import pyb, sensor, image, math
|
|
sensor.reset()
|
|
sensor.set_framesize(sensor.QVGA)
|
|
grayscale_thres = (170, 255)
|
|
rgb565_thres = (70, 100, -128, 127, -128, 127)
|
|
while(True):
|
|
sensor.set_pixformat(sensor.GRAYSCALE)
|
|
for i in range(100):
|
|
img = sensor.snapshot()
|
|
img.binary([grayscale_thres])
|
|
img.erode(2)
|
|
for i in range(100):
|
|
img = sensor.snapshot()
|
|
img.binary([grayscale_thres])
|
|
img.dilate(2)
|
|
sensor.set_pixformat(sensor.RGB565)
|
|
for i in range(100):
|
|
img = sensor.snapshot()
|
|
img.binary([rgb565_thres])
|
|
img.erode(2)
|
|
for i in range(100):
|
|
img = sensor.snapshot()
|
|
img.binary([rgb565_thres])
|
|
img.dilate(2)
|