logo

使用函数img.histogram.get_threhsold()错误

2018-09-11 16:52
F
_18200104547
779f3532-f7aa-4c8b-a1b3-9d93be0ec4f7.png

想实现自适应阈值对图像进行阈值分割,使用img.histogram.get_threhsold()函数得到阈值时出现错误提示: AttributeError:'bound_method' object has no attribute 'get_threshold',不知道是不是自己函数写错了,不知道有没有人可以帮忙解惑一下

while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.0)
#   image.get_histogram()
    th = img.histogram.get_threhsold([roi])
#   th = (42, 100, -128, 127, -128, 127)
    img.binary([th],invert = True)
I
网红小智智 星瞳科技

请提供全部的代码

2018-09-12 10:26
F
_18200104547
# Find Rects Example
#
# This example shows off how to find rectangles in the image using the quad threshold
# detection code from our April Tags code. The quad threshold detection algorithm
# detects rectangles in an extremely robust way and is much better than Hough
# Transform based methods. For example, it can still detect rectangles even when lens
# distortion causes those rectangles to look bent. Rounded rectangles are no problem!
# (But, given this the code will also detect small radius circles too)...

import sensor, image, time, lcd

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster (160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
lcd.init()

roi = (80,0,80,120)#搜索矩形的图像区域

#kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
#kernel = [-1, -1, -1,\
#         -1, +9, -1,\
#         -1, -1, -1]



while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.0)
#   th = img.histogram.get_threhsold([roi])

#   img.binary([th],invert = True)
#   img.find_edges(image.EDGE_CANNY, threshold=(50, 80))
#   img.laplacian(2)



    # `threshold` below should be set to a high enough value to filter out noise
    # rectangles detected in the image which have low edge magnitudes. Rectangles
    # have larger edge magnitudes the larger and more contrasty they are...

    for r in img.find_rects(roi,threshold = 10000):
        statistics = img.get_statistics(roi=r.rect())
        print(statistics)
        if statistics.mean() <= 50:
           img.draw_rectangle(r.rect(), color = (255, 0, 0))
           for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        lcd.display(img)
        print(r.rect())

    print("FPS %f" % clock.fps())
2018-09-12 15:19
F
_18200104547

@kidswong999

# Find Rects Example
#
# This example shows off how to find rectangles in the image using the quad threshold
# detection code from our April Tags code. The quad threshold detection algorithm
# detects rectangles in an extremely robust way and is much better than Hough
# Transform based methods. For example, it can still detect rectangles even when lens
# distortion causes those rectangles to look bent. Rounded rectangles are no problem!
# (But, given this the code will also detect small radius circles too)...

import sensor, image, time, lcd

sensor.reset()
sensor.set_pixformat(sensor.RGB565) # grayscale is faster (160x120 max on OpenMV-M7)
sensor.set_framesize(sensor.QQVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
lcd.init()

roi = (80,0,80,120)#搜索矩形的图像区域

#kernel_size = 1 # kernel width = (size*2)+1, kernel height = (size*2)+1
#kernel = [-1, -1, -1,\
#         -1, +9, -1,\
#         -1, -1, -1]



while(True):
    clock.tick()
    img = sensor.snapshot().lens_corr(1.0)
#   th = img.histogram.get_threhsold([roi])

#   img.binary([th],invert = True)
#   img.find_edges(image.EDGE_CANNY, threshold=(50, 80))
#   img.laplacian(2)



    # `threshold` below should be set to a high enough value to filter out noise
    # rectangles detected in the image which have low edge magnitudes. Rectangles
    # have larger edge magnitudes the larger and more contrasty they are...

    for r in img.find_rects(roi,threshold = 10000):
        statistics = img.get_statistics(roi=r.rect())
        print(statistics)
        if statistics.mean() <= 50:
           img.draw_rectangle(r.rect(), color = (255, 0, 0))
           for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0))
        lcd.display(img)
        print(r.rect())

    print("FPS %f" % clock.fps())
2018-09-13 14:32
I
网红小智智 星瞳科技
img = sensor.snapshot().lens_corr(1.0)
hist = img.get_histogram()
th = hist.get_threshold()