logo

边缘检测的不兼容性问题

2020-05-10 12:20
7
vdfh

想对经过【边缘检测】处理后得到的图片进行【特征点保存】,但是运行代码时,【边缘检测】只能进行一次,无法循环,而【特征点保存】可以一直循环检测下去。想让【边缘检测】和【特征点保存】一起循环运行,

import sensor, time, image

sensor.reset()

sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((320, 240))
sensor.set_pixformat(sensor.GRAYSCALE)

sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False, value=100)

FILE_NAME = "666"
img = sensor.snapshot()
kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
kernel = [-1, -1, -1,\
          -1, +8, -1,\
          -1, -1, -1]
thresholds = [(100, 255)] # grayscale thresholds设置阈值

clock = time.clock() # 追踪FPS

if (sensor.get_id() == sensor.OV7725):
    sensor.__write_reg(0xAC, 0xDF)
    sensor.__write_reg(0x8F, 0xFF)

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    img.morph(kernel_size, kernel)
    img.binary(thresholds)
    img.erode(1, threshold = 2)
    print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    time.sleep(100)
    
    kpts = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
    if (kpts == None):
        raise(Exception("Couldn't find any keypoints!"))
    
    image.save_descriptor(kpts, "/%s.orb"%(FILE_NAME))
    
    img.draw_keypoints(kpts)
    sensor.snapshot()

代码该怎么改?谢谢

2020-05-11 12:11
I
网红小智智 星瞳科技

最开始的sensor.__write_reg添加了之后,sensor的图像不能更新。

最后一行sensor.snapshot()是什么用?

我注释掉了这两个。

以下的代码是可以的。

import sensor, time, image

sensor.reset()

sensor.set_contrast(3)
sensor.set_gainceiling(16)
sensor.set_framesize(sensor.VGA)
sensor.set_windowing((320, 240))
sensor.set_pixformat(sensor.GRAYSCALE)

sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False, value=100)

FILE_NAME = "666"
img = sensor.snapshot()
kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
kernel = [-1, -1, -1,\
          -1, +8, -1,\
          -1, -1, -1]
thresholds = [(100, 255)] # grayscale thresholds设置阈值

clock = time.clock() # 追踪FPS

#if (sensor.get_id() == sensor.OV7725):
    #sensor.__write_reg(0xAC, 0xDF)
    #sensor.__write_reg(0x8F, 0xFF)

while(True):
    clock.tick() # Track elapsed milliseconds between snapshots().
    img = sensor.snapshot() # Take a picture and return the image.

    img.morph(kernel_size, kernel)
    img.binary(thresholds)
    img.erode(1, threshold = 2)
    print(clock.fps()) # Note: Your OpenMV Cam runs about half as fast while
    #time.sleep(100)
    
    kpts = img.find_keypoints(max_keypoints=150, threshold=10, scale_factor=1.2)
    if (kpts == None):
        raise(Exception("Couldn't find any keypoints!"))
    
    image.save_descriptor(kpts, "/%s.orb"%(FILE_NAME))
    
    img.draw_keypoints(kpts)