selective_search.py
# 本作品采用MIT许可证授权。
# 版权所有 (c) 2013-2023 OpenMV LLC。保留所有权利。
# https://github.com/openmv/openmv/blob/master/LICENSE
#
# 选择性搜索示例
import csi
import time
csi0 = csi.CSI()
csi0.reset() # 重置并初始化传感器。
csi0.pixformat(csi.RGB565) # 将像素格式设置为RGB565 (or GRAYSCALE)
csi0.framesize(csi.QVGA) # 将帧大小设置为QVGA (320x240)
csi0.snapshot(time=2000) # 等待设置生效。
csi0.auto_gain(False)
csi0.auto_exposure(False, exposure_us=10000)
clock = time.clock() # 创建一个时钟对象来跟踪FPS。
while True:
clock.tick() # 更新FPS时钟。
img = csi0.snapshot() # 拍照并返回图像。
rois = img.selective_search(threshold=200, size=20, a1=0.5, a2=1.0, a3=1.0)
for r in rois:
img.draw_rectangle(r, color=(255, 0, 0))
# from random import randint
# img.draw_rectangle(r, color=(randint(100, 255), randint(100, 255), randint(100, 255)))
print(clock.fps())