-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebapp.py
106 lines (78 loc) · 2.99 KB
/
webapp.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import streamlit as st
import cv2
from PIL import Image
import numpy as np
import pytesseract
languages_url = "https://github.com/tesseract-ocr/tessdata"
psm_mode = "11"
language = "eng"
def image_detect_barcodes(our_image):
barcodes = ""
print(psm_mode)
tesseract_config = r"--psm " + psm_mode + " --oem 3"
text = pytesseract.image_to_string(our_image,config=tesseract_config,lang=language)
barcodes = text
return [our_image,barcodes]
def realtime_video_detect_barcodes():
pass
def main():
"""Barcode Recognition App"""
st.title("Ywmaa's Inventions : Barcode Invention 0.2")
st.sidebar.title('BI 0.2 Sidebar')
html_temp = """
<body style="background-color:red;">
<div style="background-color:teal ;padding:10px">
<h2 style="color:white;text-align:center;">Barcode Recognition WebApp</h2>
</div>
</body>
"""
st.markdown(html_temp, unsafe_allow_html=True)
app_mode = st.sidebar.selectbox('Choose the App mode',
['Run on Image','Run on Video','About App']
)
psm_text = st.sidebar.selectbox('Page segmentation modes',
[
'0 Orientation and script detection (OSD) only.',
'1 Automatic page segmentation with OSD.',
'2 Automatic page segmentation, but no OSD, or OCR. (not implemented)',
'3 Fully automatic page segmentation, but no OSD. (Default)',
'4 Assume a single column of text of variable sizes.',
'5 Assume a single uniform block of vertically aligned text.',
'6 Assume a single uniform block of text.',
'7 Treat the image as a single text line.',
'8 Treat the image as a single word.',
'9 Treat the image as a single word in a circle.',
'10 Treat the image as a single character.',
'11 Sparse text. Find as much text as possible in no particular order.',
'12 Sparse text with OSD.',
'13 Raw line. Treat the image as a single text line',
]
)
global psm_mode
psm_mode = (psm_text[0] + psm_text[1]).strip()
global language
language = st.sidebar.selectbox('Choose the Language mode',
['eng','ara']
)
if app_mode == 'Run on Video':
pass
if app_mode == 'Run on Image':
image_file = st.file_uploader("Upload Image", type=['jpg', 'png', 'jpeg'])
if image_file is not None:
our_image = Image.open(image_file)
st.text("Original Image")
st.image(our_image)
if st.button("Recognise"):
result_img= image_detect_barcodes(our_image)
st.image(result_img[0])
st.text("Barcodes : ")
st.text(result_img[1])
if app_mode == 'About App':
st.markdown('''
# About Me \n
Made By : ywmaa \n
Contact :
'''
, unsafe_allow_html=True)
if __name__ == '__main__':
main()