OpenCV可以从任何一个ang中识别罗马数字

2024-03-28 18:04:05 发布

您现在位置:Python中文网/ 问答频道 /正文

我已经安装了Python和opencv2.7x86,并使用PyCharm作为我的IDE。这是我的要求。我想在任何角度和形状下识别从1到5的任何罗马数字。所以罗马数字可以是细的,粗的,小的或大的。给定随机数的背景只有一种颜色(亮棕色)。你们有什么好的教程我可以看一下吗?这是我到目前为止得到的,但它不能正常工作。你知道吗

import cv2
import numpy as np

img_rgb = cv2.imread('rz-template.jpg')
img_gray = cv2.cvtColor(img_rgb, cv2.COLOR_BGR2GRAY)

template = cv2.imread('rz-image.jpg',0)
w, h = template.shape[::-1]

res = cv2.matchTemplate(img_gray,template,cv2.TM_CCOEFF_NORMED)
threshold = 0.3
loc = np.where( res >= threshold)

for pt in zip(*loc[::-1]):
    cv2.rectangle(img_rgb, pt, (pt[0] + w, pt[1] + h), (0,255,255), 2)

cv2.imshow('Detected',img_rgb)
cv2.waitKey()

rz-image.jpgrz-template.jpg


Tags: importptimgthresholdnprestemplatergb