Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pytesseract
- import cv2
- from PIL import Image
- def ProcessImage():
- image_path = "bdo_fish.jpg"
- image = cv2.imread(image_path) # load the example image
- # image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # convert to grayscale
- # image = cv2.bitwise_not(image) # convert to negative
- # height, width = image.shape
- img_segment = image[55:80, 720:890]
- cv2.imwrite(filename, img_segment)
- text = ExtractText(img_segment)
- print(text)
- # segments = [
- # image[:int(height*0.33), :],
- # image[int(height*0.33):int(height*0.66), :],
- # image[int(height*0.66):, :]
- # ]
- # for segment in segments:
- # img_text = ExtractText(segment)
- def ExtractText(img):
- pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract'
- return pytesseract.image_to_string(img)
- filename = "image_processed.png"
- ProcessImage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement