Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Aniket025
GitHub Repository: Aniket025/Medical-Prescription-OCR
Path: blob/master/Model-2/main.py
427 views
1
2
# coding: utf-8
3
4
# In[1]:
5
6
7
import numpy as np
8
import pandas as pd
9
import matplotlib.pyplot as plt
10
import tensorflow as tf
11
import cv2
12
from PIL import Image
13
import pytesseract
14
import os
15
16
from ocr.helpers import implt, resize
17
from ocr import page
18
from ocr import words
19
20
21
IMG = '1' # 1, 2, 3
22
filename = "test/2.jpg"
23
save_filename = "test/2_1.jpg"
24
25
26
image = cv2.cvtColor(cv2.imread(filename), cv2.COLOR_BGR2RGB)
27
implt(image)
28
crop = page.detection(image)
29
implt(crop)
30
31
gray = cv2.cvtColor(crop, cv2.COLOR_BGR2GRAY)
32
gray = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)[1]
33
gray = cv2.medianBlur(gray, 3)
34
implt(gray)
35
36
cv2.imwrite(save_filename, gray)
37
38
text = pytesseract.image_to_string(Image.open(save_filename))
39
os.remove(save_filename)
40
print(text)
41
42