Muhammad Usman Nazir commited on
Commit
318a4d2
·
1 Parent(s): 66f795f

fix: change image encoding from RGBA to JPEG for improved performance and reduced size

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -959,9 +959,9 @@ def build_segmentation_bundle(contents: bytes):
959
  print(f"[TIMING] Floor segmentation took {time.perf_counter() - t0:.3f} seconds", flush=True)
960
 
961
  t0 = time.perf_counter()
962
- rgba = np.dstack([img_np, np.full((h, w), 255, dtype=np.uint8)])
963
- pixels_b64 = base64.b64encode(rgba.tobytes()).decode()
964
- print(f"[TIMING] Image RGBA encoding took {time.perf_counter() - t0:.3f} seconds", flush=True)
965
 
966
  t0 = time.perf_counter()
967
  primary_floor_ids = class_ids(PRIMARY_FLOOR_CLASSES)
 
959
  print(f"[TIMING] Floor segmentation took {time.perf_counter() - t0:.3f} seconds", flush=True)
960
 
961
  t0 = time.perf_counter()
962
+ success, jpeg_buf = cv2.imencode(".jpg", cv2.cvtColor(img_np, cv2.COLOR_RGB2BGR), [cv2.IMWRITE_JPEG_QUALITY, 90])
963
+ pixels_b64 = base64.b64encode(jpeg_buf.tobytes()).decode()
964
+ print(f"[TIMING] Image JPEG encoding took {time.perf_counter() - t0:.3f} seconds", flush=True)
965
 
966
  t0 = time.perf_counter()
967
  primary_floor_ids = class_ids(PRIMARY_FLOOR_CLASSES)