(frame: Any)
| 110 | |
| 111 | |
| 112 | def frame_to_bgr(frame: Any) -> np.ndarray: |
| 113 | ob = _ob() |
| 114 | width = int(frame.get_width()) |
| 115 | height = int(frame.get_height()) |
| 116 | color_format = frame.get_format() |
| 117 | data = np.asanyarray(frame.get_data()) |
| 118 | |
| 119 | if color_format == ob.OBFormat.RGB: |
| 120 | return cv2.cvtColor(_reshape_color(data, height, width, 3), cv2.COLOR_RGB2BGR) |
| 121 | if color_format == ob.OBFormat.BGR: |
| 122 | return _reshape_color(data, height, width, 3).copy() |
| 123 | if color_format == ob.OBFormat.RGBA: |
| 124 | return cv2.cvtColor(_reshape_color(data, height, width, 4), cv2.COLOR_RGBA2BGR) |
| 125 | if color_format == ob.OBFormat.BGRA: |
| 126 | return cv2.cvtColor(_reshape_color(data, height, width, 4), cv2.COLOR_BGRA2BGR) |
| 127 | if color_format == ob.OBFormat.MJPG: |
| 128 | image = cv2.imdecode(data, cv2.IMREAD_COLOR) |
| 129 | if image is None: |
| 130 | raise RuntimeError("Failed to decode Orbbec MJPG color frame") |
| 131 | return image |
| 132 | if color_format == ob.OBFormat.YUYV: |
| 133 | return cv2.cvtColor(_reshape_color(data, height, width, 2), cv2.COLOR_YUV2BGR_YUY2) |
| 134 | if color_format == ob.OBFormat.UYVY: |
| 135 | return cv2.cvtColor(_reshape_color(data, height, width, 2), cv2.COLOR_YUV2BGR_UYVY) |
| 136 | if color_format == ob.OBFormat.NV12: |
| 137 | return cv2.cvtColor(data.reshape(height * 3 // 2, width), cv2.COLOR_YUV2BGR_NV12) |
| 138 | if color_format == ob.OBFormat.NV21: |
| 139 | return cv2.cvtColor(data.reshape(height * 3 // 2, width), cv2.COLOR_YUV2BGR_NV21) |
| 140 | if color_format == ob.OBFormat.I420: |
| 141 | return cv2.cvtColor(data.reshape(height * 3 // 2, width), cv2.COLOR_YUV2BGR_I420) |
| 142 | raise RuntimeError(f"Unsupported Orbbec color format: {color_format}") |
| 143 | |
| 144 | |
| 145 | class OrbbecCamera(RgbdCamera): |
no test coverage detected