1 回答

TA貢獻1898條經(jīng)驗 獲得超8個贊
這是一個簡單的方法:
轉(zhuǎn)換為灰度
查找等值線,從左到右對等值線進行排序,并使用等值線區(qū)域進行過濾
提取投資回報率
在 Otsu 的閾值化以獲得二進制圖像之后,我們使用 imutils.contours.sort_contours()
從左到右對輪廓進行排序。這可確保當我們循環(huán)訪問每個輪廓時,每個字符的順序都正確。此外,我們使用最小閾值區(qū)域進行濾波,以消除小噪聲。這是檢測到的字符
我們可以使用Numpy切片提取每個字符。以下是每個已保存角色的投資回報率
import cv2
from imutils import contours
# Load image, grayscale, Otsu's threshold
image = cv2.imread('1.png')
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
thresh = cv2.threshold(gray,0,255,cv2.THRESH_OTSU + cv2.THRESH_BINARY)[1]
# Find contours, sort from left-to-right, then crop
cnts = cv2.findContours(thresh, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
cnts, _ = contours.sort_contours(cnts, method="left-to-right")
ROI_number = 0
for c in cnts:
area = cv2.contourArea(c)
if area > 10:
x,y,w,h = cv2.boundingRect(c)
ROI = 255 - image[y:y+h, x:x+w]
cv2.imwrite('ROI_{}.png'.format(ROI_number), ROI)
cv2.rectangle(image, (x, y), (x + w, y + h), (36,255,12), 2)
ROI_number += 1
cv2.imshow('thresh', thresh)
cv2.imshow('image', image)
cv2.waitKey()
添加回答
舉報