justin2341 commited on
Commit
bad2de3
·
verified ·
1 Parent(s): 648270d

Update demo.py

Browse files
Files changed (1) hide show
  1. demo.py +44 -31
demo.py CHANGED
@@ -5,40 +5,53 @@ import io
5
  import cv2
6
  import numpy as np
7
 
8
- palmprint_count = 0
9
-
10
- def compare_palmprint(frame1, frame2):
11
- global palmprint_count
 
 
 
 
 
 
 
 
 
 
12
 
13
- palmprint_count = palmprint_count + 1
14
-
15
- url = "http://127.0.0.1:8080/compare_palmprint"
16
- files = {'file1': open(frame1, 'rb'), 'file2': open(frame2, 'rb')}
17
-
18
- r = requests.post(url=url, files=files)
19
-
20
- html = None
21
-
22
- compare_result = r.json().get('compare_result')
23
- compare_similarity = r.json().get('compare_similarity')
24
-
25
- html = ("<table>"
26
- "<tr>"
27
- "<th>Compare Result</th>"
28
- "<th>Value</th>"
29
- "</tr>"
30
- "<tr>"
31
- "<td>Result</td>"
32
- "<td>{compare_result}</td>"
33
- "</tr>"
34
- "<tr>"
35
- "<td>Similarity</td>"
36
- "<td>{compare_similarity}</td>"
37
- "</tr>"
38
- "</table>".format(compare_result=compare_result, compare_similarity=compare_similarity))
39
 
40
- return [html]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
 
 
42
  with gr.Blocks() as demo:
43
  gr.Markdown(
44
  """
 
5
  import cv2
6
  import numpy as np
7
 
8
+ alpr_count = 0
9
+ def plot_one_box(x, img, color=None, label=None, line_thickness=3):
10
+ # Plots one bounding box on image img
11
+ tl = line_thickness or round(0.002 * (img.shape[0] + img.shape[1]) / 2) + 1 # line/font thickness
12
+ color = color
13
+ c1, c2 = (int(x[0]), int(x[1])), (int(x[2]), int(x[3]))
14
+ cv2.rectangle(img, c1, c2, color, thickness=tl, lineType=cv2.LINE_AA)
15
+ if label:
16
+ tf = max(tl - 1, 1) # font thickness
17
+ t_size = cv2.getTextSize(label, 0, fontScale=tl / 3, thickness=tf)[0]
18
+ c2 = c1[0] + t_size[0], c1[1] - t_size[1] - 3
19
+ cv2.rectangle(img, c1, c2, color, -1, cv2.LINE_AA) # filled
20
+ cv2.putText(img, label, (c1[0], c1[1] - 2), 0, tl / 3, [0, 0, 0], thickness=tf, lineType=cv2.LINE_AA)
21
+ return img
22
 
23
+ def alpr(frame):
24
+ global alpr_count
25
+
26
+ alpr_count = alpr_count + 1
27
+ print("alpr_count", alpr_count)
28
+ url = "http://127.0.0.1:8080/alpr"
29
+ file = {'file': open(frame, 'rb')}
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
30
 
31
+ r = requests.post(url=url, files=file)
32
+
33
+ alpr_output = None
34
+ result = r.json().get('result')
35
+ plate_number = r.json().get('plate number')
36
+ box = r.json().get('coordinate')
37
+ try:
38
+ image = cv2.imread(frame, cv2.IMREAD_COLOR)
39
+ if image is None:
40
+ print('image is null')
41
+ sys.exit()
42
+ image = cv2.resize(image, (1024, 640))
43
+ for alpr in plate_number:
44
+ print(plate_number)
45
+ # image = plot_one_box(alpr.get('recog_boxes'), image, label=alpr.get('recog_results'), color=[0, 255, 0], line_thickness=1)
46
+ image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
47
+
48
+ alpr_output = image.copy()
49
+
50
+ except:
51
+ pass
52
 
53
+ return alpr_output
54
+
55
  with gr.Blocks() as demo:
56
  gr.Markdown(
57
  """