测试完成代码

This commit is contained in:
琉璃月光
2025-08-18 16:54:29 +08:00
commit a38051e4dc
194 changed files with 3570686 additions and 0 deletions

Binary file not shown.

View 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()

View 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()

View 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()

View 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()

View 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()

View 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()

View 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()

Binary file not shown.

Binary file not shown.

10936
Vision/tool/tuyang/pcammls.py Normal file

File diff suppressed because it is too large Load Diff

View 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()

Binary file not shown.

Binary file not shown.