MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / encode_jpeg

Function encode_jpeg

examples/Camera Telemetry/camera_telemetry.py:161–172  ·  view source on GitHub ↗

Encode a BGR frame as JPEG bytes, downscaling if needed.

(frame_bgr, quality)

Source from the content-addressed store, hash-verified

159
160
161def encode_jpeg(frame_bgr, quality):
162 """Encode a BGR frame as JPEG bytes, downscaling if needed."""
163 h, w = frame_bgr.shape[:2]
164 if w > MAX_FRAME_WIDTH:
165 scale = MAX_FRAME_WIDTH / w
166 frame_bgr = cv2.resize(
167 frame_bgr, (MAX_FRAME_WIDTH, int(h * scale)), interpolation=cv2.INTER_LINEAR
168 )
169 ok, buf = cv2.imencode(".jpg", frame_bgr, [cv2.IMWRITE_JPEG_QUALITY, quality])
170 if not ok:
171 return None
172 return bytes(buf)
173
174
175def main():

Callers 1

mainFunction · 0.70

Calls 1

resizeMethod · 0.45

Tested by

no test coverage detected