例程讲解-09-edges快速边缘检测
此例程为09-feature-Detection-edges.py
本例程的目标是利用canny算子实现快速边缘检测,使用canny算子的边缘检测是最简单最快速的边缘检测,但是检测的效果没有morph变换的边缘检测效果好。
# Edge detection with Canny:
#
# This example demonstrates the Canny edge detector.
import sensor, image, time
sensor.reset() # Initialize the camera sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # or sensor.RGB565
sensor.set_framesize(sensor.QQVGA) # or sensor.QVGA (or others)
sensor.skip_frames(30) # Let new settings take affect.
sensor.set_gainceiling(8)
clock = time.clock() # Tracks FPS.
while(True):
clock.tick() # Track elapsed milliseconds between snapshots().
img = sensor.snapshot() # Take a picture and return the image.
# Use Canny edge detector
img.find_edges(image.EDGE_CANNY, threshold=(50, 80))
#threshold设置阈值
# Faster simpler edge detection
#img.find_edges(image.EDGE_SIMPLE, threshold=(100, 255))
print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
原图:
使用canny算子的边缘检测:
使用04-image-Filters-edge_detection.py morph变换边缘检测: