奥比中光大白DaBai DCW pytho windows调试记录
参考论坛编译https://vcp.developer.orbbec.com.cn/documentation
获得pyorbbecsdk,此处有一个大坑,如下图:
要将lib文件夹下的所有文件都拷到examples目录下,如下图:
然后可以运行所有的python程序了,由于大白不支持帧同步,所以对于D2C功能修改后的代码如下:
import argparse
import sys
import cv2
import numpy as np
from pyorbbecsdk import *
from utils import frame_to_bgr_image
ESC_KEY = 27
def main(argv):
pipeline = Pipeline()
device = pipeline.get_device()
device_info = device.get_device_info()
device_pid = device_info.get_pid()
config = Config()
parser = argparse.ArgumentParser()
parser.add_argument("-m", "--mode",
help="align mode, HW=hardware mode,SW=software mode,NONE=disable align",
type=str, default='HW')
args = parser.parse_args()
align_mode = args.mode
try:
profile_list = pipeline.get_stream_profile_list(OBSensorType.COLOR_SENSOR)
color_profile = profile_list.get_default_video_stream_profile()
config.enable_stream(color_profile)
profile_list = pipeline.get_stream_profile_list(OBSensorType.DEPTH_SENSOR)
assert profile_list is not None
depth_profile = profile_list.get_default_video_stream_profile()
assert depth_profile is not None
print("color profile : {}x{}@{}_{}".format(color_profile.get_width(),
color_profile.get_height(),
color_profile.get_fps(),
color_profile.get_format()))
print("depth profile : {}x{}@{}_{}".format(depth_profile.get_width(),
depth_profile.get_height(),
depth_profile.get_fps(),
depth_profile.get_format()))
config.enable_stream(depth_profile)
except Exception as e:
print(e)
return
if align_mode == 'HW':
if device_pid == 0x066B:
# Femto Mega does not support hardware D2C, and it is changed to software D2C
config.set_align_mode(OBAlignMode.SW_MODE)
else:
config.set_align_mode(OBAlignMode.HW_MODE)
elif align_mode == 'SW':
config.set_align_mode(OBAlignMode.SW_MODE)
else:
config.set_align_mode(OBAlignMode.DISABLE)
try:
pipeline.start(config)
except Exception as e:
print(e)
return
while True:
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
# Convert to RGB format
color_image = frame_to_bgr_image(color_frame)
if color_image is None:
print("Failed to convert frame to image")
continue
depth_frame = frames.get_depth_frame()
if depth_frame is None:
continue
width = depth_frame.get_width()
height = depth_frame.get_height()
scale = depth_frame.get_depth_scale()
depth_data = np.frombuffer(depth_frame.get_data(), dtype=np.uint16)
depth_data = depth_data.reshape((height, width))
depth_data = depth_data.astype(np.float32) * scale
depth_image = cv2.normalize(depth_data, None, 0, 255, cv2.NORM_MINMAX, dtype=cv2.CV_8U)
depth_image = cv2.applyColorMap(depth_image, cv2.COLORMAP_JET)
# Overlay color image on depth image
depth_image = cv2.addWeighted(color_image, 0.5, depth_image, 0.5, 0)
cv2.imshow("SyncAlignViewer", depth_image)
key = cv2.waitKey(1)
if key == ord('q') or key == ESC_KEY:
cv2.destroyAllWindows()
break
except KeyboardInterrupt:
break
pipeline.stop()
if __name__ == "__main__":
print("Please NOTE: This example is NOT supported by the Gemini 330 series.")
print("If you want to see the example on Gemini 330 series, please refer to align_filter_viewer.py")
main(sys.argv[1:])