OpenCV踩坑(一)为什么你的cv2.drawContours()绘制轮廓失败

活不多说,先上代码:(错的哈!!!)

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()

搞定,没报错-->运行

图片预处理之后(嗯,没毛病...)

接下来,看到绘制轮廓

评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值