Browse Source

Add pyorbeck into dora node hub

tags/v0.3.7rc2
haixuanTao 1 year ago
parent
commit
674ee0323d
5 changed files with 122 additions and 0 deletions
  1. +3
    -0
      node-hub/dora-pyorbbecksdk/README.md
  2. +11
    -0
      node-hub/dora-pyorbbecksdk/dora_pyorbbecksdk/__init__.py
  3. +77
    -0
      node-hub/dora-pyorbbecksdk/dora_pyorbbecksdk/main.py
  4. +20
    -0
      node-hub/dora-pyorbbecksdk/pyproject.toml
  5. +11
    -0
      node-hub/dora-pyorbbecksdk/tests/test_pyorbbecksdk.py

+ 3
- 0
node-hub/dora-pyorbbecksdk/README.md View File

@@ -0,0 +1,3 @@
# Dora Node to communicate with Pyorbbecksdk

Please follow the installation instruction in: https://github.com/orbbec/pyorbbecsdk

+ 11
- 0
node-hub/dora-pyorbbecksdk/dora_pyorbbecksdk/__init__.py View File

@@ -0,0 +1,11 @@
import os

# Define the path to the README file relative to the package directory
readme_path = os.path.join(os.path.dirname(os.path.dirname(__file__)), "README.md")

# Read the content of the README file
try:
with open(readme_path, "r", encoding="utf-8") as f:
__doc__ = f.read()
except FileNotFoundError:
__doc__ = "README file not found."

+ 77
- 0
node-hub/dora-pyorbbecksdk/dora_pyorbbecksdk/main.py View File

@@ -0,0 +1,77 @@
# ******************************************************************************
# Copyright (c) 2023 Orbbec 3D Technology, Inc
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http:# www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ******************************************************************************
import cv2
import os
from pyorbbecsdk import Context
from pyorbbecsdk import Config
from pyorbbecsdk import OBError
from pyorbbecsdk import OBSensorType, OBFormat
from pyorbbecsdk import Pipeline, FrameSet
from pyorbbecsdk import VideoStreamProfile
from utils import frame_to_bgr_image
from dora import Node
import pyarrow as pa

ESC_KEY = 27

DEVICE_INDEX = os.getenv("DEVICE_INDEX", 0)


def main():
node = Node()
config = Config()
ctx = Context()
device_list = ctx.query_devices()
device = device_list.get_device_by_index(int(DEVICE_INDEX))
pipeline = Pipeline(device)
try:
profile_list = pipeline.get_stream_profile_list(OBSensorType.COLOR_SENSOR)
try:
color_profile: VideoStreamProfile = profile_list.get_video_stream_profile(
640, 0, OBFormat.RGB, 30
)
except OBError as e:
print(e)
color_profile = profile_list.get_default_video_stream_profile()
print("color profile: ", color_profile)
config.enable_stream(color_profile)
except Exception as e:
print(e)
return
pipeline.start(config)
for event in node:
try:
frames: FrameSet = pipeline.wait_for_frames(100)
if frames is None:
continue
color_frame = frames.get_color_frame()
if color_frame is None:
continue
# covert to RGB format
color_image = frame_to_bgr_image(color_frame)
if color_image is None:
print("failed to convert frame to image")
continue
ret, frame = cv2.imencode("." + "jpeg", color_image)
if ret:
node.send_output("image", pa.array(frame), {"encoding": "jpeg"})
except KeyboardInterrupt:
break
pipeline.stop()


if __name__ == "__main__":
main()

+ 20
- 0
node-hub/dora-pyorbbecksdk/pyproject.toml View File

@@ -0,0 +1,20 @@
[tool.poetry]
name = "dora-pyorbbecksdk"
version = "0.3.6"
authors = ["Haixuan Xavier Tao <tao.xavier@outlook.com>"]
description = "Dora Node for capturing video with PyOrbbeck SDK"
readme = "README.md"

packages = [{ include = "dora_pyorbbecksdk" }]

[tool.poetry.dependencies]
dora-rs = "^0.3.6"
python = "^3.7"


[tool.poetry.scripts]
dora-pyorbbecksdk = "dora_pyorbbecksdk"

[build-system]
requires = ["poetry-core>=1.8.0"]
build-backend = "poetry.core.masonry.api"

+ 11
- 0
node-hub/dora-pyorbbecksdk/tests/test_pyorbbecksdk.py View File

@@ -0,0 +1,11 @@
import pytest


def test_import_main():
# from opencv_video_capture.main import main
pass
# skip test as pyorbbecksdk installation is a bit complicated

# Check that everything is working, and catch dora Runtime Exception as we're not running in a dora dataflow.
# with pytest.raises(RuntimeError):
# main()

Loading…
Cancel
Save