Advertisement
Guest User

Untitled

a guest
Feb 21st, 2020
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. import pytesseract
  2. import cv2
  3. from PIL import Image
  4.  
  5. def ProcessImage():
  6. image_path = "bdo_fish.jpg"
  7. image = cv2.imread(image_path) # load the example image
  8. # image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # convert to grayscale
  9. # image = cv2.bitwise_not(image) # convert to negative
  10. # height, width = image.shape
  11.  
  12. img_segment = image[55:80, 720:890]
  13. cv2.imwrite(filename, img_segment)
  14. text = ExtractText(img_segment)
  15. print(text)
  16.  
  17. # segments = [
  18. # image[:int(height*0.33), :],
  19. # image[int(height*0.33):int(height*0.66), :],
  20. # image[int(height*0.66):, :]
  21. # ]
  22.  
  23. # for segment in segments:
  24. # img_text = ExtractText(segment)
  25.  
  26. def ExtractText(img):
  27. pytesseract.pytesseract.tesseract_cmd = 'C:/Program Files/Tesseract-OCR/tesseract'
  28. return pytesseract.image_to_string(img)
  29.  
  30. filename = "image_processed.png"
  31. ProcessImage()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement