jayllfpt commited on
Commit
daa904a
·
1 Parent(s): d44e0e7

Revert "update source"

Browse files

This reverts commit d44e0e76290fd1b543e0ebabd8a7a177a12b9257.

Files changed (1) hide show
  1. app.py +14 -20
app.py CHANGED
@@ -34,7 +34,7 @@ def transform_image(image, box):
34
 
35
  img_height, img_width = dst_img.shape[0:2]
36
  if img_height/img_width >= 1.25:
37
- dst_img = np.rot90(dst_img, k=3)
38
 
39
  return dst_img
40
 
@@ -44,36 +44,30 @@ def main():
44
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
45
 
46
  if uploaded_file is not None:
47
- # Create two columns
48
- col1, col2 = st.columns(2)
49
-
50
- # Display the uploaded image in the left column
51
- with col1:
52
- st.header("Uploaded Image")
53
- file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
54
- org_image = cv2.imdecode(file_bytes, 1)
55
- st.image(org_image, channels="BGR", caption='Uploaded Image')
56
 
57
  images = []
58
  start = time.perf_counter()
59
  boxes = box_engine(org_image)
60
  processing_time = time.perf_counter() - start
 
61
 
62
- for box in boxes:
63
  org_image = cv2.polylines(org_image, [box.astype(np.int32)], isClosed=True, color=(0, 255, 0), thickness=2)
64
  image = transform_image(org_image, box)
65
  images.append(image)
66
 
67
- texts = text_engine(images)
 
 
68
 
69
- # Display the result in the right column
70
- with col2:
71
- st.header("Detected Text Boxes and Extracted Text")
72
- output_image = Image.fromarray(cv2.cvtColor(org_image, cv2.COLOR_BGR2RGB))
73
- st.image(output_image, caption='Detected Text Boxes', use_column_width=True)
74
- st.write(f"Processing time: {processing_time:.2f} seconds")
75
- st.write("Extracted Texts:")
76
- st.write(texts)
77
 
78
  if __name__ == '__main__':
79
  main()
 
34
 
35
  img_height, img_width = dst_img.shape[0:2]
36
  if img_height/img_width >= 1.25:
37
+ dst_img = np.rot90(dst_img, k=3)
38
 
39
  return dst_img
40
 
 
44
  uploaded_file = st.file_uploader("Choose an image...", type=["jpg", "jpeg", "png"])
45
 
46
  if uploaded_file is not None:
47
+ # Convert the uploaded file to an OpenCV image
48
+ file_bytes = np.asarray(bytearray(uploaded_file.read()), dtype=np.uint8)
49
+ org_image = cv2.imdecode(file_bytes, 1)
50
+ st.image(org_image, channels="BGR", caption='Uploaded Image')
 
 
 
 
 
51
 
52
  images = []
53
  start = time.perf_counter()
54
  boxes = box_engine(org_image)
55
  processing_time = time.perf_counter() - start
56
+ st.write(f"Box detection took {processing_time:.2f} seconds.")
57
 
58
+ for box in boxes[::-1]:
59
  org_image = cv2.polylines(org_image, [box.astype(np.int32)], isClosed=True, color=(0, 255, 0), thickness=2)
60
  image = transform_image(org_image, box)
61
  images.append(image)
62
 
63
+ # Convert back to PIL Image for displaying
64
+ output_image = Image.fromarray(cv2.cvtColor(org_image, cv2.COLOR_BGR2RGB))
65
+ st.image(output_image, caption='Detected Text Boxes', use_column_width=True)
66
 
67
+ texts = text_engine(images)
68
+
69
+ st.write("Extracted Texts:")
70
+ st.write(texts)
 
 
 
 
71
 
72
  if __name__ == '__main__':
73
  main()