Example: 01-Camera/07-Sensor-Control/autofocus.py

# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2024 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 自动对焦示例
#
# 此示例展示了如何对支持自动对焦功能的摄像头进行自动对焦。

import sensor
import time

sensor.reset()  # 重置并初始化传感器。
sensor.set_pixformat(sensor.RGB565)  # 将像素格式设置为RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)  # 将帧大小设置为QVGA (320x240)
sensor.skip_frames(time=2000)  # 等待设置生效。
clock = time.clock()  # 创建一个时钟对象来跟踪FPS。

try:
    # 摄像头现在会对准其前方的任何物体进行对焦。
    sensor.ioctl(sensor.IOCTL_TRIGGER_AUTO_FOCUS)
except:
    raise (Exception("Auto focus is not supported by your sensor/board combination."))

while True:
    clock.tick()  # 更新FPS时钟。
    img = sensor.snapshot()  # 拍照并返回图像。
    print(clock.fps())  # 注意:OpenMV摄像头在连接至IDE时运行速度会降低约一半。
    # 断开连接后,帧率应会提升。

results matching ""

    No results matching ""