#!/usr/bin/env python # -*- coding: utf-8 -*- ''' # @Time : 2024/9/19 16:08 # @Author : hjw # @File : CameraPe.py ''' from Vision.tool.percipio.win import pcammls from Vision.tool.percipio.win.pcammls import * 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: def __init__(self): self.caminit_isok = False 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 # 设备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[2]) 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[2]) 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) pointcloud_data_arr = pointcloud_data_list() err = cl.DeviceStreamEnable(handle, PERCIPIO_STREAM_COLOR | PERCIPIO_STREAM_DEPTH) if err: print('device stream enable err:{}'.format(err)) return cl.DeviceStreamOn(handle) def get_img(self): "" ''' :param api: None :return: ret ,img ''' if self.caminit_isok == False: return 0, None else: pass def get_point_map(self): "" ''' :param api: None :return: img ''' if self.caminit_isok == False: return 0, None else: pass def get_img_and_point_map(self): "" ''' :param api: None :return: ret , img, point_map ''' if self.caminit_isok == False: return 0, None, None else: pass def release(self): if self.caminit_isok == False: pass else: pass