活不多说,先上代码:(错的哈!!!)
import cv2
# 读入银行卡数字的模板图片 灰度图
template = cv2.imread('ocr_a_reference.png')
template = cv2.cvtColor(template, cv2.COLOR_BGR2GRAY)
# 对模板图片进行二值化
template_thresh = cv2.threshold(template, 10, 255, cv2.THRESH_BINARY_INV)[1]
cv2.imshow('template_thresh', template_thresh)
cv2.waitKey(0)
# 轮廓检测 cv2.RETR_EXTERNAL--检测外侧轮廓
contours, hierarchy = cv2.findContours(template_thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
print(contours)
# 轮廓绘制
res = cv2.drawContours(template_thresh.copy(), contours, -1, (0, 0, 255), 3)
cv2.imshow('res', res)
cv2.waitKey(0)
cv2.destroyAllWindows()
搞定,没报错-->运行
图片预处理之后(嗯,没毛病...)
接下来,看到绘制轮廓