>>> 星瞳科技|OpenMV中国官方网站 <<<

>>> 星瞳科技店铺地址|OpenMV中国官方代理,全球九大代理商之一 <<<

>>> OpenMV3 Cam M7 官方高配版上市啦~戳我戳我戳我~ <<<

>>> 星瞳科技-OpenMV中文教程网 <<<

此例程为09-feature-Detection-lines.py
本例程的目的是利用canny算子和霍夫变换进行直线识别。
以后官方应该会更新霍夫变换识别形状的函数。

# Canny Edge and Hough Transform Example:
#
# This example demonstrates using the Canny edge detector
# And the Hough transform to find straight lines in an image.

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)
clock = time.clock() # Tracks FPS.

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.
    img.find_edges(image.EDGE_CANNY, threshold=(50, 80))  # Find edges
    #利用canny算子进行快速边缘检测
    lines = img.find_lines(threshold=50) # Find lines.
    #直线识别
    for l in lines: 
        img.draw_line(l, color=(127)) # Draw lines
        #标记出这条直线。

原图:

运行程序效果如图: