logo

在用SSIM例程中,如何找到最大变化图像的坐标?

2024-05-09 15:02
F
gbxv

# 结构相似性(SSIM)示例

import sensor, image, os, time

MIN_TRIGGER_THRESHOLD = -0.4

sensor.reset()

sensor.set_pixformat(sensor.RGB565)

sensor.set_framesize(sensor.QVGA)

sensor.skip_frames(time = 2000)

sensor.set_auto_whitebal(False)

clock = time.clock()

extra_fb = sensor.alloc_extra_fb(sensor.width(), sensor.height(), sensor.RGB565)

print("About to save background image...")

sensor.skip_frames(time = 2000)

extra_fb.replace(sensor.snapshot())

print("Saved background image!")

while(True):

clock.tick()

img = sensor.snapshot()

sim = img.get_similarity(extra_fb)

change = "- Change -" if sim.min() < MIN_TRIGGER_THRESHOLD else "- No Change -"

max_similarity,, max_location = sim.max() # 找到最大变化图像的坐标

if max_similarity < MIN_TRIGGER_THRESHOLD:

x_coord, y_coord = max_location # 获取最大变化图像的坐标

img.draw_rectangle((x_coord-10, y_coord-10, 20, 20), color=(255, 0, 0), thickness=2) # 绘制框

img.draw_cross(x_coord, y_coord, color=(0, 255, 0), thickness=2) # 绘制交叉线

img.show()

print("Max change at:", x_coord, y_coord)

print(clock.fps(), change, sim)