首页 > 解决方案 > 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

我不仅找到了符号,还找到了单词,框架中的单词,我只需要符号来进一步被神经网络识别。

标签: pythonopencvneural-network

解决方案


推荐阅读