python - OpenCV 搜索 сontours
问题描述
如何仅找到角色的轮廓? 在此处输入图像描述
img = cv2.imread('C:\\output5.jpg')
# grayscale
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.waitKey(0)
# binarize
ret, thresh = cv2.threshold(gray, 127, 255, cv2.THRESH_BINARY_INV)
cv2.waitKey(0)
# find contours
ctrs, hier = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
# sort contours
sorted_ctrs = sorted(ctrs, key=lambda ctr: cv2.boundingRect(ctr)[0])
for i, ctr in enumerate(sorted_ctrs):
# Get bounding box
x, y, w, h = cv2.boundingRect(ctr)
# Getting ROI
roi = img[y:y + h, x:x + w]
# show ROI
# cv2.imwrite('roi_imgs.png', roi)
cv2.imshow('charachter' + str(i), roi)
cv2.rectangle(img, (x, y), (x + w, y + h), (90, 0, 255), 2)
cv2.waitKey(0)
cv2.imshow('marked areas', img)
cv2.waitKey(0)>quote
我不仅找到了符号,还找到了单词,框架中的单词,我只需要符号来进一步被神经网络识别。
解决方案
推荐阅读
- javascript - 样式外部的 LitElement 组件形式
- java - Spring CrudRepository 相同的擦除
- dialogflow-es - 无法用尼日利亚语言创建 Dialogflow 机器人
- python - Python:从特定的 .env 文件中获取 env 变量的值
- ios - 使用 Xcode 12 + StoreKit 配置文件验证收据
- python - 为什么在 MacOS 上构建我的 kivy 应用程序时不能运行 ./toolchain.py?
- ios - 滚动时隐藏/取消隐藏 NavigationItem SearchController
- python - “ManyToManyField”的实例没有“全部”成员
- javascript - 我应该如何在打字稿中将 Blob/File 数组附加到 formData?
- javascript - 单击功能正在删除 JavaScript 中不在索引处的 localStorage 项目的末尾