logo

为什么openmv上调用difference后有条纹

2024-02-28 09:44
J
uea4
eefd8bde-b406-4355-a8b3-28cd3782f1d7.png
863cf56f-0300-4b10-ba4e-75d130b3ea43.png
c561a9a4-abae-4e1a-ab6c-3cf326798978.png
1cc12013-9c78-40bc-9c4f-a17d32679edd.jpg
17aa7732-4bf0-4745-b317-b6d613cd2c1b.png
3d801130-7d9b-4bdb-afb4-71974720e74d.png
7dba5602-c710-4558-bd0c-a90f86f0b632.png
import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)


sensor.skip_frames(time = 2000) # Give the user time to get ready.

i=0
m=320
n=240
temp = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_past = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_now = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
kernel_edge = [1, 1,  1, \
          1,  -8,  1, \
           1,  1,  1]


img_past=sensor.snapshot()
clock = time.clock()
while i < 1000:
    # 获取当前灰度图
    img_now = sensor.snapshot()

    #当前灰度图归一化
    #temp.normalize(0, 255)
#    img_now.replace(temp)
    #差分图的绝对值
    img_now.save("temp3_withoutdifference/img_now"+str(i)+".bmp")
    img_diff2 = img_now.difference(img_past)
    img_diff2.morph(1, kernel_edge)
    img_diff2.save("temp2/diff"+str(i)+".bmp")



    i+=1
    img_past.replace(img_now)
    print(clock.fps())
2024-02-29 20:51
I
网红小智智 星瞳科技

问题在于

img_now = sensor.snapshot()
img_diff2 = img_now.difference(img_past)

应该换成

img = sensor.snapshot()
img_now.replace(img)
img.difference(img_past)
img_diff2.replace(img)

下面的代码是可以运行的

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.QVGA)


sensor.skip_frames(time = 2000) # Give the user time to get ready.

i=0
m=320
n=240
#temp = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_past = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
img_now = sensor.alloc_extra_fb(m, n, sensor.GRAYSCALE)
kernel_edge = [1, 1,  1, \
          1,  -8,  1, \
           1,  1,  1]


img=sensor.snapshot()
img_past.replace(img)

clock = time.clock()
while i < 1000:
    # 获取当前灰度图
    img = sensor.snapshot()

    #当前灰度图归一化
    #temp.normalize(0, 255)
    img_now.replace(img)
    #差分图的绝对值
#    img.save("temp3_withoutdifference/img_now"+str(i)+".bmp")
    img.difference(img_past)
    img.morph(1, kernel_edge)
#    img.save("temp2/diff"+str(i)+".bmp")



    i+=1
    img_past.replace(img_now)
    print(clock.fps())