-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathscan_info.py
More file actions
31 lines (26 loc) · 952 Bytes
/
scan_info.py
File metadata and controls
31 lines (26 loc) · 952 Bytes
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
from imutils.perspective import four_point_transform
import pytesseract
import argparse
import imutils
import cv2
import re
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
help="path to input receipt image")
ap.add_argument("-d", "--debug", type=int, default=-1,
help="whether or not we are visualizing each step of the pipeline")
args = vars(ap.parse_args())
## RUNNING RECEIPT DETECTION + CROPPING SCRIPT
orig = cv2.imread(args["image"])
image = orig.copy()
image = imutils.resize(image, width=500)
ratio = orig.shape[1] / float(image.shape[1])
exec(open("receipt_img_seg.py").read(), {'arg1': "-i image"})
receipt_scan = cv2.imread("result.png")
receipt = four_point_transform(orig, receipt_scan.reshape(4, 2) * ratio)
options = "--psm 4"
text = pytesseract.image_to_string(cv2.cvtColor(receipt, cv2.COLOR_BGR2RGB), config=options)
print("[INFO] raw output:")
print("==================")
print(text)
print("\n")