Convert the input frame to BGR color space if needed. Args: frame: The input frame (as NumPy array) to be converted. Returns: frame: The converted frame in BGR color space.
(self, frame)
| 441 | return frame |
| 442 | |
| 443 | def __convertToBGR(self, frame): |
| 444 | """ |
| 445 | Convert the input frame to BGR color space if needed. |
| 446 | |
| 447 | Args: |
| 448 | frame: The input frame (as NumPy array) to be converted. |
| 449 | Returns: |
| 450 | frame: The converted frame in BGR color space. |
| 451 | """ |
| 452 | if self.frame_color == self.RGB888: |
| 453 | # Convert RGB to BGR |
| 454 | logger.debug(f"__convertToBGR: converting frame from RGB to BGR") |
| 455 | frame = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR) |
| 456 | elif self.frame_color == self.GRAYSCALE8: |
| 457 | # Convert Grayscale to BGR |
| 458 | logger.debug(f"__convertToBGR: converting frame from Grayscale to BGR") |
| 459 | frame = cv2.cvtColor(frame, cv2.COLOR_GRAY2BGR) |
| 460 | elif self.frame_color == self.BGR565: |
| 461 | # Convert BGR565 to BGR |
| 462 | logger.debug(f"__convertToBGR: converting frame from BGR565 to BGR") |
| 463 | frame = cv2.cvtColor(frame, cv2.COLOR_BGR5652BGR) |
| 464 | elif self.frame_color == self.YUV420: |
| 465 | # Convert YUV420 to BGR |
| 466 | logger.debug(f"__convertToBGR: converting frame from YUV420 to BGR") |
| 467 | frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420) |
| 468 | elif self.frame_color == self.NV12: |
| 469 | # Convert NV12 to BGR |
| 470 | logger.debug(f"__convertToBGR: converting frame from NV12 to BGR") |
| 471 | frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV12) |
| 472 | elif self.frame_color == self.NV21: |
| 473 | # Convert NV21 to BGR |
| 474 | logger.debug(f"__convertToBGR: converting frame from NV21 to BGR") |
| 475 | frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_NV21) |
| 476 | |
| 477 | return frame |
| 478 | |
| 479 | def __convertFromBGR(self, frame): |
| 480 | """ |