UPDATE Vision 更新图像漾SDK,补充彩色图与深度图对齐方式
This commit is contained in:
@ -11,8 +11,11 @@
|
||||
import numpy as np
|
||||
import cv2
|
||||
import open3d as o3d
|
||||
import time
|
||||
import os
|
||||
|
||||
from Vision.tool.CameraRVC import camera_rvc
|
||||
from Vision.tool.CameraPe import camera_pe
|
||||
from Vision.tool.CameraPe_color2depth import camera_pe
|
||||
from Vision.yolo.yolov8_pt_seg import yolov8_segment
|
||||
from Vision.yolo.yolov8_openvino import yolov8_segment_openvino
|
||||
from Vision.tool.utils import find_position
|
||||
@ -21,8 +24,7 @@ from Vision.tool.utils import get_disk_space
|
||||
from Vision.tool.utils import remove_nan_mean_value
|
||||
from Vision.tool.utils import out_bounds_dete
|
||||
from Vision.tool.utils import uv_to_XY
|
||||
import time
|
||||
import os
|
||||
|
||||
|
||||
class Detection:
|
||||
|
||||
@ -43,7 +45,7 @@ class Detection:
|
||||
self.seg_distance_threshold = 10 # 1厘米
|
||||
elif self.cameraType == 'Pe':
|
||||
self.camera_rvc = camera_pe()
|
||||
self.seg_distance_threshold = 10 # 2厘米
|
||||
self.seg_distance_threshold = 15 # 2厘米
|
||||
else:
|
||||
print('相机参数错误')
|
||||
return
|
||||
@ -64,7 +66,7 @@ class Detection:
|
||||
self.model = yolov8_segment_openvino(model_path, device, conf_thres=0.3, iou_thres=0.3)
|
||||
|
||||
|
||||
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 50, width_reduce = 50):
|
||||
def get_position(self, Point_isVision=False, Box_isPoint=True, First_Depth =True, Iter_Max_Pixel = 30, save_img_point=0, Height_reduce = 60, width_reduce = 100):
|
||||
"""
|
||||
检测料袋相关信息
|
||||
:param Point_isVision: 点云可视化
|
||||
@ -81,7 +83,7 @@ class Detection:
|
||||
:return box_list: list 内缩检测框四顶点,形如[[x1,y1],[],[],[]]
|
||||
|
||||
"""
|
||||
ret, img, pm = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
||||
ret, img, pm, _depth_align = self.camera_rvc.get_img_and_point_map() # 拍照,获取图像及
|
||||
if self.camera_rvc.caminit_isok == True:
|
||||
if ret == 1:
|
||||
if save_img_point != 0:
|
||||
|
||||
171
Vision/tool/CameraPe_color2depth.py
Normal file
171
Vision/tool/CameraPe_color2depth.py
Normal file
@ -0,0 +1,171 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
# @Time : 2024/9/19 16:08
|
||||
# @Author : hjw
|
||||
# @File : CameraPe.py
|
||||
'''
|
||||
from Vision.tool.tuyang import pcammls
|
||||
from Vision.tool.tuyang.pcammls import *
|
||||
from Expection import VisionError_Code
|
||||
import cv2
|
||||
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
class camera_pe():
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.caminit_isok = False
|
||||
self.cl = PercipioSDK()
|
||||
dev_list = self.cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print('{} -- {} \t {}'.format(idx, dev.id, dev.iface.id))
|
||||
if len(dev_list) == 0:
|
||||
print('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
# 设备ID
|
||||
self.handle = self.cl.Open(sn)
|
||||
if not self.cl.isValidHandle(self.handle):
|
||||
err = self.cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
self.event = PythonPercipioDeviceEvent()
|
||||
self.cl.DeviceRegiststerCallBackEvent(self.event)
|
||||
|
||||
color_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_COLOR)
|
||||
if len(color_fmt_list) == 0:
|
||||
print('device has no color stream.')
|
||||
return
|
||||
|
||||
# print('color image format list:')
|
||||
# for idx in range(len(color_fmt_list)): # 查看图像分辨率
|
||||
# fmt = color_fmt_list[idx]
|
||||
# print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_COLOR, color_fmt_list[0]) # 图像大小
|
||||
|
||||
depth_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) == 0:
|
||||
print('device has no depth stream.')
|
||||
return
|
||||
|
||||
# print('depth image format list:') # 查看深度图分辨率
|
||||
# for idx in range(len(depth_fmt_list)):
|
||||
# fmt = depth_fmt_list[idx]
|
||||
# print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[0]) # 深度图大小
|
||||
self.depth_calib_data = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
|
||||
err = self.cl.DeviceLoadDefaultParameters(self.handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(self.cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
self.scale_unit = self.cl.DeviceReadCalibDepthScaleUnit(self.handle)
|
||||
#print('depth image scale unit :{}'.format(scale_unit))
|
||||
|
||||
self.depth_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
self.color_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_COLOR)
|
||||
|
||||
err = self.cl.DeviceStreamEnable(self.handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
self.cl.DeviceStreamOn(self.handle)
|
||||
|
||||
# self.pointcloud_data_arr = pointcloud_data_list()
|
||||
# self.img_registration_depth = image_data()
|
||||
# self.img_registration_render = image_data()
|
||||
# self.img_parsed_color = image_data()
|
||||
# self.img_undistortion_color = image_data()
|
||||
# self.img_registration_color = image_data()
|
||||
self.img_registration_render = image_data()
|
||||
self.img_registration_depth = image_data()
|
||||
self.img_registration_render = image_data()
|
||||
self.img_parsed_color = image_data()
|
||||
self.img_undistortion_color = image_data()
|
||||
self.img_registration_color = image_data()
|
||||
self.pointcloud_data_arr = pointcloud_data_list()
|
||||
self.caminit_isok = True
|
||||
print(VisionError_Code.CAMERA_SUCCESS)
|
||||
|
||||
|
||||
def get_img_and_point_map(self):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
:return: ret , img, point_map
|
||||
'''
|
||||
if self.caminit_isok == False or self.event.IsOffline():
|
||||
return 0, None, None
|
||||
else:
|
||||
image_list = self.cl.DeviceStreamRead(self.handle, 2000)
|
||||
if len(image_list) == 2:
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
img_depth = frame
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
img_color = frame
|
||||
|
||||
self.cl.DeviceStreamImageDecode(img_color, self.img_parsed_color)
|
||||
self.cl.DeviceStreamDoUndistortion(self.color_calib, self.img_parsed_color, self.img_undistortion_color)
|
||||
|
||||
self.cl.DeviceStreamMapRGBImageToDepthCoordinate(self.depth_calib, img_depth, self.scale_unit, self.color_calib,
|
||||
self.img_undistortion_color, self.img_registration_color)
|
||||
# 对齐
|
||||
# mat_depth_render = self.img_registration_render.as_nparray()
|
||||
self.cl.DeviceStreamDepthRender(img_depth, self.img_registration_render)
|
||||
mat_depth_render = self.img_registration_render.as_nparray()
|
||||
|
||||
self.cl.DeviceStreamMapDepthImageToPoint3D(img_depth, self.depth_calib_data, self.scale_unit, self.pointcloud_data_arr)
|
||||
p3d_nparray = self.pointcloud_data_arr.as_nparray()
|
||||
|
||||
mat_registration_color = self.img_registration_color.as_nparray() # 对齐的彩色图
|
||||
|
||||
return 1, mat_registration_color, p3d_nparray, mat_depth_render
|
||||
else:
|
||||
return 0, None, None, None
|
||||
|
||||
def release(self):
|
||||
if self.caminit_isok == False:
|
||||
pass
|
||||
else:
|
||||
self.cl.DeviceStreamOff(self.handle)
|
||||
self.cl.Close(self.handle)
|
||||
pass
|
||||
|
||||
|
||||
# my_camera = camera()
|
||||
# while True:
|
||||
# ret, img, p3d_nparray = my_camera.get_img_and_point_map()
|
||||
# cv2.imshow('img', img)
|
||||
# cv2.imshow('3d',p3d_nparray)
|
||||
# cv2.waitKey(1)
|
||||
182
Vision/tool/CameraPe_depth2color.py
Normal file
182
Vision/tool/CameraPe_depth2color.py
Normal file
@ -0,0 +1,182 @@
|
||||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
'''
|
||||
# @Time : 2024/9/19 16:08
|
||||
# @Author : hjw
|
||||
# @File : CameraPe.py
|
||||
'''
|
||||
from Vision.tool.tuyang import pcammls
|
||||
from Vision.tool.tuyang.pcammls import *
|
||||
from Expection import VisionError_Code
|
||||
import cv2
|
||||
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
class camera_pe():
|
||||
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.caminit_isok = False
|
||||
self.cl = PercipioSDK()
|
||||
dev_list = self.cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print('{} -- {} \t {}'.format(idx, dev.id, dev.iface.id))
|
||||
if len(dev_list) == 0:
|
||||
print('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
# 设备ID
|
||||
self.handle = self.cl.Open(sn)
|
||||
if not self.cl.isValidHandle(self.handle):
|
||||
err = self.cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
self.event = PythonPercipioDeviceEvent()
|
||||
self.cl.DeviceRegiststerCallBackEvent(self.event)
|
||||
|
||||
color_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_COLOR)
|
||||
if len(color_fmt_list) == 0:
|
||||
print('device has no color stream.')
|
||||
return
|
||||
|
||||
# print('color image format list:')
|
||||
# for idx in range(len(color_fmt_list)): # 查看图像分辨率
|
||||
# fmt = color_fmt_list[idx]
|
||||
# print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_COLOR, color_fmt_list[2]) # 图像大小
|
||||
|
||||
depth_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) == 0:
|
||||
print('device has no depth stream.')
|
||||
return
|
||||
|
||||
# print('depth image format list:') # 查看深度图分辨率
|
||||
# for idx in range(len(depth_fmt_list)):
|
||||
# fmt = depth_fmt_list[idx]
|
||||
# print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[2]) # 深度图大小
|
||||
self.depth_calib_data = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
|
||||
err = self.cl.DeviceLoadDefaultParameters(self.handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(self.cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
self.scale_unit = self.cl.DeviceReadCalibDepthScaleUnit(self.handle)
|
||||
#print('depth image scale unit :{}'.format(scale_unit))
|
||||
|
||||
self.depth_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||
self.color_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_COLOR)
|
||||
|
||||
err = self.cl.DeviceStreamEnable(self.handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
self.cl.DeviceStreamOn(self.handle)
|
||||
|
||||
# self.pointcloud_data_arr = pointcloud_data_list()
|
||||
# self.img_registration_depth = image_data()
|
||||
# self.img_registration_render = image_data()
|
||||
# self.img_parsed_color = image_data()
|
||||
# self.img_undistortion_color = image_data()
|
||||
# self.img_registration_color = image_data()
|
||||
self.img_registration_render = image_data()
|
||||
self.img_registration_depth = image_data()
|
||||
self.img_registration_render = image_data()
|
||||
self.img_parsed_color = image_data()
|
||||
self.img_undistortion_color = image_data()
|
||||
self.img_registration_color = image_data()
|
||||
self.pointcloud_data_arr = pointcloud_data_list()
|
||||
self.caminit_isok = True
|
||||
print(VisionError_Code.CAMERA_SUCCESS)
|
||||
|
||||
|
||||
def get_img_and_point_map(self):
|
||||
""
|
||||
'''
|
||||
:param api: None
|
||||
:return: ret , img, point_map
|
||||
'''
|
||||
if self.caminit_isok == False or self.event.IsOffline():
|
||||
return 0, None, None
|
||||
else:
|
||||
image_list = self.cl.DeviceStreamRead(self.handle, 2000)
|
||||
if len(image_list) == 2:
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
img_depth = frame
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
img_color = frame
|
||||
|
||||
self.cl.DeviceStreamMapDepthImageToColorCoordinate(self.depth_calib, img_depth, self.scale_unit, self.color_calib,
|
||||
img_color.width, img_color.height, self.img_registration_depth)
|
||||
|
||||
self.cl.DeviceStreamDepthRender(self.img_registration_depth, self.img_registration_render)
|
||||
mat_depth_render = self.img_registration_render.as_nparray()
|
||||
self.cl.DeviceStreamMapDepthImageToPoint3D(self.img_registration_depth, self.depth_calib_data, self.scale_unit,
|
||||
self.pointcloud_data_arr)
|
||||
p3d_nparray = self.pointcloud_data_arr.as_nparray()
|
||||
|
||||
|
||||
self.cl.DeviceStreamImageDecode(img_color, self.img_parsed_color)
|
||||
self.cl.DeviceStreamDoUndistortion(self.color_calib, self.img_parsed_color, self.img_undistortion_color)
|
||||
mat_undistortion_color = self.img_undistortion_color.as_nparray()
|
||||
|
||||
# self.cl.DeviceStreamMapRGBImageToDepthCoordinate(self.depth_calib, img_depth, self.scale_unit, self.color_calib,
|
||||
# self.img_undistortion_color, self.img_registration_color)
|
||||
# # 对齐
|
||||
# # mat_depth_render = self.img_registration_render.as_nparray()
|
||||
# self.cl.DeviceStreamDepthRender(img_depth, self.img_registration_render)
|
||||
# mat_depth_render = self.img_registration_render.as_nparray()
|
||||
#
|
||||
# self.cl.DeviceStreamMapDepthImageToPoint3D(img_depth, self.depth_calib_data, self.scale_unit, self.pointcloud_data_arr)
|
||||
# p3d_nparray = self.pointcloud_data_arr.as_nparray()
|
||||
#
|
||||
# mat_registration_color = self.img_registration_color.as_nparray() # 对齐的彩色图
|
||||
|
||||
return 1, mat_undistortion_color, p3d_nparray, mat_depth_render
|
||||
else:
|
||||
return 0, None, None, None
|
||||
|
||||
def release(self):
|
||||
if self.caminit_isok == False:
|
||||
pass
|
||||
else:
|
||||
self.cl.DeviceStreamOff(self.handle)
|
||||
self.cl.Close(self.handle)
|
||||
pass
|
||||
|
||||
|
||||
# my_camera = camera()
|
||||
# while True:
|
||||
# ret, img, p3d_nparray = my_camera.get_img_and_point_map()
|
||||
# cv2.imshow('img', img)
|
||||
# cv2.imshow('3d',p3d_nparray)
|
||||
# cv2.waitKey(1)
|
||||
BIN
Vision/tool/tuyang/_pcammls.pyd
Normal file
BIN
Vision/tool/tuyang/_pcammls.pyd
Normal file
Binary file not shown.
142
Vision/tool/tuyang/frame_fetch.py
Normal file
142
Vision/tool/tuyang/frame_fetch.py
Normal file
@ -0,0 +1,142 @@
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
color_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_COLOR)
|
||||
if len(color_fmt_list) != 0:
|
||||
print ('color image format list:')
|
||||
for idx in range(len(color_fmt_list)):
|
||||
fmt = color_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
print('\tSelect {}'.format(fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_COLOR, color_fmt_list[0])
|
||||
|
||||
color_enum_desc = TY_ENUM_ENTRY()
|
||||
cl.DeviceReadCurrentEnumData(handle, PERCIPIO_STREAM_COLOR, color_enum_desc)
|
||||
print('current color image mode {}x{}'.format(cl.Width(color_enum_desc), cl.Height(color_enum_desc)))
|
||||
|
||||
color_calib_data = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_COLOR)
|
||||
color_calib_width = color_calib_data.Width()
|
||||
color_calib_height = color_calib_data.Height()
|
||||
color_calib_intr = color_calib_data.Intrinsic()
|
||||
color_calib_extr = color_calib_data.Extrinsic()
|
||||
color_calib_dis = color_calib_data.Distortion()
|
||||
print('color calib info:')
|
||||
print('\tcalib size :[{}x{}]'.format(color_calib_width, color_calib_height))
|
||||
print('\tcalib intr : {}'.format(color_calib_intr))
|
||||
print('\tcalib extr : {}'.format(color_calib_extr))
|
||||
print('\tcalib distortion : {}'.format(color_calib_dis))
|
||||
|
||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) != 0:
|
||||
print ('depth image format list:')
|
||||
for idx in range(len(depth_fmt_list)):
|
||||
fmt = depth_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
print('\tSelect {}'.format(fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[0])
|
||||
|
||||
depth_enum_desc = TY_ENUM_ENTRY()
|
||||
cl.DeviceReadCurrentEnumData(handle, PERCIPIO_STREAM_DEPTH, depth_enum_desc)
|
||||
print('current depth image mode {}x{}'.format(cl.Width(depth_enum_desc), cl.Height(depth_enum_desc)))
|
||||
|
||||
depth_calib_data = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_DEPTH)
|
||||
depth_calib_width = depth_calib_data.Width()
|
||||
depth_calib_height = depth_calib_data.Height()
|
||||
depth_calib_intr = depth_calib_data.Intrinsic()
|
||||
depth_calib_extr = depth_calib_data.Extrinsic()
|
||||
depth_calib_dis = depth_calib_data.Distortion()
|
||||
print('delth calib info:')
|
||||
print('\tcalib size :[{}x{}]'.format(depth_calib_width, depth_calib_height))
|
||||
print('\tcalib intr : {}'.format(depth_calib_intr))
|
||||
print('\tcalib extr : {}'.format(depth_calib_extr))
|
||||
print('\tcalib distortion : {}'.format(depth_calib_dis))
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
err=cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
rgb_image = image_data()
|
||||
depth_render = image_data()
|
||||
cl.DeviceStreamOn(handle)
|
||||
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
image_list = cl.DeviceStreamRead(handle, -1)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
cl.DeviceStreamDepthRender(frame, depth_render)
|
||||
arr = depth_render.as_nparray()
|
||||
cv2.imshow('depth',arr)
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
cl.DeviceStreamImageDecode(frame, rgb_image)
|
||||
arr = rgb_image.as_nparray()
|
||||
cv2.imshow('color',arr)
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
103
Vision/tool/tuyang/frame_fetchIR.py
Normal file
103
Vision/tool/tuyang/frame_fetchIR.py
Normal file
@ -0,0 +1,103 @@
|
||||
'''
|
||||
Description:
|
||||
Author: zxy
|
||||
Date: 2023-07-14 19:12:19
|
||||
LastEditors: zxy
|
||||
LastEditTime: 2023-07-18 12:07:14
|
||||
'''
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
cl.DeviceControlLaserPowerAutoControlEnable(handle, False)
|
||||
cl.DeviceControlLaserPowerConfig(handle, 80)
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_IR_LEFT | PERCIPIO_STREAM_IR_RIGHT)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
img_ir = image_data()
|
||||
cl.DeviceStreamOn(handle)
|
||||
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
|
||||
image_list = cl.DeviceStreamRead(handle, 2000)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_IR_LEFT:
|
||||
cl.DeviceStreamIRRender(frame, img_ir)
|
||||
arr = img_ir.as_nparray()
|
||||
cv2.imshow('leftir',arr)
|
||||
if frame.streamID == PERCIPIO_STREAM_IR_RIGHT:
|
||||
cl.DeviceStreamIRRender(frame, img_ir)
|
||||
arr = img_ir.as_nparray()
|
||||
cv2.imshow('right ir',arr)
|
||||
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
97
Vision/tool/tuyang/frame_isp.py
Normal file
97
Vision/tool/tuyang/frame_isp.py
Normal file
@ -0,0 +1,97 @@
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
color_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_COLOR)
|
||||
if len(color_fmt_list) != 0:
|
||||
print ('color image format list:')
|
||||
for idx in range(len(color_fmt_list)):
|
||||
fmt = color_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
print('\tSelect {}'.format(fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_COLOR, color_fmt_list[len(color_fmt_list) - 1])
|
||||
else:
|
||||
print ('device has no color stream.')
|
||||
cl.Close(handle)
|
||||
return
|
||||
|
||||
#enable rgb image software isp
|
||||
cl.DeviceColorStreamIspEnable(handle, True)
|
||||
|
||||
rgb_image = image_data()
|
||||
|
||||
cl.DeviceStreamOn(handle)
|
||||
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
image_list = cl.DeviceStreamRead(handle, -1)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
cl.DeviceStreamImageDecode(frame, rgb_image)
|
||||
arr = rgb_image.as_nparray()
|
||||
cv2.imshow('color',arr)
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
157
Vision/tool/tuyang/frame_registration.py
Normal file
157
Vision/tool/tuyang/frame_registration.py
Normal file
@ -0,0 +1,157 @@
|
||||
'''
|
||||
Description:
|
||||
Author: zxy
|
||||
Date: 2023-07-14 09:48:00
|
||||
LastEditors: zxy
|
||||
LastEditTime: 2024-01-02 11:36:57
|
||||
'''
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
color_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_COLOR)
|
||||
if len(color_fmt_list) == 0:
|
||||
print ('device has no color stream.')
|
||||
return
|
||||
|
||||
print ('color image format list:')
|
||||
for idx in range(len(color_fmt_list)):
|
||||
fmt = color_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_COLOR, color_fmt_list[0])
|
||||
|
||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) == 0:
|
||||
print ('device has no depth stream.')
|
||||
return
|
||||
|
||||
print ('depth image format list:')
|
||||
for idx in range(len(depth_fmt_list)):
|
||||
fmt = depth_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[0])
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
scale_unit = cl.DeviceReadCalibDepthScaleUnit(handle)
|
||||
print ('depth image scale unit :{}'.format(scale_unit))
|
||||
|
||||
depth_calib = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_DEPTH)
|
||||
color_calib = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_COLOR)
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
print ('{} -- {} \t'.format(0,"Map depth to color coordinate(suggest)"))
|
||||
print ('{} -- {} \t'.format(1,"Map color to depth coordinate"))
|
||||
registration_mode = int(input('select registration mode(0 or 1):'))
|
||||
if selected_idx < 0 or selected_idx >= 2:
|
||||
registration_mode = 0
|
||||
|
||||
cl.DeviceStreamOn(handle)
|
||||
img_registration_depth = image_data()
|
||||
img_registration_render = image_data()
|
||||
img_parsed_color = image_data()
|
||||
img_undistortion_color = image_data()
|
||||
img_registration_color = image_data()
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
image_list = cl.DeviceStreamRead(handle, 2000)
|
||||
if len(image_list) == 2:
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
img_depth = frame
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
img_color = frame
|
||||
|
||||
if 0 == registration_mode:
|
||||
cl.DeviceStreamMapDepthImageToColorCoordinate(depth_calib, img_depth, scale_unit, color_calib, img_color.width, img_color.height, img_registration_depth)
|
||||
|
||||
cl.DeviceStreamDepthRender(img_registration_depth, img_registration_render)
|
||||
mat_depth_render = img_registration_render.as_nparray()
|
||||
cv2.imshow('registration', mat_depth_render)
|
||||
|
||||
cl.DeviceStreamImageDecode(img_color, img_parsed_color)
|
||||
cl.DeviceStreamDoUndistortion(color_calib, img_parsed_color, img_undistortion_color)
|
||||
mat_undistortion_color = img_undistortion_color.as_nparray()
|
||||
cv2.imshow('undistortion rgb', mat_undistortion_color)
|
||||
else:
|
||||
cl.DeviceStreamImageDecode(img_color, img_parsed_color)
|
||||
cl.DeviceStreamDoUndistortion(color_calib, img_parsed_color, img_undistortion_color)
|
||||
|
||||
cl.DeviceStreamMapRGBImageToDepthCoordinate(depth_calib, img_depth, scale_unit, color_calib, img_undistortion_color, img_registration_color)
|
||||
|
||||
cl.DeviceStreamDepthRender(img_depth, img_registration_render)
|
||||
mat_depth_render = img_registration_render.as_nparray()
|
||||
cv2.imshow('depth', mat_depth_render)
|
||||
|
||||
mat_registration_color = img_registration_color.as_nparray()
|
||||
cv2.imshow('registration rgb', mat_registration_color)
|
||||
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
111
Vision/tool/tuyang/frame_trigger.py
Normal file
111
Vision/tool/tuyang/frame_trigger.py
Normal file
@ -0,0 +1,111 @@
|
||||
'''
|
||||
Description:
|
||||
Author: zxy
|
||||
Date: 2023-07-13 15:38:51
|
||||
LastEditors: zxy
|
||||
LastEditTime: 2023-07-18 11:57:37
|
||||
'''
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) == 0:
|
||||
print ('device has no depth stream.')
|
||||
return
|
||||
|
||||
print ('depth image format list:')
|
||||
for idx in range(len(depth_fmt_list)):
|
||||
fmt = depth_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[0])
|
||||
|
||||
cl.DeviceControlTriggerModeEnable(handle, 1)
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
depth_render = image_data()
|
||||
cl.DeviceStreamOn(handle)
|
||||
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
|
||||
|
||||
cl.DeviceControlTriggerModeSendTriggerSignal(handle)
|
||||
image_list = cl.DeviceStreamRead(handle, 20000)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
arr = frame.as_nparray()
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
cl.DeviceStreamDepthRender(frame, depth_render)
|
||||
mat_depth_render = depth_render.as_nparray()
|
||||
cv2.imshow('depth',mat_depth_render)
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
106
Vision/tool/tuyang/multidevice_fetch.py
Normal file
106
Vision/tool/tuyang/multidevice_fetch.py
Normal file
@ -0,0 +1,106 @@
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
|
||||
#register offline event
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
#sn list init
|
||||
sn = [0] * len(dev_list)
|
||||
for idx in range(len(dev_list)):
|
||||
sn[idx] = dev_list[idx].id
|
||||
|
||||
#open device
|
||||
handle = [0] * len(dev_list)
|
||||
for i in range(len(dev_list)):
|
||||
handle[i] = cl.Open(sn[i])
|
||||
if not cl.isValidHandle(handle[i]):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
#device stream config
|
||||
for i in range(len(dev_list)):
|
||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle[i], PERCIPIO_STREAM_DEPTH)
|
||||
print ('depth image format list:')
|
||||
for idx in range(len(depth_fmt_list)):
|
||||
fmt = depth_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle[i], PERCIPIO_STREAM_DEPTH, depth_fmt_list[0])
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle[i])
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
err = cl.DeviceStreamEnable(handle[i], PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
cl.DeviceStreamOn(handle[i])
|
||||
|
||||
depth_render = [0] * len(dev_list)
|
||||
for i in range(len(dev_list)):
|
||||
depth_render[i] = image_data()
|
||||
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
|
||||
for m in range(len(dev_list)):
|
||||
image_list = cl.DeviceStreamRead(handle[m], -1)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
cl.DeviceStreamDepthRender(frame, depth_render[m])
|
||||
arr = depth_render[m].as_nparray()
|
||||
cv2.imshow(sn[m],arr)
|
||||
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
for i in range(len(dev_list)):
|
||||
cl.DeviceStreamOff(handle[i])
|
||||
|
||||
for i in range(len(dev_list)):
|
||||
cl.Close(handle[i])
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
109
Vision/tool/tuyang/parameter_settings.py
Normal file
109
Vision/tool/tuyang/parameter_settings.py
Normal file
@ -0,0 +1,109 @@
|
||||
'''
|
||||
Description:
|
||||
Author: zxy
|
||||
Date: 2023-07-14 09:48:00
|
||||
LastEditors: zxy
|
||||
LastEditTime: 2024-11-25 11:36:57
|
||||
'''
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
#bool:color aec
|
||||
aec = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_BOOL_AUTO_EXPOSURE)
|
||||
if aec.isEmpty():
|
||||
print('aec is not support!')
|
||||
else :
|
||||
print('current aec status : {}'.format(aec.toBool()))
|
||||
|
||||
#disable color aec
|
||||
aec = cl.DevParamFromBool(False)
|
||||
err = cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_BOOL_AUTO_EXPOSURE, aec)
|
||||
print('aec close result : ', end='')
|
||||
print(err)
|
||||
|
||||
#int:color exposure time
|
||||
exp = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_INT_EXPOSURE_TIME)
|
||||
if exp.isEmpty():
|
||||
print('exposure time is not support!')
|
||||
else :
|
||||
print('current exposure time status : {}, range : {} - {}, inc : {}'.format(exp.toInt(), exp.mMin(), exp.mMax(), exp.mInc()))
|
||||
|
||||
exposure_time = int(input('Enter exposure time:'))
|
||||
exp = cl.DevParamFromInt(exposure_time)
|
||||
err = cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_INT_EXPOSURE_TIME, exp)
|
||||
print('set color exposure time result : ', end='')
|
||||
print(err)
|
||||
|
||||
image_mode = cl.DeviceGetParameter(handle, TY_COMPONENT_RGB_CAM, TY_ENUM_IMAGE_MODE)
|
||||
if image_mode.isEmpty():
|
||||
print('color image mode is not support!')
|
||||
else :
|
||||
list = image_mode.eList()
|
||||
for idx in range(len(list)):
|
||||
mode = list[idx]
|
||||
print('{}: {}x{} - {}'.format(idx, cl.Width(mode), cl.Height(mode), cl.Description(mode)))
|
||||
|
||||
index = int(input('Enter image mode index:'))
|
||||
image_mode = cl.DevParamFromEnum(cl.Value(list[index]))
|
||||
err = cl.DeviceSetParameter(handle, TY_COMPONENT_RGB_CAM, TY_ENUM_IMAGE_MODE, image_mode)
|
||||
|
||||
cl.DeviceStreamOn(handle)
|
||||
img_parsed_color = image_data()
|
||||
while True:
|
||||
image_list = cl.DeviceStreamRead(handle, 2000)
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||
img_color = frame
|
||||
|
||||
cl.DeviceStreamImageDecode(img_color, img_parsed_color)
|
||||
mat_undistortion_color = img_parsed_color.as_nparray()
|
||||
cv2.imshow('rgb', mat_undistortion_color)
|
||||
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
BIN
Vision/tool/tuyang/pcammls.exp
Normal file
BIN
Vision/tool/tuyang/pcammls.exp
Normal file
Binary file not shown.
BIN
Vision/tool/tuyang/pcammls.lib
Normal file
BIN
Vision/tool/tuyang/pcammls.lib
Normal file
Binary file not shown.
10936
Vision/tool/tuyang/pcammls.py
Normal file
10936
Vision/tool/tuyang/pcammls.py
Normal file
File diff suppressed because it is too large
Load Diff
129
Vision/tool/tuyang/point3d_fetch.py
Normal file
129
Vision/tool/tuyang/point3d_fetch.py
Normal file
@ -0,0 +1,129 @@
|
||||
'''
|
||||
Description:
|
||||
Author: zxy
|
||||
Date: 2023-07-18 09:55:47
|
||||
LastEditors: zxy
|
||||
LastEditTime: 2023-12-28 15:49:28
|
||||
'''
|
||||
import pcammls
|
||||
from pcammls import *
|
||||
import cv2
|
||||
import numpy
|
||||
import sys
|
||||
import os
|
||||
|
||||
class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
||||
Offline = False
|
||||
|
||||
def __init__(self):
|
||||
pcammls.DeviceEvent.__init__(self)
|
||||
|
||||
def run(self, handle, eventID):
|
||||
if eventID==TY_EVENT_DEVICE_OFFLINE:
|
||||
print('=== Event Callback: Device Offline!')
|
||||
self.Offline = True
|
||||
return 0
|
||||
|
||||
def IsOffline(self):
|
||||
return self.Offline
|
||||
|
||||
def main():
|
||||
cl = PercipioSDK()
|
||||
|
||||
dev_list = cl.ListDevice()
|
||||
for idx in range(len(dev_list)):
|
||||
dev = dev_list[idx]
|
||||
print ('{} -- {} \t {}'.format(idx,dev.id,dev.iface.id))
|
||||
if len(dev_list)==0:
|
||||
print ('no device')
|
||||
return
|
||||
if len(dev_list) == 1:
|
||||
selected_idx = 0
|
||||
else:
|
||||
selected_idx = int(input('select a device:'))
|
||||
if selected_idx < 0 or selected_idx >= len(dev_list):
|
||||
return
|
||||
|
||||
sn = dev_list[selected_idx].id
|
||||
|
||||
handle = cl.Open(sn)
|
||||
if not cl.isValidHandle(handle):
|
||||
err = cl.TYGetLastErrorCodedescription()
|
||||
print('no device found : ', end='')
|
||||
print(err)
|
||||
return
|
||||
|
||||
event = PythonPercipioDeviceEvent()
|
||||
cl.DeviceRegiststerCallBackEvent(event)
|
||||
|
||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if len(depth_fmt_list) == 0:
|
||||
print ('device has no depth stream.')
|
||||
return
|
||||
|
||||
print ('depth image format list:')
|
||||
for idx in range(len(depth_fmt_list)):
|
||||
fmt = depth_fmt_list[idx]
|
||||
print ('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
||||
cl.DeviceStreamFormatConfig(handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[0])
|
||||
|
||||
depth_calib_data = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_DEPTH)
|
||||
depth_calib_width = depth_calib_data.Width()
|
||||
depth_calib_height = depth_calib_data.Height()
|
||||
depth_calib_intr = depth_calib_data.Intrinsic()
|
||||
depth_calib_extr = depth_calib_data.Extrinsic()
|
||||
depth_calib_dis = depth_calib_data.Distortion()
|
||||
print('delth calib info:')
|
||||
print('\tcalib size :[{}x{}]'.format(depth_calib_width, depth_calib_height))
|
||||
print('\tcalib intr : {}'.format(depth_calib_intr))
|
||||
print('\tcalib extr : {}'.format(depth_calib_extr))
|
||||
print('\tcalib distortion : {}'.format(depth_calib_dis))
|
||||
|
||||
err = cl.DeviceLoadDefaultParameters(handle)
|
||||
if err:
|
||||
print('Load default parameters fail: ', end='')
|
||||
print(cl.TYGetLastErrorCodedescription())
|
||||
else:
|
||||
print('Load default parameters successful')
|
||||
|
||||
scale_unit = cl.DeviceReadCalibDepthScaleUnit(handle)
|
||||
print ('depth image scale unit :{}'.format(scale_unit))
|
||||
|
||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_DEPTH)
|
||||
if err:
|
||||
print('device stream enable err:{}'.format(err))
|
||||
return
|
||||
|
||||
cl.DeviceStreamOn(handle)
|
||||
|
||||
pointcloud_data_arr = pointcloud_data_list()
|
||||
while True:
|
||||
if event.IsOffline():
|
||||
break
|
||||
image_list = cl.DeviceStreamRead(handle, -1)
|
||||
|
||||
for i in range(len(image_list)):
|
||||
frame = image_list[i]
|
||||
if frame.streamID == PERCIPIO_STREAM_DEPTH:
|
||||
cl.DeviceStreamMapDepthImageToPoint3D(frame, depth_calib_data, scale_unit, pointcloud_data_arr)
|
||||
sz = pointcloud_data_arr.size()
|
||||
print('get p3d size : {}'.format(sz))
|
||||
center = frame.width * frame.height / 2 + frame.width / 2
|
||||
|
||||
#show p3d arr data
|
||||
p3d_nparray = pointcloud_data_arr.as_nparray()
|
||||
cv2.imshow('p3d',p3d_nparray)
|
||||
|
||||
p3d = pointcloud_data_arr.get_value(int(center))
|
||||
print('\tp3d data : {} {} {}'.format(p3d.getX(), p3d.getY(), p3d.getZ()))
|
||||
k = cv2.waitKey(10)
|
||||
if k==ord('q'):
|
||||
break
|
||||
|
||||
cl.DeviceStreamOff(handle)
|
||||
cl.Close(handle)
|
||||
pass
|
||||
|
||||
if __name__=='__main__':
|
||||
main()
|
||||
|
||||
BIN
Vision/tool/tuyang/tycam.dll
Normal file
BIN
Vision/tool/tuyang/tycam.dll
Normal file
Binary file not shown.
BIN
Vision/tool/tuyang/tycam.lib
Normal file
BIN
Vision/tool/tuyang/tycam.lib
Normal file
Binary file not shown.
@ -6,8 +6,11 @@
|
||||
# @File : get_position_test.py
|
||||
'''
|
||||
import time
|
||||
import platform
|
||||
import cv2
|
||||
import os
|
||||
|
||||
from Vision.camera_coordinate_dete_img import Detection
|
||||
from Vision.camera_coordinate_dete import Detection
|
||||
from Trace.handeye_calibration import *
|
||||
from Vision.tool.utils import get_disk_space
|
||||
from Vision.tool.utils import remove_nan_mean_value
|
||||
@ -15,9 +18,7 @@ from Vision.detect_person import DetectionPerson
|
||||
from Vision.detect_bag_num import DetectionBagNum
|
||||
from Vision.tool.CameraHIK import camera_HIK
|
||||
from Vision.bag_collection import DetectionBag
|
||||
import platform
|
||||
import cv2
|
||||
import os
|
||||
|
||||
#
|
||||
"""
|
||||
测试 Vision
|
||||
@ -26,7 +27,7 @@ import os
|
||||
def detectionPosition_test():
|
||||
detection = Detection()
|
||||
while True:
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position(Point_isVision=True)
|
||||
ret, img, xyz, nx_ny_nz, box = detection.get_position(Point_isVision=True, save_img_point=1)
|
||||
if ret==1:
|
||||
print('xyz点云坐标:', xyz)
|
||||
print('nx_ny_nz法向量:', nx_ny_nz)
|
||||
|
||||
Reference in New Issue
Block a user