logo

请教亮度对比度以及一段找圆代码的问题

2020-05-05 15:54
8
ul1g
请教OPENMV4中图像亮度和对比度如何调整;另外请教我下面的代码哪里有错误,调试不通过,这段代码是想在灰度力图像中找到一个符合要求的黑色色块,再判断该色块的圆弧度,最后判断输出该色块是不是一个黑色的圆形
# 单色灰度色块跟踪示例
#
# 这个例子展示了使用OpenMV Cam的单色灰度跟踪。

import sensor, image, time

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
# 下面的灰度阈值设置为只能找到非常明亮的白色区域。
thresholds = (120, 0)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(True) # must be turned off for color tracking
sensor.set_auto_whitebal(True) # must be turned off for color tracking
clock = time.clock()

# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = False”合并图像中所有重叠的色块。

while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds], x_stride=50, y_stride=50, pixels_threshold=9000, area_threshold=9000, merge=False):

        for blob in img.find_blobs(blob.roundness() > 0.95):

        #img.draw_rectangle(blob.rect())
        #img.draw_cross(blob.cx(), blob.cy())

    #print(blob.roundness())
    #print(blob.density())
    #print(clock.fps())
    #print(blob.cx(), blob.cy())
    #print(blob.x_hist_bins())
    #print(blob.x_hist_bins())
2020-05-06 12:30
I
网红小智智 星瞳科技

你这个不是一个问题,我现在说代码的问题。

缩进必须严格,即使是注释。所以最下面的几行需要删掉。或者改成正确的缩进。

for下面一行需要内容,不能空着,如果没有需要填写pass。

你的逻辑根本不对。22行和24行多次调用img.find_blobs。

I
网红小智智 星瞳科技

下面的代码是可以运行的。

import sensor, image, time

# Color Tracking Thresholds (Grayscale Min, Grayscale Max)
# 下面的灰度阈值设置为只能找到非常明亮的白色区域。
thresholds = (120, 0)

sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(True) # must be turned off for color tracking
sensor.set_auto_whitebal(True) # must be turned off for color tracking
clock = time.clock()

# 只有比“pixel_threshold”多的像素和多于“area_threshold”的区域才被
# 下面的“find_blobs”返回。 如果更改相机分辨率,
# 请更改“pixels_threshold”和“area_threshold”。 “merge = False”合并图像中所有重叠的色块。

while(True):
    clock.tick()
    img = sensor.snapshot()
    for blob in img.find_blobs([thresholds], x_stride=50, y_stride=50, pixels_threshold=9000, area_threshold=9000, merge=False):
        if (blob.roundness() > 0.95):
            print("found")
I
网红小智智 星瞳科技

每一个新的提问,单独发一个新帖子