UPDATE Vision 更新图像漾相机
This commit is contained in:
@ -7,6 +7,10 @@ class Error_Code(Enum):
|
|||||||
|
|
||||||
class VisionError_Code(Enum):
|
class VisionError_Code(Enum):
|
||||||
CAMERA_SUCCESS = 200
|
CAMERA_SUCCESS = 200
|
||||||
|
CAMERA_NO_DEVICE = 201
|
||||||
|
CAMERA_NO_DEVICE_FOUND = 202
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
'''
|
'''
|
||||||
from Vision.tool.percipio.win import pcammls
|
from Vision.tool.percipio.win import pcammls
|
||||||
from Vision.tool.percipio.win.pcammls import *
|
from Vision.tool.percipio.win.pcammls import *
|
||||||
|
from Expection import VisionError_Code
|
||||||
import cv2
|
import cv2
|
||||||
|
|
||||||
|
|
||||||
@ -25,12 +26,13 @@ class PythonPercipioDeviceEvent(pcammls.DeviceEvent):
|
|||||||
def IsOffline(self):
|
def IsOffline(self):
|
||||||
return self.Offline
|
return self.Offline
|
||||||
|
|
||||||
class camera:
|
class camera():
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
self.caminit_isok = False
|
self.caminit_isok = False
|
||||||
cl = PercipioSDK()
|
self.cl = PercipioSDK()
|
||||||
dev_list = cl.ListDevice()
|
dev_list = self.cl.ListDevice()
|
||||||
for idx in range(len(dev_list)):
|
for idx in range(len(dev_list)):
|
||||||
dev = dev_list[idx]
|
dev = dev_list[idx]
|
||||||
print('{} -- {} \t {}'.format(idx, dev.id, dev.iface.id))
|
print('{} -- {} \t {}'.format(idx, dev.id, dev.iface.id))
|
||||||
@ -46,72 +48,84 @@ class camera:
|
|||||||
|
|
||||||
sn = dev_list[selected_idx].id
|
sn = dev_list[selected_idx].id
|
||||||
# 设备ID
|
# 设备ID
|
||||||
handle = cl.Open(sn)
|
self.handle = self.cl.Open(sn)
|
||||||
if not cl.isValidHandle(handle):
|
if not self.cl.isValidHandle(self.handle):
|
||||||
err = cl.TYGetLastErrorCodedescription()
|
err = self.cl.TYGetLastErrorCodedescription()
|
||||||
print('no device found : ', end='')
|
print('no device found : ', end='')
|
||||||
print(err)
|
print(err)
|
||||||
return
|
return
|
||||||
|
|
||||||
event = PythonPercipioDeviceEvent()
|
self.event = PythonPercipioDeviceEvent()
|
||||||
cl.DeviceRegiststerCallBackEvent(event)
|
self.cl.DeviceRegiststerCallBackEvent(self.event)
|
||||||
|
|
||||||
color_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_COLOR)
|
color_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_COLOR)
|
||||||
if len(color_fmt_list) == 0:
|
if len(color_fmt_list) == 0:
|
||||||
print('device has no color stream.')
|
print('device has no color stream.')
|
||||||
return
|
return
|
||||||
|
|
||||||
print('color image format list:')
|
# print('color image format list:')
|
||||||
for idx in range(len(color_fmt_list)):
|
# for idx in range(len(color_fmt_list)): # 查看图像分辨率
|
||||||
fmt = color_fmt_list[idx]
|
# fmt = color_fmt_list[idx]
|
||||||
print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
# 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[2])
|
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_COLOR, color_fmt_list[2])
|
||||||
|
|
||||||
depth_fmt_list = cl.DeviceStreamFormatDump(handle, PERCIPIO_STREAM_DEPTH)
|
depth_fmt_list = self.cl.DeviceStreamFormatDump(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||||
if len(depth_fmt_list) == 0:
|
if len(depth_fmt_list) == 0:
|
||||||
print('device has no depth stream.')
|
print('device has no depth stream.')
|
||||||
return
|
return
|
||||||
|
|
||||||
print('depth image format list:')
|
# print('depth image format list:') # 查看深度图分辨率
|
||||||
for idx in range(len(depth_fmt_list)):
|
# for idx in range(len(depth_fmt_list)):
|
||||||
fmt = depth_fmt_list[idx]
|
# fmt = depth_fmt_list[idx]
|
||||||
print('\t{} -size[{}x{}]\t-\t desc:{}'.format(idx, cl.Width(fmt), cl.Height(fmt), fmt.getDesc()))
|
# 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[2])
|
self.cl.DeviceStreamFormatConfig(self.handle, PERCIPIO_STREAM_DEPTH, depth_fmt_list[2])
|
||||||
|
|
||||||
err = cl.DeviceLoadDefaultParameters(handle)
|
err = self.cl.DeviceLoadDefaultParameters(self.handle)
|
||||||
if err:
|
if err:
|
||||||
print('Load default parameters fail: ', end='')
|
print('Load default parameters fail: ', end='')
|
||||||
print(cl.TYGetLastErrorCodedescription())
|
print(self.cl.TYGetLastErrorCodedescription())
|
||||||
else:
|
else:
|
||||||
print('Load default parameters successful')
|
print('Load default parameters successful')
|
||||||
|
|
||||||
scale_unit = cl.DeviceReadCalibDepthScaleUnit(handle)
|
self.scale_unit = self.cl.DeviceReadCalibDepthScaleUnit(self.handle)
|
||||||
print('depth image scale unit :{}'.format(scale_unit))
|
#print('depth image scale unit :{}'.format(scale_unit))
|
||||||
|
|
||||||
depth_calib = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_DEPTH)
|
self.depth_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_DEPTH)
|
||||||
color_calib = cl.DeviceReadCalibData(handle, PERCIPIO_STREAM_COLOR)
|
self.color_calib = self.cl.DeviceReadCalibData(self.handle, PERCIPIO_STREAM_COLOR)
|
||||||
|
|
||||||
pointcloud_data_arr = pointcloud_data_list()
|
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()
|
||||||
|
|
||||||
err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
err = self.cl.DeviceStreamEnable(self.handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH)
|
||||||
if err:
|
if err:
|
||||||
print('device stream enable err:{}'.format(err))
|
print('device stream enable err:{}'.format(err))
|
||||||
return
|
return
|
||||||
|
|
||||||
cl.DeviceStreamOn(handle)
|
self.cl.DeviceStreamOn(self.handle)
|
||||||
|
self.caminit_isok = True
|
||||||
|
print(VisionError_Code.CAMERA_SUCCESS)
|
||||||
|
|
||||||
def get_img(self):
|
def get_img(self):
|
||||||
""
|
""
|
||||||
'''
|
'''
|
||||||
:param api: None
|
:param api: None
|
||||||
:return: ret ,img
|
:return: ret ,img
|
||||||
'''
|
'''
|
||||||
if self.caminit_isok == False:
|
if self.caminit_isok == False or self.event.IsOffline():
|
||||||
return 0, None
|
return 0, None
|
||||||
else:
|
else:
|
||||||
pass
|
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_COLOR:
|
||||||
|
img_color = frame
|
||||||
|
self.cl.DeviceStreamImageDecode(frame, self.img_undistortion_color)
|
||||||
|
img = self.img_undistortion_color.as_nparray()
|
||||||
|
return 1, img
|
||||||
|
return 0, None
|
||||||
|
|
||||||
def get_point_map(self):
|
def get_point_map(self):
|
||||||
""
|
""
|
||||||
@ -119,7 +133,7 @@ class camera:
|
|||||||
:param api: None
|
:param api: None
|
||||||
:return: img
|
:return: img
|
||||||
'''
|
'''
|
||||||
if self.caminit_isok == False:
|
if self.caminit_isok == False or self.event.IsOffline():
|
||||||
return 0, None
|
return 0, None
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
@ -130,13 +144,53 @@ class camera:
|
|||||||
:param api: None
|
:param api: None
|
||||||
:return: ret , img, point_map
|
:return: ret , img, point_map
|
||||||
'''
|
'''
|
||||||
if self.caminit_isok == False:
|
if self.caminit_isok == False or self.event.IsOffline():
|
||||||
return 0, None, None
|
return 0, None
|
||||||
else:
|
else:
|
||||||
pass
|
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
|
||||||
|
img_depth2p3d = frame
|
||||||
|
if frame.streamID == PERCIPIO_STREAM_COLOR:
|
||||||
|
img_color = frame
|
||||||
|
|
||||||
|
self.cl.DeviceStreamMapDepthImageToColorCoordinate(self.depth_calib, img_depth.width, img_depth.height,
|
||||||
|
self.scale_unit, img_depth, 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()
|
||||||
|
# cv2.imshow('registration', mat_depth_render)
|
||||||
|
|
||||||
|
self.cl.DeviceStreamMapDepthImageToPoint3D(self.img_registration_depth, self.depth_calib, self.scale_unit,
|
||||||
|
self.pointcloud_data_arr)
|
||||||
|
|
||||||
|
# show p3d arr data
|
||||||
|
p3d_nparray = self.pointcloud_data_arr.as_nparray()
|
||||||
|
#cv2.imshow('p3d2', p3d_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()
|
||||||
|
return 1, mat_undistortion_color, p3d_nparray
|
||||||
|
else:
|
||||||
|
return 0, None, None
|
||||||
|
|
||||||
def release(self):
|
def release(self):
|
||||||
if self.caminit_isok == False:
|
if self.caminit_isok == False:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
pass
|
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)
|
||||||
Reference in New Issue
Block a user