python - 数字边界框 Opencv Python
问题描述
我正在尝试从门牌号码中提取边界框,这是我的代码,距离想要的结果还很远。
问题是,在这种情况下,该框不会将数字框起来
thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY_INV + cv2.THRESH_OTSU)[1]
original = img.copy()
# Find contours, obtain bounding box, extract and save ROI
ROI_number = 0
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
rect = cv2.boundingRect(c)
x,y,w,h = rect
#x,y,w,h = cv2.boundingRect(c)
if 100< w < 1000 and 100< h < 1000:
print(x, y, w, h, w*h)
cv2.rectangle(img, (x, y), (x + w, y + h), (36,255,12), 2)
ROI = original[y:y+h, x:x+w]
#cv2.imwrite('ROI_{}.png'.format(ROI_number), ROI)
ROI_number += 1
原来的
盒装
解决方案
推荐阅读
- javascript - 访问数组属性的编译错误
- sql - Select * From Table Where Name in like(通配符)
- angular8 - (ngx-admin/Nebular) 如何将 Grid 系统与 nebular 集成?
- mongodb - Mongoose 从多个文档更新多个子文档
- java - 如何使用 WebView 为 onClickListener 设置线性布局
- intellij-idea - 如果已通过 JetBrains Toolbox 安装 IntelliJ IDEA,如何在 Windows 上下文菜单中提供“在 IntelliJ IDEA 中打开此项目”选项?
- gcloud - 无法下载谷歌凭据 json 文件
- javascript - 如何使用 ES6 HOF Javascript 在数组中查找重复对象(所有键值对都应该相同)
- python - 在 Python 中使用不同的符号预处理文本数据
- amazon-web-services - 如何使用 AWS Lambda 捕获无服务器网站截图?