From 89c5a7584ac4e1a52e0b971a2d9fe3be3bef5809 Mon Sep 17 00:00:00 2001 From: WU Jia <35290826+kaingwade@users.noreply.github.com> Date: Mon, 24 Apr 2023 17:12:01 +0800 Subject: [PATCH] Merge pull request #23531 from kaingwade:orbbec_python_sample Add python sample of how to use Orbbec camera. #23531 ### Pull Request Readiness Checklist See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request - [x] I agree to contribute to the project under Apache 2 License. - [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV - [x] The PR is proposed to the proper branch - [ ] There is a reference to the original bug report and related work - [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable Patch to opencv_extra has the same branch name. - [ ] The feature is well documented and sample code can be built with the project CMake --- samples/python/videocapture_obsensor.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 samples/python/videocapture_obsensor.py diff --git a/samples/python/videocapture_obsensor.py b/samples/python/videocapture_obsensor.py new file mode 100644 index 0000000000..f63e899473 --- /dev/null +++ b/samples/python/videocapture_obsensor.py @@ -0,0 +1,38 @@ +#!/usr/bin/env python + +import numpy as np +import sys +import cv2 as cv + + +def main(): + # Open Orbbec depth sensor + orbbec_cap = cv.VideoCapture(0, cv.CAP_OBSENSOR) + if orbbec_cap.isOpened() == False: + sys.exit("Fail to open camera.") + + while True: + # Grab data from the camera + if orbbec_cap.grab(): + # RGB data + ret_bgr, bgr_image = orbbec_cap.retrieve(None, cv.CAP_OBSENSOR_BGR_IMAGE) + if ret_bgr: + cv.imshow("BGR", bgr_image) + + # depth data + ret_depth, depth_map = orbbec_cap.retrieve(None, cv.CAP_OBSENSOR_DEPTH_MAP) + if ret_depth: + color_depth_map = cv.normalize(depth_map, None, 0, 255, cv.NORM_MINMAX, cv.CV_8UC1) + color_depth_map = cv.applyColorMap(color_depth_map, cv.COLORMAP_JET) + cv.imshow("DEPTH", color_depth_map) + else: + print("Fail to grab data from the camera.") + + if cv.pollKey() >= 0: + break + + orbbec_cap.release() + + +if __name__ == '__main__': + main()