Added python VisionBuf class (#29075)

* Added python VisionBuf class

* fixed property names

* Bump cereal
old-commit-hash: f0ae0c34cd
beeps
Mitchell Goff 2 years ago committed by GitHub
parent d4ec764235
commit 49b07db500
  1. 2
      cereal
  2. 12
      system/camerad/snapshot/snapshot.py
  3. 4
      tools/replay/ui.py

@ -1 +1 @@
Subproject commit aed9fd278a704816aba11f4473aafefc281ed2bc
Subproject commit a9082c826872e5650e8a8e9a6f3e5f95a4d27572

@ -43,10 +43,10 @@ def yuv_to_rgb(y, u, v):
return rgb.astype(np.uint8)
def extract_image(buf, w, h, stride, uv_offset):
y = np.array(buf[:uv_offset], dtype=np.uint8).reshape((-1, stride))[:h, :w]
u = np.array(buf[uv_offset::2], dtype=np.uint8).reshape((-1, stride//2))[:h//2, :w//2]
v = np.array(buf[uv_offset+1::2], dtype=np.uint8).reshape((-1, stride//2))[:h//2, :w//2]
def extract_image(buf):
y = np.array(buf.data[:buf.uv_offset], dtype=np.uint8).reshape((-1, buf.stride))[:buf.height, :buf.width]
u = np.array(buf.data[buf.uv_offset::2], dtype=np.uint8).reshape((-1, buf.stride//2))[:buf.height//2, :buf.width//2]
v = np.array(buf.data[buf.uv_offset+1::2], dtype=np.uint8).reshape((-1, buf.stride//2))[:buf.height//2, :buf.width//2]
return yuv_to_rgb(y, u, v)
@ -67,10 +67,10 @@ def get_snapshots(frame="roadCameraState", front_frame="driverCameraState"):
rear, front = None, None
if frame is not None:
c = vipc_clients[frame]
rear = extract_image(c.recv(), c.width, c.height, c.stride, c.uv_offset)
rear = extract_image(c.recv())
if front_frame is not None:
c = vipc_clients[front_frame]
front = extract_image(c.recv(), c.width, c.height, c.stride, c.uv_offset)
front = extract_image(c.recv())
return rear, front

@ -113,10 +113,10 @@ def ui_thread(addr):
yuv_img_raw = vipc_client.recv()
if yuv_img_raw is None or not yuv_img_raw.any():
if yuv_img_raw is None or not yuv_img_raw.data.any():
continue
imgff = np.frombuffer(yuv_img_raw, dtype=np.uint8).reshape((vipc_client.height * 3 // 2, vipc_client.width))
imgff = np.frombuffer(yuv_img_raw.data, dtype=np.uint8).reshape((vipc_client.height * 3 // 2, vipc_client.width))
num_px = vipc_client.width * vipc_client.height
bgr = cv2.cvtColor(imgff, cv2.COLOR_YUV2RGB_NV12)

Loading…
Cancel
Save