logo

二值化处理,模板匹配识别不到数字

2022-09-11 22:04
4
_2iay

# 颜色二值化滤波例子

#

# 这个脚本展示了二值图像滤波。

# 您可以传递二进制任意的阈值来分割图像。

import sensor, image, time

from image import SEARCH_EX, SEARCH_DS

sensor.set_contrast(1)

sensor.set_gainceiling(16)

sensor.reset()

sensor.set_framesize(sensor.QQVGA)

sensor.set_pixformat(sensor.GRAYSCALE)

#设置颜色阈值,如果是rgb图像,六个数字分别为(minL, maxL, minA, maxA, minB, maxB);

#如果是灰度图,则只需设置(min, max)两个数字即可。

red_threshold = (0,100, 0,127, 0,127) # L A B

green_threshold = (0,100, -128,0, 0,127) # L A B

blue_threshold = (0,100, -128,127, -128,0) # L A B

gray=(0,130)

sensor.skip_frames(time = 2000)

clock = time.clock()

template = image.Image("/5.0.pgm")

#使用工具 - >机器视觉 - >阈值编辑器选择更好的阈值。

while(True):

clock.tick()

img = sensor.snapshot().lens_corr(strength = 1.8, zoom = 1.0)

img.binary([gray],invert = 1)

r = img.find_template(template, 0.50, step=4, search=SEARCH_EX , roi=(55,25, 45, 60))

if r:

img.draw_rectangle(r,rgb=(255,0,0))

print(clock.fps())![0_1662905051472_screenshot_20220911_220156.png]

704689bb-105a-4d09-aea0-bb202cb4a5fc.png
2022-09-15 19:34
I
网红小智智 星瞳科技

你这个应用,用目标点检测吧

https://singtown.com/learn/50918/