当前位置:   article > 正文

openmv实现自适应阈值_openmv自适应阈值

openmv自适应阈值

我们都知道Opencv上有许多算法,可以实现自适应阈值
https://blog.csdn.net/qq_51491920/article/details/125727129

那么 Openmv 上的自适应阈值要如何实现呢。

废话不多说,直接上代码。如果想要知道原理,可以看上面链接中的文章。

获取前景

import sensor, image, time


sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    # to the IDE. The FPS should increase once disconnected.
    hist = img.get_histogram()
    Thresholds = hist.get_threshold()
    print(Thresholds)
    v = Thresholds.value()
    img.binary([(0,v)])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

获取背景

import sensor, image, time


sensor.reset()                      # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA)   # Set frame size to QVGA (320x240)
sensor.skip_frames(time = 2000)     # Wait for settings take effect.
clock = time.clock()                # Create a clock object to track the FPS.


while(True):
    clock.tick()                    # Update the FPS clock.
    img = sensor.snapshot()         # Take a picture and return the image.
    # to the IDE. The FPS should increase once disconnected.
    hist = img.get_histogram()
    Thresholds = hist.get_threshold()
    print(Thresholds)
    v = Thresholds.value()
    img.binary([(v, 255)])
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19

可以根据个人需求,选择所需要的代码。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/喵喵爱编程/article/detail/920243
推荐阅读
相关标签
  

闽ICP备14008679号