Omnibus commited on
Commit
704d03b
1 Parent(s): 234ba0c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -4
app.py CHANGED
@@ -1,14 +1,38 @@
1
  import gradio as gr
2
  import zxingcpp
 
 
3
  import cv2
4
 
5
  def decode(im):
6
  img = cv2.imread(f'{im}')
7
- results = zxingcpp.read_barcodes(img)
8
-
9
- print (results[0].text)
10
- return results[0].text
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
 
13
 
14
  with gr.Blocks() as app:
 
1
  import gradio as gr
2
  import zxingcpp
3
+ from PIL import Image
4
+
5
  import cv2
6
 
7
  def decode(im):
8
  img = cv2.imread(f'{im}')
9
+ try:
10
+ results = zxingcpp.read_barcodes(img)
11
+ return results[0].text
12
+ except Exception:
13
+ return "QR Code not Detected \nTry using 'Detect by Color'"
14
 
15
+ def detect_color(im,col):
16
+ #qr_img=Image.open(im).convert("RGBA")
17
+ qr_img=Image.open(im)
18
+ datas = qr_img.getdata()
19
+ newData = []
20
+ h1 = col.strip("#")
21
+ rgb_tup = tuple(int(h1[i:i+2], 16) for i in (0, 2, 4))
22
+ for item in datas:
23
+ if item[0] == rgb_tup[0] and item[1] == rgb_tup[1] and item[2] == rgb_tup[2]:
24
+ newData.append((0,0,0))
25
+ else:
26
+ newData.append(255,255,255)
27
+ qr_img.putdata(newData)
28
+ qr_img.save(f'conv_im.png')
29
+ img = cv2.imread('conv_im.png')
30
+ try:
31
+ results = zxingcpp.read_barcodes(img)
32
+ return results[0].text
33
+ except Exception:
34
+ return "QR Code not Detected \nTry using 'Detect by Color'"
35
+
36
 
37
 
38
  with gr.Blocks() as app: