# Untitled - By: SAU - 周二 2月 28 2023
import sensor, image, time,math,gc
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(10)
clock = time.clock()
while(True):
clock.tick()
img = sensor.snapshot()
img.gaussian(1)
grad = [[0 for i in range(img.height())] for j in range(img.width())]
for i in range(1, img.width()- 1):
for j in range(1, img.height() - 1):
grad_x = 2*img.get_pixel(i+1,j) + img.get_pixel(i+1,j-1) + img.get_pixel(i+1,j+1) - 2*img.get_pixel(i-1,j) - img.get_pixel(i-1,j-1) - img.get_pixel(i-1,j+1)
grad_y = 2*img.get_pixel(i,j+1) + img.get_pixel(i-1,j+1) + img.get_pixel(i+1,j+1) - 2*img.get_pixel(i,j-1) - img.get_pixel(i-1,j-1) - img.get_pixel(i+1,j-1)
grad_x = math.floor(grad_x / 4)
grad_y = math.floor(grad_y / 4)
#合梯度
grad[i][j] = math.floor(math.sqrt(grad_x * grad_x + grad_y * grad_y))
img.set_pixel(i,j,(math.floor(math.sqrt(grad_x * grad_x + grad_y * grad_y))))
print(clock.fps())
L
lodp
@lodp
0
声望
1
楼层
299
资料浏览
0
粉丝
0
关注
lodp 发布的帖子
-
帧率只有零点几是怎么回事 只有两层for循环