logo

颜色跟踪中颜色阈值获取标红代码的意思与原理,该方法与histogram.get_threhsold()的区别是?

2020-04-19 11:54
F
ma2x
2dc65be6-a048-486f-be2b-64a2826fc43c.png
2020-04-20 12:53
I
网红小智智 星瞳科技

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/omv.image.html#histogram.get_percentile

https://docs.singtown.com/micropython/zh/latest/openmvcam/library/omv.image.html#histogram.get_threhsold

2020-04-20 13:04
F
ma2x

主要是不太明白这里边的表述,相如计算直方图频道的CDF,返回一个传递 percentile (0.0 - 1.0) (浮点数)中的直方图的值,我知道是通过累加到一定百分数对应的阈值的值,但是不知道累加到的这个百分数是什么东西,如果调整的话怎么调整。

2020-04-21 19:44
I
网红小智智 星瞳科技

把所有的像素从小到大排起来,

get_percentile(0.1)就是10%位置上的灰度值。

get_percentile(0.9)就是90%位置上的灰度值。

get_percentile(0.5)就是50%位置上的灰度值,也就是中位数。

# Image Histogram Info Example
#
# This script computes the histogram of the image and prints it out.

import sensor, image, time

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE) # or RGB565.
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_auto_whitebal(False) # must be turned off for color tracking
clock = time.clock()

while(True):
    clock.tick()
    img = sensor.snapshot()
    # Gets the grayscale histogram for the image into 8 bins.
    # Bins defaults to 256 and may be between 2 and 256.
    hist = img.get_histogram(bins=8)
    print(hist)
    print(hist.get_percentile(0.1))
    print(clock.fps())

# You can also pass get_histogram() an "roi=" to get just the histogram of that area.
# get_histogram() allows you to quickly determine the color channel information of
# any any area in the image.