DanielFD commited on
Commit
7624331
·
1 Parent(s): af25ad9

Upload 2 files

Browse files
Files changed (1) hide show
  1. app.py +11 -7
app.py CHANGED
@@ -4,27 +4,31 @@ from io import BytesIO
4
  import base64
5
  import matplotlib.image as mpimg
6
  import cv2
 
 
 
 
 
 
 
7
 
8
  def string_to_img(base64_string):
 
9
  imgdata = base64.b64decode(base64_string + '==')
10
  im = BytesIO(imgdata)
11
  img = mpimg.imread(im, format='PNG')
12
  opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
13
  return opencv_img
14
 
15
- def img_to_string(img):
16
- _, encoded_img = cv2.imencode('.PNG', img)
17
- base64_string = base64.b64encode(encoded_img).decode('utf-8')
18
- return base64_string
19
-
20
  def api_image_processing(image):
21
  # API Endpoint
22
- url = "http://18.132.59.76/fmc_api"
23
  # Step 1
24
  b64_string = img_to_string(image)
25
  # Step 2
26
  payload ={"base64_string": b64_string}
27
- base64_string_resp = requests.post(url=url, data=payload)
 
28
  # Step 3
29
  img_output = string_to_img(base64_string_resp)
30
  # Return processed image
 
4
  import base64
5
  import matplotlib.image as mpimg
6
  import cv2
7
+ import numpy as np
8
+
9
+ def img_to_string(img):
10
+ # Encodes an image into a base64_string
11
+ _, encoded_img = cv2.imencode('.PNG', img)
12
+ base64_string = base64.b64encode(encoded_img).decode('utf-8')
13
+ return base64_string
14
 
15
  def string_to_img(base64_string):
16
+ # Decodes a base64_string into an image
17
  imgdata = base64.b64decode(base64_string + '==')
18
  im = BytesIO(imgdata)
19
  img = mpimg.imread(im, format='PNG')
20
  opencv_img= cv2.cvtColor(np.array(img), cv2.COLOR_BGR2RGB)
21
  return opencv_img
22
 
 
 
 
 
 
23
  def api_image_processing(image):
24
  # API Endpoint
25
+ url = "http://13.42.31.235/fmc_api"
26
  # Step 1
27
  b64_string = img_to_string(image)
28
  # Step 2
29
  payload ={"base64_string": b64_string}
30
+ response = requests.post(url=url, data=payload)
31
+ base64_string_resp = response.json()['message']
32
  # Step 3
33
  img_output = string_to_img(base64_string_resp)
34
  # Return processed image