Remove raw depth map compression logic
Browse filesEliminated the depth map quantization, PNG encoding, and Base64 conversion. Simplifies the depth map handling to return only normalized results. Removed unused `cv2` import as it's no longer required.
- handler.py +2 -13
handler.py
CHANGED
|
@@ -7,7 +7,7 @@ import matplotlib.pyplot as plt
|
|
| 7 |
from PIL import Image
|
| 8 |
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
|
| 9 |
import numpy as np
|
| 10 |
-
|
| 11 |
|
| 12 |
|
| 13 |
class EndpointHandler:
|
|
@@ -107,18 +107,7 @@ class EndpointHandler:
|
|
| 107 |
"format": "base64_png"
|
| 108 |
}
|
| 109 |
else:
|
| 110 |
-
|
| 111 |
-
# Quantize and compress the depth map for efficient transmission
|
| 112 |
-
depth_16bit = np.clip(depth_map, 0, 10) * 6553.5 # assuming 0–10m range
|
| 113 |
-
depth_16bit = depth_16bit.astype(np.uint16)
|
| 114 |
-
|
| 115 |
-
# Encode as PNG in memory
|
| 116 |
-
success, buffer = cv2.imencode('.png', depth_16bit)
|
| 117 |
-
if not success:
|
| 118 |
-
raise RuntimeError("Failed to encode depth map as PNG")
|
| 119 |
-
|
| 120 |
-
# Base64 encode the PNG for transmission
|
| 121 |
-
compressed_depth_base64 = base64.b64encode(buffer).decode('utf-8')
|
| 122 |
|
| 123 |
result = {
|
| 124 |
# "depth": normalized_depth.tolist(),
|
|
|
|
| 7 |
from PIL import Image
|
| 8 |
from transformers import AutoImageProcessor, AutoModelForDepthEstimation
|
| 9 |
import numpy as np
|
| 10 |
+
|
| 11 |
|
| 12 |
|
| 13 |
class EndpointHandler:
|
|
|
|
| 107 |
"format": "base64_png"
|
| 108 |
}
|
| 109 |
else:
|
| 110 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
result = {
|
| 113 |
# "depth": normalized_depth.tolist(),
|