Browse Source

More testing

master
Quildra 4 years ago
parent
commit
cf0e8c4cb0
  1. 14
      OCR.py

14
OCR.py

@ -1,6 +1,7 @@
import cv2 import cv2
from PIL import Image from PIL import Image
import pytesseract import pytesseract
from wand.image import Image as WandImage
card_name_roi = { 'x':44, 'y':32, 'w':360, 'h':40 } card_name_roi = { 'x':44, 'y':32, 'w':360, 'h':40 }
@ -35,7 +36,14 @@ def thick_font(image):
file_path = "data/WTR/WTR003.png" file_path = "data/WTR/WTR003.png"
img = cv2.imread(file_path) with WandImage(filename=file_path) as img2:
width = img2.width
height = img2.height
img2.resize(width*4, height*4)
img2.save(filename="temp/big.jpg")
big_file_path = "temp/big.jpg"
img = cv2.imread(big_file_path)
inverted_image = cv2.bitwise_not(img) inverted_image = cv2.bitwise_not(img)
cv2.imwrite("temp/inverted.jpg", inverted_image) cv2.imwrite("temp/inverted.jpg", inverted_image)
@ -55,7 +63,7 @@ dilated_image = thick_font(no_noise)
cv2.imwrite("temp/dilated_image.jpg", dilated_image) cv2.imwrite("temp/dilated_image.jpg", dilated_image)
im = Image.open(file_path) im = Image.open(file_path)
ocr_result = pytesseract.image_to_string(im) ocr_result = pytesseract.image_to_string(im, config='psm 11')
print("Unaltered:") print("Unaltered:")
print (ocr_result) print (ocr_result)
print("===========================") print("===========================")
@ -106,5 +114,5 @@ def testArea(image, x,y,w,h):
ocr_result = pytesseract.image_to_string(gray_image) ocr_result = pytesseract.image_to_string(gray_image)
print(ocr_result) print(ocr_result)
testArea(img, card_name_roi['x'], card_name_roi['y'], card_name_roi['w'], card_name_roi['h']) testArea(img, card_name_roi['x']*4, card_name_roi['y']*4, card_name_roi['w']*4, card_name_roi['h']*4)
cv2.imwrite("temp/markup.jpg", img) cv2.imwrite("temp/markup.jpg", img)
Loading…
Cancel
Save