-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmedicine_details.py
36 lines (29 loc) · 1.06 KB
/
medicine_details.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# import the necessary packages
from PIL import Image
import pytesseract
import argparse
import cv2
import os
from crawler import get_details
pytesseract.tesseract_cmd = 'C:/Program Files (x86)/Tesseract-OCR/tesseract'
# load the example image and convert it to grayscale
image = cv2.imread("C:/git/know_your_medicine/images/" + "med2.jpg")
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
cv2.imshow("Image", gray)
# write the grayscale image to disk as a temporary file so we can
# apply OCR to it
filename = "{}.png".format(os.getpid())
print(filename)
cv2.imwrite("C:/git/know_your_medicine/images/" + filename, gray)
#img = cv2.imread("C:/Users/VISHAL/images/" + filename)
#cv2.imshow(filename, img)
# load the image as a PIL/Pillow image, apply OCR, and then delete
# the temporary file
src_path = "C:/git/know_your_medicine/images/"
text = pytesseract.image_to_string(Image.open(src_path + filename))
os.remove("C:/git/know_your_medicine/images/" + filename)
get_details(text)
# show the output images
# cv2.imshow("Image", image)
#cv2.imshow("Output", gray)
cv2.waitKey(0)