# 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())
我
我叫panhe
@我叫panhe
0
声望
9
楼层
518
资料浏览
0
粉丝
0
关注
我叫panhe 发布的帖子
-
RE: 使用函数img.histogram.get_threhsold()错误
-
RE: 使用函数img.histogram.get_threhsold()错误
# 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())
-
使用函数img.histogram.get_threhsold()错误
想实现自适应阈值对图像进行阈值分割,使用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)
-
RE: 请问下除了例程中的几个feature能用其他的图像特征吗比如surf之类的
@kidswong999 Openmv内置的一些图像算法在实际场景中应用的比较吃力,基本上精度很难达到要求。