Added python VisionBuf class (#29075)

* Added python VisionBuf class

* fixed property names

* Bump cereal
This commit is contained in:
Mitchell Goff
2023-07-25 01:08:39 -07:00
committed by GitHub
parent 0dd1dcc7d0
commit f0ae0c34cd
3 changed files with 9 additions and 9 deletions

2
cereal

Submodule cereal updated: aed9fd278a...a9082c8268

View File

@@ -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

View File

@@ -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)