Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 61cd76b

Browse files
committed
Update text_from_image to output the OCRed image
1 parent 0b9ee33 commit 61cd76b

File tree

4 files changed

+35
-28
lines changed

4 files changed

+35
-28
lines changed

text_from_image/OCRed.png

272 KB
Loading

text_from_image/main.py

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,37 @@
1+
import cv2
12
import pytesseract
2-
from PIL import Image
3-
path = r'C:\\Program Files\\Tesseract-OCR\\tesseract.exe'
4-
pytesseract.pytesseract.tesseract_cmd = path
5-
image = r'D:\\PersonalProjects\\temp\\Text from Image\\test.png'
6-
text = pytesseract.image_to_string(Image.open(image), lang='eng')
7-
file = open(r'D:\\PersonalProjects\\temp\\Text from Image\\output.txt', 'w')
3+
4+
5+
tesseract_path = r"D:\Saransh\Softwares\Tesseract-OCR\tesseract.exe"
6+
image_path = "test.png"
7+
file_path = "output.txt"
8+
9+
pytesseract.pytesseract.tesseract_cmd = tesseract_path
10+
11+
img = cv2.imread(image_path)
12+
13+
# extracting the text by using LSTM
14+
text = pytesseract.image_to_string(img, config="-l eng --oem 1")
15+
text = text.replace("-\n", "").replace("\n", " ")
16+
17+
# writing the text
18+
file = open(file_path, "w")
819
file.write(text)
920
file.close()
21+
22+
# adding boxes around the words
23+
boxes = pytesseract.image_to_data(img)
24+
for z, box in enumerate(boxes.splitlines()):
25+
if z != 0:
26+
box = box.split()
27+
28+
# if the data has a word
29+
if len(box) == 12:
30+
31+
x, y = int(box[6]), int(box[7])
32+
h, w = int(box[8]), int(box[9])
33+
34+
cv2.rectangle(img, (x, y), (x + h, y + w), (0, 0, 255), 1)
35+
36+
cv2.imwrite("OCRed.png", img)
37+
cv2.destroyAllWindows()

text_from_image/output.txt

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1 @@
1-
Learning is one of the overcommunicated but underleveraged tools of the
2-
common entrepreneur.
3-
4-
Everyone talks about methods of learning, but few people find realistic and
5-
authentic techniques that actually yield a net profit in the information and
6-
application categories.
7-
8-
Elon Musk has broken through that barrier with learning techniques that
9-
have proven successful not just once, but time and time again.
10-
11-
A good argument could be made that Musk has leveraged his learning by
12-
becoming a disruptor. He and his companies have shifted entire industries,
13-
including the transportation sector, the energy sector, and the space sector.
14-
15-
He recently announced at a press conference that his plans for his biotech
16-
company Neuralink are progressing quite nicely, hinting at yet another
17-
sector which his hands will likely shift in the coming years.
18-
19-
Yes, Musk is a once-in-a-lifetime genius. Likely on the same levels as Nikola
20-
Tesla, Albert Einstein, Isaac Newton. He has a different way of viewing
21-
problems than the average entrepreneur.
22-
1+
Learning is one of the overcommunicated but underleveraged tools of the common entrepreneur. Everyone talks about methods of learning, but few people find realistic and authentic techniques that actually yield a net profit in the information and application categories. Elon Musk has broken through that barrier with learning techniques that have proven successful not just once, but time and time again. A good argument could be made that Musk has leveraged his learning by becoming a disruptor. He and his companies have shifted entire industries, including the transportation sector, the energy sector, and the space sector. He recently announced at a press conference that his plans for his biotech company Neuralink are progressing quite nicely, hinting at yet another sector which his hands will likely shift in the coming years. Yes, Musk is a once-in-a-lifetime genius. Likely on the same levels as Nikola Tesla, Albert Einstein, Isaac Newton. He has a different way of viewing problems than the average entrepreneur.

text_from_image/requirements.txt

4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)