Routine explanation -09-find_rects identifies rectangles

Video tutorial 13 - Shape recognition: https://singtown.com/learn/50009/
Video Tutorial 21 - A car chasing other objects: https://singtown.com/learn/50041/

This routine uses a four-element detection algorithm to identify the rectangle, which is also used to identify AprilTag. Four-element detection algorithm can recognize rectangles of any size and Angle. Function returns a list of rect objects.

rect.corners()\ Returns a list of four tuples, each representing the four vertices of the rectangle (x, y). Start at the top left vertex and sort clockwise.

rect.rect()\ Returns the detected rectangle of the outer rectangle (x, y, w, h).

rect.magnitude()\ Returns the size of the detected rectangle.

# Find Rects Example
#
# 这个例子展示了如何使用april标签代码中的四元检测代码在图像中找到矩形。 四元检测算法以非常稳健的方式检测矩形,并且比基于Hough变换的方法好得多。 例如,即使镜头失真导致这些矩形看起来弯曲,它仍然可以检测到矩形。 圆角矩形是没有问题的!
# (但是,这个代码也会检测小半径的圆)...

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # 灰度更快(160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()

    # 下面的`threshold`应设置为足够高的值,以滤除在图像中检测到的具有
    # 低边缘幅度的噪声矩形。最适用与背景形成鲜明对比的矩形。

    for r in img.find_rects(threshold = 10000):
        img.draw_rectangle(r.rect(), color = (255, 0, 0))
        for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        print(r)

    print("FPS %f" % clock.fps())

original image:\

The recognition effect is shown as follows:\

Singtown Technology OpenMV official Chinese document function explanation:

results matching ""

    No results matching ""