入力として写真を取り、書かれたテキストを検出するプログラムを作成しました。プログラムを編集して、さらに 2 つの機能を追加する必要があります。
まず、輪郭座標を取得できたので(完了)、各文字の輪郭線を囲む背景の色を取得する方法を知りたい(複数のポイントで、RGBカラーの平均を計算したいため)そのキャラクターを取り巻く値)自分がやりたいことを行う機能がすでにあるかどうか、または従うべき特定のアプローチがあるかどうかはわかりません
次に、輪郭の内側を塗りつぶそうとしましたが、うまくいきませんでした。cv2.drawContours で、thickness=-1 と thickness=cv2.FILLE の両方を試した理由を教えてください。何も機能せず、明らかにコントロール ラインは青色ですが、内部は青色ではありません
コードが完璧ではなく、非常に多くのコメントがあることは知っていますが、それは私が新しいことを試みているキムだからです。助けてくれるすべての人に事前に感謝します
import cv2
import pytesseract
import numpy as np
from PIL import ImageGrab
import pyautogui
def Contour(img):
Contours,hierarchy = cv2.findContours(img, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)
for cnt in Contours:
area = cv2.contourArea(cnt)
# print(area)
# if area<150: could be useded to be cpecific
# we need a copy of the image so we dont draw on the original or thickness=-1
cv2.drawContours(imgcpy, cnt, -1, (255,0,0), thickness=-1)
#pytesseract.pytesseract.tesseract_cmd= 'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
cap= cv2
img = cv2.imread('D:\\opencv\\R\\img\\lec\\3.png')
imgcpy = img.copy()
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# for japanese txt = pytesseract.image_to_string(gray, lang='jpn')
txt = pytesseract.image_to_string(gray)
imgblur = cv2.GaussianBlur(img, (7, 7), 0)
imgcanny = cv2.Canny(img, 200, 200)
#imgDialation = cv2.dilate(imgcanny, kernel, iterations=1)
#imgeroded = cv2.erode(imgDialation, kernel, iterations=1)
imBlank = np.zeros_like(img)
# waste of time only the same picture work -_-
# imstack = np.hstack((gray,gray,gray))
Contour(imgcanny)
cv2.imshow('Contour', imgcpy)
#img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print(txt)
print(Contour(imgcanny))
#cv2.imshow('test', img)
cv2.waitKey()