Example: 02-Image-Processing/01-Image-Filters/perspective_and_rotation_correction.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 旋转校正
#
# 此示例演示了如何使用rotation_corr()函数来校正
# 透视畸变,然后在3D空间中旋转新校正后的图像
# 以处理后续运动。

import sensor
import time

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time=2000)
clock = time.clock()

# 图像将被扭曲,使得以下点成为新的:
#
#   (0,   0)
#   (w-1, 0)
#   (w-1, h-1)
#   (0,   h-1)
#
# Try setting the points below to the corners of a quadrilateral
# (in clock-wise order) in the field-of-view. You can get points
# 通过在帧缓冲区上点击并拖动
# 记录直方图部件中显示的值。

w = sensor.width()
h = sensor.height()

TARGET_POINTS = [
    (0, 0),  # (x, y) 请修改此处!
    (w - 1, 0),  # (x, y) 请修改此处!
    (w - 1, h - 1),  # (x, y) 请修改此处!
    (0, h - 1),
]  # (x, y) 请修改此处!

# 每帧旋转的角度...
X_ROTATION_DEGREE_RATE = 5
Y_ROTATION_DEGREE_RATE = 0.5
Z_ROTATION_DEGREE_RATE = 0
X_OFFSET = 0
Y_OFFSET = 0

ZOOM_AMOUNT = 1  # 数值越小则放大,越大则缩小。
FOV_WINDOW = 25  # 介于0到180之间,代表场景的视野范围
# 在3D空间旋转图像时的窗口。当接近
# 零时,线条会随着窗口移动变得更直
# 远离在3D空间中旋转的图像。较大的
# 该值使窗口在3D空间中更靠近图像,从而
# 导致更多的透视变形,有时甚至
# 使图像在3D中与场景窗口相交。

x_rotation_counter = 0
y_rotation_counter = 0
z_rotation_counter = 0

while True:
    clock.tick()

    img = sensor.snapshot().rotation_corr(
        x_rotation=x_rotation_counter,
        y_rotation=y_rotation_counter,
        z_rotation=z_rotation_counter,
        x_translation=X_OFFSET,
        y_translation=Y_OFFSET,
        zoom=ZOOM_AMOUNT,
        fov=FOV_WINDOW,
        corners=TARGET_POINTS,
    )

    x_rotation_counter += X_ROTATION_DEGREE_RATE
    y_rotation_counter += Y_ROTATION_DEGREE_RATE
    z_rotation_counter += Z_ROTATION_DEGREE_RATE

    print(clock.fps())

results matching ""

    No results matching ""