OpenMv多模板匹配

import time, sensor, image
from image import SEARCH_EX, SEARCH_DS
from pyb import UART
import ustruct
#从imgae模块引入SEARCH_EX和SEARCH_DS。使用from import仅仅引入SEARCH_EX,
#SEARCH_DS两个需要的部分,而不把image模块全部引入。

# Reset sensor
sensor.reset()

# Set sensor settings
sensor.set_contrast(1)
sensor.set_gainceiling(16)
# Max resolution for template matching with SEARCH_EX is QQVGA
sensor.set_framesize(sensor.QQVGA)
# You can set windowing to reduce the search image.
#sensor.set_windowing(((640-80)//2, (480-60)//2, 80, 60))
sensor.set_pixformat(sensor.GRAYSCALE)

uart = UART(3,115200)   #定义串口3变量
uart.init(115200, bits=8, parity=None, stop=1) # init with given parameters

# Load template.
# Template should be a small (eg. 32x32 pixels) grayscale image.

Template = [image.Image("/5.pgm"),image.Image("/6.pgm"),image.Image("/7.pgm"),image.Image("/8.pgm")]
#加载模板图片



clock = time.clock()

# Run template matching
while (True):
    clock.tick()
    img = sensor.snapshot()

    #r = img.find_template(template, 0.70, step=4, search=SEARCH_EX) #, roi=(10, 0, 60, 60))
    #find_template(template, threshold, [roi, step, search]),threshold中
    #的0.7是相似度阈值,roi是进行匹配的区域(左上顶点为(10,0),长80宽60的矩形),
    #注意roi的大小要比模板图片大,比frambuffer小。
    #把匹配到的图像标记出来

    for i in range(4):
            r = img.find_template(Template[i], 0.70, step=4, search=SEARCH_EX)
            if r:
                img.draw_rectangle(r)
                num = i + 5
                print(num)
                FH = bytearray([0x2C,0x12,num,0x5B])
                uart.write(FH)

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值