当前位置 博文首页 > 8U_沉迷单车的追风少年:解决error: (-210:Unsupported format o
原程序:
# -*- 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)
报错:
cs