阅读背景:

解决error:(-210:Unsupportedformatorcombinationofformats)[Start]FindContourssupportsonlyCV_8U

来源:互联网 

原程序:

# -*- coding:utf-8 -*-
# 创立时光:2019年7月29日
# 应用轮廓匹配辨认出目的物

import cv2
import numpy as np


# 不同特点的形状匹配
# 输入参数:model_img:目的图象矩阵;train_frame:待检测的图象矩阵
# 输出参数:matching_value:匹配值,越小表现匹配度越高
def contours_matching(model_img,train_frame):


    ret, thresh = cv2.threshold(model_img, 127, 255,0)
    ret, thresh2 = cv2.threshold(train_frame, 127, 255,0)

    img1, contours, hierarchy = cv2.findContours(thresh,2,1)
    cnt1 = contours[0]
    img2, contours, hierarchy = cv2.findContours(thresh2,2,1)
    cnt2 = contours[0]

    matching_value = cv2.matchShapes(cnt1,cnt2,1,0.0)   # 盘算匹配度
    print("匹配度:",matching_value)

    return matching_value


model_img = cv2.imread("../images/contours/circle.png")
train_frame = cv2.imread("../images/contours/circle.png")

matching_value = contours_matching(model_img,train_frame)

# -*- coding:utf-8 -*-
# 创立时光:2019年7月29日
# 



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: