diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b6bad32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +/venv/ +# 忽略 build 目录 +/build/ + +# 忽略 dist 目录 +/dist/ + +# 忽略 image 目录 +/image/ + +# 忽略 Mv3dRgbdLog 文件或目录 +/Mv3dRgbdLog/ + +/.idea/ \ No newline at end of file diff --git a/Hik3DApp.spec b/Hik3DApp.spec new file mode 100644 index 0000000..e3e3826 --- /dev/null +++ b/Hik3DApp.spec @@ -0,0 +1,45 @@ +# -*- mode: python ; coding: utf-8 -*- + + +a = Analysis( + ['main.py'], + pathex=[], + binaries=[], + datas=[('dlls', '_internal\\\\dlls')], + hiddenimports=['cv2.cv2', 'numpy.core._methods', 'numpy.lib.format', 'scipy.__config__', 'scipy._distributor_init', 'scipy.sparse.csgraph._validation', 'scipy.special._ellip_harm_2', 'scipy._cyutility', 'scipy._lib._ccallback', 'scipy.linalg.cython_blas', 'scipy.linalg.cython_lapack', 'scipy.optimize._highs._highs_constants', 'scipy.optimize._highs._highs_wrapper', 'sklearn.utils._weight_vector', 'sklearn.utils._weight_vector_fast', 'sklearn.tree._utils'], + hookspath=[], + hooksconfig={}, + runtime_hooks=[], + excludes=['tkinter', 'PyQt5'], + noarchive=False, + optimize=0, +) +pyz = PYZ(a.pure) + +exe = EXE( + pyz, + a.scripts, + [], + exclude_binaries=True, + name='Hik3DApp', + debug=False, + bootloader_ignore_signals=False, + strip=False, + upx=True, + console=True, + disable_windowed_traceback=False, + argv_emulation=False, + target_arch=None, + codesign_identity=None, + entitlements_file=None, + icon=['app.png'], +) +coll = COLLECT( + exe, + a.binaries, + a.datas, + strip=False, + upx=True, + upx_exclude=[], + name='Hik3DApp', +) diff --git a/Mv3dRgbdImport/Mv3dRgbdApi.py b/Mv3dRgbdImport/Mv3dRgbdApi.py new file mode 100644 index 0000000..7f53e2e --- /dev/null +++ b/Mv3dRgbdImport/Mv3dRgbdApi.py @@ -0,0 +1,818 @@ +# -- coding: utf-8 -- + +import sys +import copy +import ctypes +import os + +from ctypes import * + +# ch: python3.8及相关版本可以指定如下路径的库 | en: python3.8 and related versions can specify libraries for the following paths +# os.add_dll_directory("C:\Program Files (x86)\Common Files\MV3D\Runtime\Win64_x64") +# os.add_dll_directory("C:\Program Files (x86)\Common Files\Mv3dRgbdSDK\Runtime\Win64_x64") +# 动态加载 SDK 路径 +current_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) +sdk_path_1 = os.path.join(current_dir, "dlls", "MV3D", "Win64_x64") +sdk_path_2 = os.path.join(current_dir, "dlls", "Mv3dRgbdSDK", "Win64_x64") + +os.add_dll_directory(sdk_path_1) +os.add_dll_directory(sdk_path_2) +Mv3dRgbdDll = ctypes.WinDLL("Mv3dRgbd.dll") + +class Mv3dRgbd(): + def __init__(self): + self._handle = c_void_p() #~chinese 记录当前连接设备的句柄 ~english Records the handle of the currently connected device + self.handle = pointer(self._handle) #~chinese 创建句柄指针 ~english Create pointer of handle + + # ******************************************************************************************************* + # brief 获取SDK版本号 + # param pstVersion [OUT] 版本信息 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief Get SDK Version + # param pstVersion [OUT] version info + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_GetSDKVersion(pstVersion): + Mv3dRgbdDll.MV3D_RGBD_GetSDKVersion.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_GetSDKVersion.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetSDKVersion(MV3D_RGBD_VERSION_INFO* pstVersion); + return Mv3dRgbdDll.MV3D_RGBD_GetSDKVersion(pstVersion) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief SDK运行环境初始化 + # param + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief SDK run environment initialization + # param + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_Initialize(): + Mv3dRgbdDll.MV3D_RGBD_Initialize.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_Initialize(); + return Mv3dRgbdDll.MV3D_RGBD_Initialize() + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief SDK运行环境释放 + # param + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief SDK run environment release + # param + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_Release(): + Mv3dRgbdDll.MV3D_RGBD_Release.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_Release(); + return Mv3dRgbdDll.MV3D_RGBD_Release() + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 获取当前环境中设备数量 + # param nDeviceType [IN] 设备类型,见Mv3dRgbdDeviceType,可全部获取(DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir) + # param pDeviceNumber [OUT] 设备数量 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief gets the number of devices in the current environment + # param nDeviceType [IN] device type,refer to Mv3dRgbdDeviceType,get all(DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir) + # param pDeviceNumber [OUT] device number + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_GetDeviceNumber(nDeviceType, pDeviceNumber): + Mv3dRgbdDll.MV3D_RGBD_GetDeviceNumber.argtype = (c_uint, c_char_p) + Mv3dRgbdDll.MV3D_RGBD_GetDeviceNumber.restype = c_uint + # C原型:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetDeviceNumber(uint32_t nDeviceType, uint32_t* pDeviceNumber); + return Mv3dRgbdDll.MV3D_RGBD_GetDeviceNumber(nDeviceType, pDeviceNumber) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 获取设备列表 + # param nDeviceType [IN] 设备类型,见Mv3dRgbdDeviceType,可全部获取(DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir) + # param pstDeviceInfos [IN OUT] 设备列表 + # param nMaxDeviceCount [IN] 设备列表缓存最大个数 + # param pDeviceCount [OUT] 填充列表中设备个数 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief gets 3D cameras list + # param nDeviceType [IN] device type,refer to Mv3dRgbdDeviceType,get all(DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir) + # param pstDeviceInfos [IN OUT] devices list + # param nMaxDeviceCount [IN] max Number of device list caches + # param pDeviceCount [OUT] number of devices in the fill list + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_GetDeviceList(nDeviceType, pstDeviceInfos, nMaxDeviceCount, pDeviceNumber): + Mv3dRgbdDll.MV3D_RGBD_GetDeviceList.argtype = (c_uint, c_char_p, c_uint, c_char_p) + Mv3dRgbdDll.MV3D_RGBD_GetDeviceList.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetDeviceList(uint32_t nDeviceType, MV3D_RGBD_DEVICE_INFO* pstDeviceInfos, uint32_t nMaxDeviceCount, uint32_t* pDeviceCount); + return Mv3dRgbdDll.MV3D_RGBD_GetDeviceList(nDeviceType, pstDeviceInfos, nMaxDeviceCount, pDeviceNumber) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 打开设备 + # param self.handle [IN OUT] 相机句柄 + # param pstDeviceInfo [IN] 枚举的设备信息,默认为空,打开第一个相机 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief open device + # param self.handle [IN OUT] camera handle + # param pstDeviceInfo [IN] enum camera info. the default is null, open first camera + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_OpenDevice(self, pstDeviceInfo): + Mv3dRgbdDll.MV3D_RGBD_OpenDevice.argtype = (c_char_p, c_char_p) + Mv3dRgbdDll.MV3D_RGBD_OpenDevice.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_OpenDevice(HANDLE *handle, MV3D_RGBD_DEVICE_INFO* pstDeviceInfo = NULL); + return Mv3dRgbdDll.MV3D_RGBD_OpenDevice(byref(self.handle), pstDeviceInfo) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 通过设备设备自定义打开设备 + # param self.handle [IN OUT] 相机句柄 + # param chDeviceName [IN] 设备用户自定义名称 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief open device by device user defined name + # param self.handle [IN OUT] camera handle + # param chDeviceName [IN] device user defined name + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_OpenDeviceByName(self, chDeviceName): + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByName.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByName.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_OpenDeviceByName(HANDLE *handle, const char* chDeviceName); + return Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByName(byref(self.handle), chDeviceName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 通过序列号打开设备 + # param self.handle [IN OUT] 相机句柄 + # param chSerialNumber [IN] 序列号 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief open device by serial number + # param self.handle [IN OUT] camera handle + # param chSerialNumber [IN] serial number + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_OpenDeviceBySerialNumber(self, chSerialNumber): + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceBySerialNumber.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceBySerialNumber.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_OpenDeviceBySerialNumber(HANDLE *handle, const char* chSerialNumber); + return Mv3dRgbdDll.MV3D_RGBD_OpenDeviceBySerialNumber(byref(self.handle), chSerialNumber.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 通过IP打开设备,仅网口设备有效 + # param self.handle [IN OUT] 相机句柄 + # param chIP [IN] IP地址,例如"10.114.71.116" + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief open device by ip,only network device is valid + # param self.handle [IN OUT] camera handle + # param chIP [IN] IP, for example, "10.114.71.116" + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_OpenDeviceByIp(self, chIP): + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByIp.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByIp.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_OpenDeviceByIp(HANDLE *handle, const char* chIP); + return Mv3dRgbdDll.MV3D_RGBD_OpenDeviceByIp(byref(self.handle), chIP.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # param self.handle [IN] 相机句柄 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # param self.handle [IN] camera handle + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_CloseDevice(self): + Mv3dRgbdDll.MV3D_RGBD_CloseDevice.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_CloseDevice.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_CloseDevice(HANDLE *handle); + return Mv3dRgbdDll.MV3D_RGBD_CloseDevice(byref(self.handle)) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 获取当前设备的详细信息 + # param self.handle [IN] 相机句柄 + # param pstDevInfo [IN][OUT] 返回给调用者有关相机设备信息结构体指针 + # return 成功,MV3D_RGBD_OK,失败,返回错误码 + + # brief get current device information + # param self.handle [IN] camera handle + # param pstDevInfo [IN][OUT] structure pointer of device information + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetDeviceInfo(self, pstDevInfo): + Mv3dRgbdDll.MV3D_RGBD_GetDeviceInfo.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetDeviceInfo.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetDeviceInfo(HANDLE handle, MV3D_RGBD_DEVICE_INFO* pstDevInfo); + return Mv3dRgbdDll.MV3D_RGBD_GetDeviceInfo(self.handle, pstDevInfo) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 配置IP,仅网口设备有效 + # param chSerialNumber [IN] 序列号 + # param pstIPConfig [IN] IP配置,静态IP,DHCP等 + # return 成功,MV3D_RGBD_OK,失败,返回错误码 + + # brief ip configuration,only network device is valid + # param chSerialNumber [IN] serial number + # param pstIPConfig [IN] ip config, static ip,DHCP + # return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_SetIpConfig(chSerialNumber, pstIPConfig): + Mv3dRgbdDll.MV3D_RGBD_SetIpConfig.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_SetIpConfig.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SetIpConfig(const char* chSerialNumber, MV3D_RGBD_IP_CONFIG* pstIPConfig); + return Mv3dRgbdDll.MV3D_RGBD_SetIpConfig(chSerialNumber, pstIPConfig) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 注册图像数据回调 + # param self.handle [IN] 相机句柄 + # param cbOutput [IN] 回调函数指针 + # param pUser [IN] 用户自定义变量 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief register image data callback + # param self.handle [IN] camera handle + # param cbOutput [IN] callback function pointer + # param pUser [IN] user defined variable + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_RegisterFrameCallBack(self, cbOutput, pUser): + Mv3dRgbdDll.MV3D_RGBD_RegisterFrameCallBack.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_RegisterFrameCallBack.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_RegisterFrameCallBack(HANDLE handle, MV3D_RGBD_FrameDataCallBack cbOutput, void* pUser); + return Mv3dRgbdDll.MV3D_RGBD_RegisterFrameCallBack(self.handle, cbOutput, pUser) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 注册异常消息回调 + # param self.handle: [IN] 相机句柄 + # param cbException [IN] 异常回调函数指针 + # param pUser [IN] 用户自定义变量 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief register exception message callBack + # param self.handle: [IN] camera handle + # param cbException [IN] exception message callBack function pointer + # param pUser [IN] user defined variable + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_RegisterExceptionCallBack(self, cbException, pUser): + Mv3dRgbdDll.MV3D_RGBD_RegisterExceptionCallBack.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_RegisterExceptionCallBack.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_RegisterExceptionCallBack(HANDLE handle, MV3D_RGBD_ExceptionCallBack cbException, void* pUser); + return Mv3dRgbdDll.MV3D_RGBD_RegisterExceptionCallBack(self.handle, cbException, pUser) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 开始取流前获取数据流配置列表 + # param self.handle: [IN] 相机句柄 + # param pstStreamCfgList [IN] 返回给调用者数据流配置列表指针 + # return 成功,MV3D_RGBD_OK,失败,返回错误码 + + # brief get stream cfg list before start working + # param self.handle: [IN] camera handle + # param pstStreamCfgList [IN] structure pointer of stream cfg list + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetStreamCfgList(self, pstStreamCfgList): + Mv3dRgbdDll.MV3D_RGBD_GetStreamCfgList.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetStreamCfgList.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetStreamCfgList(HANDLE handle, MV3D_RGBD_STREAM_CFG_LIST* pstStreamCfgList); + return Mv3dRgbdDll.MV3D_RGBD_GetStreamCfgList(self.handle, pstStreamCfgList) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 开始工作 + # param self.handle [IN] 相机句柄 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief start working + # param self.handle [IN] camera handle + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_Start(self): + Mv3dRgbdDll.MV3D_RGBD_Start.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_Start.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_Start(HANDLE handle); + return Mv3dRgbdDll.MV3D_RGBD_Start(self.handle) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 停止工作 + # param self.handle [IN] 相机句柄 + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief stop working + # param self.handle [IN] camera handle + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_Stop(self): + Mv3dRgbdDll.MV3D_RGBD_Stop.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_Stop.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_Stop(HANDLE handle); + return Mv3dRgbdDll.MV3D_RGBD_Stop(self.handle) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 轮询方式获取帧数据 + # param self.handle [IN] 相机句柄 + # param pstFrameData [IN][OUT] 数据指针 + # param nTimeOut [IN] 超时时间(单位:毫秒) + # return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + # brief fetch frame data + # param self.handle [IN] camera handle + # param pstFrameData [IN][OUT] data set pointer + # param nTimeOut [IN] timevalue(Unit: ms) + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_FetchFrame(self, pstFrameData, nTimeOut): + Mv3dRgbdDll.MV3D_RGBD_FetchFrame.argtype = (c_void_p, c_void_p, c_uint) + Mv3dRgbdDll.MV3D_RGBD_FetchFrame.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_FetchFrame(HANDLE handle, MV3D_RGBD_FRAME_DATA* pstFrameData, uint32_t nTimeOut); + return Mv3dRgbdDll.MV3D_RGBD_FetchFrame(self.handle, pstFrameData, nTimeOut) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 执行设备软触发 + # param self.handle [IN] 相机句柄 + # return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + # remark 设置触发模式为打开,设置触发源为软触发并执行,软触发得到的图像帧包含触发id + + # brief execute camera soft trigger + # param self.handle [IN] camera handle + # return Success, return MV3D_RGBD_OK. Failure, return error code + # remark Set trigger mode to open, trigger source to software, and excute soft trigger. The image frame obtained by soft trigger contains the trigger id + def MV3D_RGBD_SoftTrigger(self): + Mv3dRgbdDll.MV3D_RGBD_SoftTrigger.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_SoftTrigger.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SoftTrigger(HANDLE handle); + return Mv3dRgbdDll.MV3D_RGBD_SoftTrigger(self.handle) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 执行带触发ID的设备软触发 + # param self.handle [IN] 相机句柄 + # param nTriggerId [IN] 触发ID + # return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + # remark 设置触发模式为打开,设置触发源为软触发并执行,软触发得到的图像帧包含触发id。 + # 通过对比输入的触发id参数与图像帧返回的触发id,判断当前帧是否有效 + + # brief execute camera soft trigger with trigger id + # param self.handle [IN] camera handle + # param nTriggerId [IN] trigger id + # return Success, return MV3D_RGBD_OK. Failure, return error code + # remark Set trigger mode to open, trigger source to software, and excute soft trigger. The image frame obtained by soft trigger contains the trigger id. + # Compare the input trigger id parameter with the returned trigger id to determine whether the current frame is valid + def MV3D_RGBD_SoftTriggerEx(self, nTriggerId): + Mv3dRgbdDll.MV3D_RGBD_SoftTriggerEx.argtype = (c_void_p, c_uint) + Mv3dRgbdDll.MV3D_RGBD_SoftTriggerEx.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SoftTriggerEx(HANDLE handle, uint32_t nTriggerId); + return Mv3dRgbdDll.MV3D_RGBD_SoftTriggerEx(self.handle, nTriggerId) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 执行设备Command命令 + # param self.handle [IN] 相机句柄 + # param strKey [IN] 属性键值 + # return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + # brief execute camera command + # param self.handle [IN] camera handle + # param strKey [IN] key value + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_Execute(self, strKey): + Mv3dRgbdDll.MV3D_RGBD_Execute.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_Execute.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_Execute(HANDLE handle, const char* strKey); + return Mv3dRgbdDll.MV3D_RGBD_Execute(self.handle, strKey.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 获取相机当前标定信息 + # param self.handle [IN] 相机句柄 + # param nCoordinateType [IN] 坐标系类型,见Mv3dRgbdCoordinateType + # param pstCalibInfo [IN][OUT] 输出标定信息 + # return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + # brief get camera current calibration info + # param self.handle [IN] camera handle + # param nCoordinateType [IN] coordinate Type,refer to Mv3dRgbdCoordinateType + # param pstCalibInfo [IN][OUT] calibration Info + # return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetCalibInfo(self, nCoordinateType, pstCalibInfo): + Mv3dRgbdDll.MV3D_RGBD_GetCalibInfo.argtype = (c_void_p, c_uint, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetCalibInfo.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetCalibInfo(HANDLE handle, uint32_t nCoordinateType, MV3D_RGBD_CALIB_INFO *pstCalibInfo); + return Mv3dRgbdDll.MV3D_RGBD_GetCalibInfo(self.handle, nCoordinateType, pstCalibInfo) + # ******************************************************************************************************* + + # ******************************************************************************************************* + # brief 获取相机内外参信息 + # param handle [IN] 相机句柄 + # param pstCameraParam [IN][OUT] 输出相机内/外参数信息 + # return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + # brief get camera intrinsic and extrinsic information + # param handle [IN] camera handle + # param pstCameraParam [IN][OUT] camera intrinsic and extrinsic Info + def MV3D_RGBD_GetCameraParam(self, pstCameraParam): + Mv3dRgbdDll.MV3D_RGBD_GetCameraParam.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetCameraParam.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetCameraParam(HANDLE handle, MV3D_RGBD_CAMERA_PARAM *pstCameraParam); + return Mv3dRgbdDll.MV3D_RGBD_GetCameraParam(self.handle, pstCameraParam) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 设备升级 + #param handle [IN] 相机句柄 + #param pFilePathName [IN] 文件名 + #return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + #brief device upgrade + #param handle [IN] camera handle + #param pFilePathName [IN] file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_LocalUpgrade(self, pFilePathName): + Mv3dRgbdDll.MV3D_RGBD_LocalUpgrade.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_LocalUpgrade.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_LocalUpgrade(HANDLE handle, const char* pFilePathName); + return Mv3dRgbdDll.MV3D_RGBD_LocalUpgrade(self.handle, pFilePathName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 获取升级进度 + #param handle [IN] 相机句柄 + #param pProcess [OUT] 进度接收地址 + #return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + #brief get upgrade progress + #param handle [IN] camera handle + #param pProcess [OUT] progress receiving address + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetUpgradeProcess(self, pProcess): + Mv3dRgbdDll.MV3D_RGBD_GetUpgradeProcess.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetUpgradeProcess.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetUpgradeProcess(HANDLE handle, uint32_t* pProcess); + return Mv3dRgbdDll.MV3D_RGBD_GetUpgradeProcess(self.handle, pProcess) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 获取相机参数值 + #param handle [IN] 相机句柄 + #param strKey [IN] 属性键值 + #param pstParam [IN] 返回的相机参数结构体指针 + #return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + #brief get camera param value + #param handle [IN] camera handle + #param strKey [IN] key value + #param pstParam [IN] structure pointer of camera param + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetParam(self, strkey, pstParam): + Mv3dRgbdDll.MV3D_RGBD_GetParam.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetParam.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetParam(HANDLE handle, const char* strKey, MV3D_RGBD_PARAM* pstParam); + return Mv3dRgbdDll.MV3D_RGBD_GetParam(self.handle, strkey.encode('ascii'), pstParam) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 设置相机参数值 + #param handle [IN] 相机句柄 + #param strKey [IN] 属性键值 + #param pstParam [IN] 输入的相机参数结构体指针 + #return 成功,返回MV3D_RGBD_OK,失败,返回错误码 + + #brief set camera param value + #param handle [IN] camera handle + #param strKey [IN] key value + #param pstParam [IN] structure pointer of camera param + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_SetParam(self, strkey, pstParam): + Mv3dRgbdDll.MV3D_RGBD_SetParam.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_SetParam.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SetParam(HANDLE handle, const char* strKey, MV3D_RGBD_PARAM* pstParam); + return Mv3dRgbdDll.MV3D_RGBD_SetParam(self.handle, strkey.encode('ascii'), pstParam) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 导出相机参数 + #param handle [IN] 相机句柄 + #param pOutFileName [IN] 导出文件名称 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief export camera param + #param handle [IN] camera handle + #param pOutFileName [IN] export file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_ExportAllParam(self, pOutFileName): + Mv3dRgbdDll.MV3D_RGBD_ExportAllParam.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_ExportAllParam.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_ExportAllParam(HANDLE handle, const char* pOutFileName); + return Mv3dRgbdDll.MV3D_RGBD_ExportAllParam(self.handle, pOutFileName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 导入相机参数 + #param handle [IN] 相机句柄 + #param pInFileName [IN] 导入文件名称 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief import camera param + #param handle [IN] camera handle + #param pInFileName [IN] import file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_ImportAllParam(self, pInFileName): + Mv3dRgbdDll.MV3D_RGBD_ImportAllParam.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_ImportAllParam.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_ImportAllParam(HANDLE handle, const char* pInFileName); + return Mv3dRgbdDll.MV3D_RGBD_ImportAllParam(self.handle, pInFileName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 从相机读取文件 + #param handle [IN] 相机句柄 + #param pstFileAccess [IN] 文件存取结构体 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief read the file from the camera + #param handle [IN] camera handle + #param pstFileAccess [IN] file access structure + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_FileAccessRead(self, pstFileAccess): + Mv3dRgbdDll.MV3D_RGBD_FileAccessRead.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_FileAccessRead.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_FileAccessRead(void* handle, MV3D_RGBD_FILE_ACCESS * pstFileAccess); + return Mv3dRgbdDll.MV3D_RGBD_FileAccessRead(self.handle, pstFileAccess) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 将文件写入相机 + #param handle [IN] 相机句柄 + #param pstFileAccess [IN] 文件存取结构体 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief write the file to camera + #param handle [IN] camera handle + #param pstFileAccess [IN] file access structure + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_FileAccessWrite(self, pstFileAccess): + Mv3dRgbdDll.MV3D_RGBD_FileAccessWrite.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_FileAccessWrite.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_FileAccessWrite(void* handle, MV3D_RGBD_FILE_ACCESS * pstFileAccess); + return Mv3dRgbdDll.MV3D_RGBD_FileAccessWrite(self.handle, pstFileAccess) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 获取文件存取的进度 + #param handle [IN] 相机句柄 + #param pstFileAccessProgress [IN] 文件存取进度结构体 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief get file access progress + #param handle [IN] camera handle + #param pstFileAccessProgress [IN] file access progress structure + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_GetFileAccessProgress(self, pstFileAccessProgress): + Mv3dRgbdDll.MV3D_RGBD_GetFileAccessProgress.argtype = (c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_GetFileAccessProgress.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_GetFileAccessProgress(void* handle, MV3D_RGBD_FILE_ACCESS_PROGRESS * pstFileAccessProgress); + return Mv3dRgbdDll.MV3D_RGBD_GetFileAccessProgress(self.handle, pstFileAccessProgress) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 检查相机功能支持情况 + #param handle [IN] 相机句柄 + #param enFuncType [IN] 功能类型 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + #remark 调用该接口检查相机是否支持某项功能,例如检查相机是否支持触发id功能,如果支持,则后续可以调用MV3D_RGBD_SoftTriggerEx接口,执行带触发id的软触发 + + #brief check camera function support + #param handle [IN] camera handle + #param enFuncType [IN] function type + #return Success, return MV3D_RGBD_OK. Failure, return error code + #remark Call this interface to check whether the camera supports a certain function, for example, check whether the camera supports the trigger id function. + # If camera supports the trigger id function, you can call the MV3D_RGBD_SoftTriggerEx interface to execute the soft trigger with the trigger id + def MV3D_RGBD_CheckCameraFuncSupport(self, enFuncType): + Mv3dRgbdDll.MV3D_RGBD_CheckCameraFuncSupport.argtype = (c_void_p, c_uint) + Mv3dRgbdDll.MV3D_RGBD_CheckCameraFuncSupport.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_CheckCameraFuncSupport(void* handle, Mv3dRgbdFunctionType enFuncType); + return Mv3dRgbdDll.MV3D_RGBD_CheckCameraFuncSupport(self.handle, enFuncType) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 清除数据缓存 + #param handle [IN] 相机句柄 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief clear data buffer + #param handle [IN] camera handle + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_ClearDataBuffer(self): + Mv3dRgbdDll.MV3D_RGBD_ClearDataBuffer.argtype = c_void_p + Mv3dRgbdDll.MV3D_RGBD_ClearDataBuffer.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_ClearDataBuffer(void* handle); + return Mv3dRgbdDll.MV3D_RGBD_ClearDataBuffer(self.handle) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief RGBD相机深度图像转换点云图像 + #param handle [IN] 相机句柄 + #param pstDepthImage [IN] 深度图数据 + #param pstPointCloudImage [OUT] 点云图数据 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief depth image convert to pointcloud image + #param handle [IN] camera handle + #param pstDepthImage [IN] depth data + #param pstPointCloudImage [OUT] point cloud data + #return Success, return MV3D_RGBD_OK. Failure,return error code + def MV3D_RGBD_MapDepthToPointCloud(self, pstDepthImage, pstPointCloudImage): + Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloud.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloud.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_MapDepthToPointCloud(void* handle, MV3D_RGBD_IMAGE_DATA* pstDepthImage, MV3D_RGBD_IMAGE_DATA* pstPointCloudImage); + return Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloud(self.handle, pstDepthImage, pstPointCloudImage) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief RGBD相机深度图像转换点云图像(无句柄) + #param pstDepthImage [IN] 深度图数据 + #param pstCalibInfo [IN] 标定信息 + #param fZunit [IN] 深度图量纲(mm) + #param pstPointCloudImage [OUT] 点云图数据 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief depth image convert to pointcloud image without handle + #param pstDepthImage [IN] depth data + #param pstCalibInfo [IN] calib info + #param fZunit [IN] dimension(mm) + #param pstPointCloudImage [OUT] point cloud data + #return Success, return MV3D_RGBD_OK. Failure,return error code + @staticmethod + def MV3D_RGBD_MapDepthToPointCloudEx(pstDepthImage, pstCalibInfo, fZunit, pstPointCloudImage): + Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloudEx.argtype = (c_void_p, c_void_p, c_float, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloudEx.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_MapDepthToPointCloudEx(MV3D_RGBD_IMAGE_DATA* pstDepthImage, MV3D_RGBD_CALIB_INFO* pstCalibInfo, float fZunit, MV3D_RGBD_IMAGE_DATA* pstPointCloudImage); + return Mv3dRgbdDll.MV3D_RGBD_MapDepthToPointCloudEx(pstDepthImage, pstCalibInfo, ctypes.c_float(fZunit), pstPointCloudImage) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 图像坐标系转换 + #param pstInImage [IN] 输入图像数据 + #param fZunit [IN] 深度图量纲(mm) + #param pstOutImage [OUT] 输出图像数据 + #param pstCameraParam [IN][OUT] 相机内/外参数信息 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief image convert coordinate to rgb coordinate + #param pstInImage [IN] input image data + #param fZunit [IN] dimension(mm) + #param pstOutImage [OUT] output image data + #param pstCameraParam [IN][OUT] camera intrinsic and extrinsic Info + #return Success, return MV3D_RGBD_OK. Failure,return error code + @staticmethod + def MV3D_RGBD_ImageCoordinateTrans(pstInImage, fZunit, pstOutImage, pstCameraParam): + Mv3dRgbdDll.MV3D_RGBD_ImageCoordinateTrans.argtype = (c_void_p, c_float, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_ImageCoordinateTrans.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_ImageCoordinateTrans(MV3D_RGBD_IMAGE_DATA* pstInImage, float fZunit, MV3D_RGBD_IMAGE_DATA* pstOutImage, MV3D_RGBD_CAMERA_PARAM* pstCameraParam); + return Mv3dRgbdDll.MV3D_RGBD_ImageCoordinateTrans(pstInImage, ctypes.c_float(fZunit), pstOutImage, pstCameraParam) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 深度图,RGB图和原始图存图接口 + # 深度图格式:C16 + # RGB图格式:RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + # 原始图格式:Mono8(仅支持bmp格式) + #param handle [IN] 相机句柄 + #param pstImage [IN] 图像数据 + #param enFileType [IN] 文件类型 + #param chFileName [IN] 文件名称 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief depth and rgb image save image to file + # depth image format: C16 + # rgb image format: RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + # mono image format: Mono8(only support bmp file type) + #param handle [IN] camera handle + #param pstImage [IN] image data + #param enFileType [IN] file type + #param chFileName [IN] file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_SaveImage(self, pstImage, enFileType, chFileName): + Mv3dRgbdDll.MV3D_RGBD_SaveImage.argtype = (c_void_p, c_void_p, c_int, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_SaveImage.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SaveImage(void* handle, MV3D_RGBD_IMAGE_DATA* pstImage, Mv3dRgbdFileType enFileType, const char* chFileName); + return Mv3dRgbdDll.MV3D_RGBD_SaveImage(self.handle, pstImage, enFileType, chFileName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 点云图存图接口 + #param handle [IN] 相机句柄 + #param pstImage [IN] 图像数据 + #param enPointCloudFileType [IN] 点云图文件类型 + #param chFileName [IN] 文件名称 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief pointcloud image save image to file + #param handle [IN] camera handle + #param pstImage [IN] image data + #param enPointCloudFileType [IN] pointcloud image file type + #param chFileName [IN] file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_SavePointCloudImage(self, pstImage, enPointCloudFileType, chFileName): + Mv3dRgbdDll.MV3D_RGBD_SavePointCloudImage.argtype = (c_void_p, c_void_p, c_int, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_SavePointCloudImage.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SavePointCloudImage(void* handle, MV3D_RGBD_IMAGE_DATA* pstImage, Mv3dRgbdPointCloudFileType enPointCloudFileType, const char* chFileName); + return Mv3dRgbdDll.MV3D_RGBD_SavePointCloudImage(self.handle, pstImage, enPointCloudFileType, chFileName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 纹理点云存图接口 + # 纹理图格式: RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + # 保存的点云图格式: PLY_ASCII/PLC_Binary/PCD_ASCII/PCD_Binary + #param handle [IN] 相机句柄 + #param pstPointCloudImage [IN] 点云图像数据 + #param pstTexture [IN] 图像纹理数据 + #param enPointCloudFileType [IN] 点云图文件类型 + #param chFileName [IN] 文件名称 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief textured pointcloud image save image to file + # texture image format:RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + # point cloud file type: PLY_ASCII/PLC_Binary/PCD_ASCII/PCD_Binary + #param handle [IN] camera handle + #param pstPointCloudImage [IN] pointcloude image data + #param pstTexture [IN] image texture data + #param enPointCloudFileType [IN] pointcloud image file type + #param chFileName [IN] file name + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_SaveTexturedPointCloudImage(self, pstPointCloudImage, pstTexture, enPointCloudFileType, chFileName): + Mv3dRgbdDll.MV3D_RGBD_SaveTexturedPointCloudImage.argtype = (c_void_p, c_void_p, c_void_p, c_int, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_SaveTexturedPointCloudImage.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_SaveTexturedPointCloudImage(void* handle, MV3D_RGBD_IMAGE_DATA* pstPointCloudImage, MV3D_RGBD_IMAGE_DATA* pstTexture, Mv3dRgbdPointCloudFileType enPointCloudFileType, const char* chFileName); + return Mv3dRgbdDll.MV3D_RGBD_SaveTexturedPointCloudImage(self.handle, pstPointCloudImage, pstTexture, enPointCloudFileType, chFileName.encode('ascii')) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 显示深度和RGB图像接口 + # 深度图格式:C16 + # RGB图格式:RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + #param handle [IN] 相机句柄 + #param pstImage [IN] 图像数据 + #param hWnd [IN] 窗口句柄 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief display depth and rgb image + # depth image format: C16 + # rgb image format: RGB8_Planar/YUV422/YUV420SP_NV12/YUV420SP_NV21 + #param handle [IN] camera handle + #param pstImage [IN] image data + #param hWnd [IN] windows handle + #return Success, return MV3D_RGBD_OK. Failure, return error code + def MV3D_RGBD_DisplayImage(self, pstImage, hWnd): + Mv3dRgbdDll.MV3D_RGBD_DisplayImage.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_DisplayImage.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_DisplayImage(void* handle, MV3D_RGBD_IMAGE_DATA* pstImage, void* hWnd) + return Mv3dRgbdDll.MV3D_RGBD_DisplayImage(self.handle, pstImage, hWnd) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 深度图转伪彩图接口 + # 深度图格式:C16 + # 伪彩图格式:RGB8_Planar + #param pstDepthImage [IN] 深度图像数据 + #param pstConvertParam [IN] 深度图转伪彩配置参数 + #param pstColorImage [OUT] 伪彩图像数据 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief display depth and rgb image + # depth image format: C16 + # rgb image format: RGB8_Planar + #param pstDepthImage [IN] depth image data + #param pstConvertParam [IN] depth convert to color image parameters + #param pstColorImage [OUT] color image data + #return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_MapDepthToColor(pstDepthImage, pstConvertParam, pstColorImage): + Mv3dRgbdDll.MV3D_RGBD_MapDepthToColor.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_MapDepthToColor.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_MapDepthToColor(MV3D_RGBD_IMAGE_DATA* pstDepthImage, MV3D_RGBD_CONVERT_COLOR_PAPRAM* pstConvertParam, MV3D_RGBD_IMAGE_DATA* pstColorImage) + return Mv3dRgbdDll.MV3D_RGBD_MapDepthToColor(pstDepthImage, pstConvertParam, pstColorImage) + # ******************************************************************************************************* + + # ******************************************************************************************************* + #brief 点云转UV坐标接口 + #param pstCloudPointImage [IN] 点云图像数据 + #param pstCalibInfo [IN] 标定参数 + #param pstUVMap [OUT] UV坐标数据 + #return 成功,返回MV3D_RGBD_OK;错误,返回错误码 + + #brief convert point cloud to uv coordinate + #param pstCloudPointImage [IN] point cloud image data + #param pstCalibInfo [IN] calib info + #param pstUVMap [OUT] uv coordinate data + #return Success, return MV3D_RGBD_OK. Failure, return error code + @staticmethod + def MV3D_RGBD_MapPointCloudToUV(pstCloudPointImage, pstCalibInfo, pstUvMap): + Mv3dRgbdDll.MV3D_RGBD_MapPointCloudToUV.argtype = (c_void_p, c_void_p, c_void_p) + Mv3dRgbdDll.MV3D_RGBD_MapPointCloudToUV.restype = c_uint + # C:MV3D_RGBD_API MV3D_RGBD_STATUS MV3D_RGBD_MapPointCloudToUV(MV3D_RGBD_IMAGE_DATA* pstCloudPointImage, MV3D_RGBD_CALIB_INFO* pstCalibInfo, MV3D_RGBD_UV_DATA* pstUvMap) + return Mv3dRgbdDll.MV3D_RGBD_MapPointCloudToUV(pstCloudPointImage, pstCalibInfo, pstUvMap) + # ******************************************************************************************************* diff --git a/Mv3dRgbdImport/Mv3dRgbdDefine.py b/Mv3dRgbdImport/Mv3dRgbdDefine.py new file mode 100644 index 0000000..9980bc4 --- /dev/null +++ b/Mv3dRgbdImport/Mv3dRgbdDefine.py @@ -0,0 +1,627 @@ +# -- coding: utf-8 -- +from ctypes import * + +STRING = c_char_p +int8_t = c_int8 +int16_t = c_int16 +int32_t = c_int32 +int64_t = c_int64 +uint8_t = c_uint8 +uint16_t = c_uint16 +uint32_t = c_uint32 +uint64_t = c_uint64 +int_least8_t = c_byte +int_least16_t = c_short +int_least32_t = c_int +int_least64_t = c_long +uint_least8_t = c_ubyte +uint_least16_t = c_ushort +uint_least32_t = c_uint +uint_least64_t = c_ulong +int_fast8_t = c_byte +int_fast16_t = c_long +int_fast32_t = c_long +int_fast64_t = c_long +uint_fast8_t = c_ubyte +uint_fast16_t = c_ulong +uint_fast32_t = c_ulong +uint_fast64_t = c_ulong +intptr_t = c_long +uintptr_t = c_ulong +intmax_t = c_long +uintmax_t = c_ulong + +MV3D_RGBD_UNDEFINED = -1 +# ch: 状态码 | en: Status Code +# ch: 正确码定义 | en: Definition of correct code +MV3D_RGBD_OK = 0 #~chinese 成功,无错误 ~english Successed, no error + +# ch: 通用错误码定义:范围0x80060000-0x800600FF | en: Definition of General Error Code (from 0x80060000 to 0x800600FF) +MV3D_RGBD_E_HANDLE = 0x80060000 #~chinese 错误或无效的句柄 ~english Incorrect or invalid handle +MV3D_RGBD_E_SUPPORT = 0x80060001 #~chinese 不支持的功能 ~english The function is not supported +MV3D_RGBD_E_BUFOVER = 0x80060002 #~chinese 缓存已满 ~english The buffer is full +MV3D_RGBD_E_CALLORDER = 0x80060003 #~chinese 函数调用顺序错误 ~english Incorrect calling sequence +MV3D_RGBD_E_PARAMETER = 0x80060004 #~chinese 错误的参数 ~english Incorrect parameter +MV3D_RGBD_E_RESOURCE = 0x80060005 #~chinese 资源申请失败 english Resource request failed +MV3D_RGBD_E_NODATA = 0x80060006 #~chinese 无数据 ~english No data +MV3D_RGBD_E_PRECONDITION = 0x80060007 #~chinese 前置条件有误,或运行环境已发生变化 ~english Incorrect precondition, or running environment has changed +MV3D_RGBD_E_VERSION = 0x80060008 #~chinese 版本不匹配 ~english The version mismatched +MV3D_RGBD_E_NOENOUGH_BUF = 0x80060009 #~chinese 传入的内存空间不足 ~english Insufficient memory +MV3D_RGBD_E_ABNORMAL_IMAGE = 0x8006000A #~chinese 异常图像,可能是丢包导致图像不完整 ~english Abnormal image. Incomplete image caused by packet loss +MV3D_RGBD_E_LOAD_LIBRARY = 0x8006000B #~chinese 动态导入DLL失败 ~english Failed to load the dynamic link library dynamically +MV3D_RGBD_E_ALGORITHM = 0x8006000C #~chinese 算法错误 ~english Algorithm error +MV3D_RGBD_E_DEVICE_OFFLINE = 0x8006000D #~chinese 设备离线 ~english The device is offline +MV3D_RGBD_E_ACCESS_DENIED = 0x8006000E #~chinese 设备无访问权限 ~english No device access permission +MV3D_RGBD_E_OUTOFRANGE = 0x8006000F #~chinese 值超出范围 ~english The value is out of range + +MV3D_RGBD_E_UPG_FILE_MISMATCH = 0x80060010 #~chinese 升级固件不匹配 ~english The upgraded firmware does not match +MV3D_RGBD_E_UPG_CONFLICT = 0x80060012 #~chinese 升级冲突 ~english The upgraded firmware conflict +MV3D_RGBD_E_UPG_INNER_ERR = 0x80060013 #~chinese 升级时相机内部出现错误 ~english An error occurred inside the camera during the upgrade + +MV3D_RGBD_E_INDUSTRY = 0x80060020 #~chinese 行业属性不匹配 ~english The industry attributes does not match +MV3D_RGBD_E_NETWORK = 0x80060021 #~chinese 网络相关错误 ~english Network related error + +MV3D_RGBD_E_USB_WRITE = 0x80060030 #~chinese 写USB出错 ~english Writing USB error + +MV3D_RGBD_E_UNKNOW = 0x800600FF #~chinese 未知的错误 ~english Unknown error + +# ch: 常量定义 | en: Macro Definition +MV3D_RGBD_MAX_IMAGE_COUNT = 10 #~chinese 最大图片个数 ~english The maximum number of images +MV3D_RGBD_MAX_STRING_LENGTH = 256 #~chinese 最大字符串长度 ~english The maximum length of string +MV3D_RGBD_MAX_PATH_LENGTH = 256 #~chinese 最大路径长度 ~english The maximum length of path +MV3D_RGBD_MAX_ENUM_COUNT = 16 #~chinese 最大枚举数量 ~english The maximum number of enumerations + +# ch: 像素类型 | en: Pixel Type +MV3D_RGBD_PIXEL_MONO = 0x01000000 #~chinese Mono像素格式 ~english Mono pixel format +MV3D_RGBD_PIXEL_COLOR = 0x02000000 #~chinese Color像素格式 ~english Color pixel format +MV3D_RGBD_PIXEL_CUSTOM = 0x80000000 #~chinese 自定义像素格式 ~english Custom pixel format + +# ch:设备属性key值相关定义 | en: Attribute Key Value Definition +MV3D_RGBD_INT_WIDTH = "Width" #~chinese 图像宽 ~english Image width +MV3D_RGBD_INT_HEIGHT = "Height" #~chinese 图像高 ~english Image height +MV3D_RGBD_ENUM_WORKINGMODE = "CameraWorkingMode" #~chinese 工作模式 ~english The camera working mode +MV3D_RGBD_ENUM_PIXELFORMAT = "PixelFormat" #~chinese 像素格式 ~english Pixel format +MV3D_RGBD_ENUM_IMAGEMODE = "ImageMode" #~chinese 图像模式 ~english Image mode +MV3D_RGBD_FLOAT_GAIN = "Gain" #~chinese 增益 ~english Gain +MV3D_RGBD_FLOAT_EXPOSURETIME = "ExposureTime" #~chinese 曝光时间 ~english Exposure time +MV3D_RGBD_FLOAT_FRAMERATE = "AcquisitionFrameRate" #~chinese 采集帧率 ~english Acquired frame rate +MV3D_RGBD_ENUM_TRIGGERSELECTOR = "TriggerSelector" #~chinese 触发选择器 ~english Trigger selector +MV3D_RGBD_ENUM_TRIGGERMODE = "TriggerMode" #~chinese 触发模式 ~english Trigger mode +MV3D_RGBD_ENUM_TRIGGERSOURCE = "TriggerSource" #~chinese 触发源 ~english Trigger source +MV3D_RGBD_FLOAT_TRIGGERDELAY = "TriggerDelay" #~chinese 触发延迟时间 ~english Trigger delay +MV3D_RGBD_INT_IMAGEALIGN = "ImageAlign" #~chinese 对齐坐标系(默认值1:对齐到彩色图坐标系;0:不对齐;2:对齐到深度图坐标系),重启程序后恢复默认值 + #~english Whether to align the depth image with RGB image: 1 (align, default value), 0 (not align). The default value will be restored after rebooting +MV3D_RGBD_BOOL_LASERENABLE = "LaserEnable" #~chinese 投射器使能 ~english Open or close laser control +Mv3D_RGBD_FLOAT_BASEDISTANCE = "BaseDistance" #~chinese 左右目基线距 ~english Left and right eyes base distance +MV3D_RGBD_ENUM_RESOLUTION = "BinningSelector" #~chinese 采集分辨率 ~english Acquisition resolution +MV3D_RGBD_INT_OUTPUT_RGBD = "OutputRgbd" #~chinese RGBD图像输出(默认值0:不输出;1:输出),重启程序后恢复默认值 + #~english Whether to output rgbd image: 1 (not output, default value), 0 (output). The default value will be restored after rebooting +MV3D_RGBD_INT_DEVICE_TIMEOUT = "DeviceTimeout" #~chinese 设备控制超时时间(ms) ~english Timeout period of device control (unit: ms) +MV3D_RGBD_INT_IMAGE_NODE_NUM = "ImageNodeNum" #~chinese 图像缓存节点个数 ~english The number of image buffer node +MV3D_RGBD_FLOAT_Z_UNIT = "ZUnit" #~chinese 深度图量纲(mm) ~english The dimension of depth image (unit: mm) +MV3D_RGBD_ENUM_POINT_CLOUD_OUTPUT = "PointCloudOutput" #~chinese 输出点云数据类型,详见Mv3dRgbdPointCloudType ~english The types of output point cloud. Refer to Mv3dRgbdPointCloudType +MV3D_RGBD_INT_DOWNSAMPLE = "DownSample" #~chinese 降采样参数(默认值0:不输出;1:图像宽高降低一半) ~english Down sampling param: 0 (output original data), 1 (output half width and height) + +# ch:设备文件枚举常量 | en: File Constant Definition +MV3D_RGBD_SENSOR_CALI = "RGBDSensorCali" #~chinese 相机传感器标定文件 ~english The calibration file of camera sensor +MV3D_RGBD_HANDEYE_CALI = "RGBDHandEyeCali" #~chinese 相机手眼标定文件 ~english The camera hand-eye calibration file + +# Mv3dRgbdDeviceType +# ch:设备类型 | en: Device Type +DeviceType_Ethernet = 1 #~chinese 网口设备 ~english Network type camera +DeviceType_USB = 2 #~chinese USB设备 ~english USB type camera +DeviceType_Ethernet_Vir = 4 #~chinese 虚拟网口设备 ~english Virtual network type camera +DeviceType_USB_Vir = 8 #~chinese 虚拟USB设备 ~english Virtual USB type camera + +# Mv3dRgbdIpCfgMode +# ch:ip类型 | en: IP Address Mode +IpCfgMode_Static = 1 #~chinese 静态IP ~english Static IP mode +IpCfgMode_DHCP = 2 #~chinese 自动分配IP(DHCP) ~english Automatically assigned IP address (DHCP) +IpCfgMode_LLA = 4 #~chinese 自动分配IP(LLA) ~english Automatically assigned IP address (LLA) + +# Mv3dRgbdUsbProtocol +# ch:USB协议 | en: Supported USB Protocol Type +UsbProtocol_USB2 = 1 #~chinese USB2协议 ~english USB 2.0 +UsbProtocol_USB3 = 2 #~chinese USB3协议 ~english USB 3.0 + +# Mv3dRgbdImageType +# ch:图像格式 | en:Image Format +ImageType_Undefined = -1 #~chinese 未定义 ~english Undefined +ImageType_Mono8 = 17301505 #~chinese Mono8 ~english Mono8 +ImageType_Mono16 = 17825799 #~chinese Mono16 ~english Mono16 +ImageType_Depth = 17825976 #~chinese C16 ~english C16 +ImageType_YUV422 = 34603058 #~chinese YUV422 ~english YUV422 +ImageType_YUV420SP_NV12 = 34373633 #~chinese YUV420SP_NV12 ~english YUV420SP_NV12 +ImageType_YUV420SP_NV21 = 34373634 #~chinese YUV420SP_NV21 ~english YUV420SP_NV21 +ImageType_RGB8_Planar = 35127329 #~chinese RGB8_Planar ~english RGB8_Planar +ImageType_PointCloud = 39846080 #~chinese ABC32f ~english ABC32f +ImageType_PointCloudWithNormals = -2134900735 #~chinese MV3D_RGBD_POINT_XYZ_NORMALS ~english MV3D_RGBD_POINT_XYZ_NORMALS +ImageType_TexturedPointCloud = -2139619326 #~chinese MV3D_RGBD_POINT_XYZ_RGB ~english MV3D_RGBD_POINT_XYZ_RGB +ImageType_TexturedPointCloudWithNormals = -2133327869 #~chinese MV3D_RGBD_POINT_XYZ_RGB_NORMALS ~english MV3D_RGBD_POINT_XYZ_RGB_NORMALS +ImageType_Jpeg = -2145910783 #~chinese Jpeg ~english Jpeg +ImageType_Rgbd = -2111295481 #~chinese RGBD ~english RGBD + +# Mv3dRgbdStreamType +# ch:数据流类型 | en: Data Stream Type +StreamType_Undefined = 0 +StreamType_Depth = 1 #~chinese 深度图数据流 ~english Depth image data stream +StreamType_Color = 2 #~chinese Color图数据流 ~english Color image data stream +StreamType_Ir_Left = 3 #~chinese 矫正后的左目图数据流 ~english Corrected left-eye image data stream +StreamType_Ir_Right = 4 #~chinese 矫正后的右目图数据流 ~english Corrected right-eye image data stream +StreamType_Imu = 5 #~chinese IMU数据流 ~english IMU data stream +StreamType_LeftMono = 6 #~chinese 左目泛光图数据流 ~english Illuminated left-eye image data stream +StreamType_Mask = 7 #~chinese 掩膜图数据流 ~english Mask image data stream +StreamType_Mono = 8 #~chinese 未矫正的左右目融合图数据流 ~english Uncorrected left and right eyes fusion image data stream +StreamType_Phase = 9 #~chinese 相位图数据流 ~english Phase image data stream +StreamType_Rgbd = 10 #~chinese RGB-D图数据流 ~english RGB-D image data stream + +# Mv3dRgbdCoordinateType +# ch:坐标系类型 | en:Coordinates Type +CoordinateType_Undefined = 0 #~chinese 坐标系未定义 ~english Undefined coordinates +CoordinateType_Depth = 1 #~chinese 深度图坐标系 ~english Depth image coordinates +CoordinateType_RGB = 2 #~chinese RGB图坐标系 ~english RGB image coordinates + +# Mv3dRgbdDevException +# ch:异常信息 | en:Exception Information +DevException_Disconnect = 1 #~chinese 设备断开连接 ~english The device is disconnected + +# Mv3dRgbdParamType +# ch:参数类型 | en:Parameter Data Type +ParamType_Bool = 1 #~chinese Bool类型参数 ~english Boolean +ParamType_Int = 2 #~chinese Int类型参数 ~english Int +ParamType_Float = 3 #~chinese Float类型参数 ~english Float +ParamType_Enum = 4 #~chinese Enum类型参数 ~english Enumeration +ParamType_String = 5 #~chinese String类型参数 ~english String + +# Mv3dRgbdFileType +# ch:深度图与rgb图存图格式 | en: Format of Saving Depth Images and RGB Images +FileType_BMP = 1 #~chinese BMP格式 ~english BMP +FileType_JPG = 2 #~chinese JPG格式 ~english JPG +FileType_TIFF = 3 #~chinese TIFF格式 ~english TIFF + +# Mv3dRgbdPointCloudFileType +# ch:点云图存图格式 | en:Formats of Saving Point Cloud Images +PointCloudFileType_PLY = 1 #~chinese PLY_ASCII格式 ~english PLY(ascii) +PointCloudFileType_CSV = 2 #~chinese CSV格式 ~english CSV +PointCloudFileType_OBJ = 3 #~chinese OBJ格式 ~english OBJ +PointCloudFileType_PLY_Binary = 4 #~chinese PLY_BINARY格式 ~english PLY(binary) +PointCloudFileType_PCD_ASCII = 5 #~chinese PCD_ASCII格式 ~english PCD(ascii) +PointCloudFileType_PCD_Binary = 6 #~chinese PCD_BINARY格式 ~english PCD(binary) + +# Mv3dRgbdPointCloudType +# ch:输出点云图像类型 | en:Types of Output Point Cloud Data +PointCloudType_Undefined = 0 #~chinese 不输出点云 ~english Output without point cloud +PointCloudType_Common = 1 #~chinese 点云图像 ~english Point cloud image +PointCloudType_Normals = 2 #~chinese 带法向量信息的点云图像 ~english Point cloud image with normals +PointCloudType_Texture = 3 #~chinese 纹理点云图像 ~english Textured point cloud image +PointCloudType_Texture_Normals = 4 #~chinese 带法向量的纹理点云图像 ~english Textured point cloud image with normals + +# Mv3dRgbdConvertColorMapMode +# ch:伪彩图转换映射模式 | en:Convert Color Image Mapping Mode +ConvertColorMapMode_Rainbow = 1 #~chinese 彩色 ~english Rainbow +ConvertColorMapMode_Dark_Rainbow = 2 #~chinese 暗彩色 ~english Dark rainbow +ConvertColorMapMode_Dark_Green = 3 #~chinese 暗绿色 ~english Dark green +ConvertColorMapMode_Pinkish_Red = 4 #~chinese 粉红色 ~english Pinkish red +ConvertColorMapMode_Yellow = 5 #~chinese 黄色 ~english Yellow +ConvertColorMapMode_Gray_Scale = 6 #~chinese 灰度 ~english Gray scale + +# Mv3dRgbdConvertColorRangeMode +# ch:伪彩图转换范围模式 | en:Convert Color Image Range Mode +ConvertColorRangeMode_Auto = 0 #~chinese 自动 ~english Auto +ConvertColorRangeMode_Abs = 1 #~chinese 绝对值 ~english Absolute value +ConvertColorRangeMode_Percentage = 2 #~chinese 百分比 ~english Percentage + +# Mv3dRgbdFunctionType +# ch:功能类型 | en:Function Type +FunctionType_TriggerId = 1 #~chinese 触发id ~english Trigger ID + +# ch:版本信息 | en:SDK Version Information +class _MV3D_RGBD_VERSION_INFO_(Structure): + pass +_MV3D_RGBD_VERSION_INFO_._fields_ = [ + ('nMajor', c_uint), #~chinese 主版本 ~english The main version + ('nMinor', c_uint), #~chinese 次版本 ~english The minor version + ('nRevision', c_uint), #~chinese 修正版本 ~english The revision version +] +MV3D_RGBD_VERSION_INFO = _MV3D_RGBD_VERSION_INFO_ + +# ch:网口设备信息 | en:Network Type Device Information +class _MV3D_RGBD_DEVICE_NET_INFO_(Structure): + pass +Mv3dRgbdIpCfgMode = c_int # enum + +_MV3D_RGBD_DEVICE_NET_INFO_._fields_ = [ + ('chMacAddress', c_ubyte * 8), #~chinese Mac地址 ~english MAC address + ('enIPCfgMode', Mv3dRgbdIpCfgMode), #~chinese 当前IP类型 ~english Current IP type + ('chCurrentIp', c_ubyte * 16), #~chinese 设备当前IP ~english Device‘s IP address + ('chCurrentSubNetMask', c_ubyte * 16), #~chinese 设备当前子网掩码 ~english Device’s subnet mask + ('chDefultGateWay', c_ubyte * 16), #~chinese 设备默认网关 ~english Device‘s default gateway + ('chNetExport', c_ubyte * 16), #~chinese 网口IP地址 ~english Network interface IP address + ('nReserved', c_byte * 16), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_DEVICE_NET_INFO = _MV3D_RGBD_DEVICE_NET_INFO_ + +# ch:USB设备信息 | en:USB Type Device Information +class _MV3D_RGBD_DEVICE_USB_INFO_(Structure): + pass +Mv3dRgbdUsbProtocol = c_int # enum + +_MV3D_RGBD_DEVICE_USB_INFO_._fields_ = [ + ('nVendorId', c_uint), #~chinese 供应商ID号 ~english Manufacturer/vendor ID + ('nProductId', c_uint), #~chinese 产品ID号 ~english Product ID + ('enUsbProtocol', Mv3dRgbdUsbProtocol), #~chinese 支持的USB协议 ~english Supported USB protocol types + ('chDeviceGUID', c_ubyte * 64), #~chinese 设备GUID号 ~english Device GUID + ('nReserved', c_byte * 16), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_DEVICE_USB_INFO = _MV3D_RGBD_DEVICE_USB_INFO_ + +# ch:枚举相关设备信息 | en:Device Information +class _MV3D_RGBD_DEVICE_INFO_(Structure): + pass +class MV3D_RGBD_DEVICE_SPECIAL_INFO(Union): + pass +Mv3dRgbdDeviceType = c_int # enum + +# ch:不同设备特有信息 | en:Particular information of different types devices +MV3D_RGBD_DEVICE_SPECIAL_INFO._fields_ = [ + ('stNetInfo', MV3D_RGBD_DEVICE_NET_INFO), #~chinese 网口设备特有 ~english Network type device + ('stUsbInfo', MV3D_RGBD_DEVICE_USB_INFO), #~chinese USB设备特有 ~english USB type device information +] + +_MV3D_RGBD_DEVICE_INFO_._fields_ = [ + ('chManufacturerName', c_ubyte * 32), #~chinese 设备厂商 ~english Manufacturer + ('chModelName', c_ubyte * 32), #~chinese 设备型号 ~english Device model + ('chDeviceVersion', c_ubyte * 32), #~chinese 设备版本 ~english Device version + ('chManufacturerSpecificInfo', c_ubyte * 44), #~chinese 设备厂商特殊信息 ~english The specific information about manufacturer + ('nDevTypeInfo', c_uint), #~chinese 设备类型信息 ~english Device type info + ('chSerialNumber', c_ubyte * 16), #~chinese 设备序列号 ~english Device serial number + ('chUserDefinedName', c_ubyte * 16), #~chinese 设备用户自定义名称 ~english User-defined name of device + ('enDeviceType', Mv3dRgbdDeviceType), #~chinese 设备类型:网口、USB、虚拟网口设备、虚拟USB设备 + #~english Device type(network / USB / virtual network / virtual USB) + ('SpecialInfo', MV3D_RGBD_DEVICE_SPECIAL_INFO), #~chinese 不同设备特有信息 ~english Particular information of different types devices +] +MV3D_RGBD_DEVICE_INFO = _MV3D_RGBD_DEVICE_INFO_ + +# ch:IP配置 | en:IP Configuration Parameters +class _MV3D_RGBD_IP_CONFIG_(Structure): + pass +Mv3dRgbdIpCfgMode = c_int # enum + +_MV3D_RGBD_IP_CONFIG_._fields_ = [ + ('enIPCfgMode', Mv3dRgbdIpCfgMode), #~chinese IP配置模式 ~english IP configuration mode + ('chDestIp', c_ubyte * 16), #~chinese 设置的目标IP,仅静态IP模式下有效 ~english The IP address which is to be attributed to the target device. It is valid in the static IP mode only + ('chDestNetMask', c_ubyte * 16), #~chinese 设置的目标子网掩码,仅静态IP模式下有效 ~english The subnet mask of target device. It is valid in the static IP mode only + ('chDestGateWay', c_ubyte * 16), #~chinese 设置的目标网关,仅静态IP模式下有效 ~english The gateway of target device. It is valid in the static IP mode only + + ('nReserved', c_byte * 16), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_IP_CONFIG = _MV3D_RGBD_IP_CONFIG_ + +# ch:相机图像 | en:Camera Image Parameters +class _MV3D_RGBD_IMAGE_DATA_(Structure): + pass +Mv3dRgbdImageType = c_int # enum +Mv3dRgbdStreamType = c_int # enum +Mv3dRgbdCoordinateType = c_int # enum + +_MV3D_RGBD_IMAGE_DATA_._fields_ = [ + ('enImageType', Mv3dRgbdImageType), #~chinese 图像格式 ~english Image format + ('nWidth', c_uint), #~chinese 图像宽 ~english Image width + ('nHeight', c_uint), #~chinese 图像高 ~english Image height + ('pData', POINTER(c_ubyte)), #~chinese 相机输出的图像数据 ~english Image data, which is outputted by the camera + ('nDataLen', c_uint), #~chinese 图像数据长度(字节) ~english Image data length (bytes) + ('nFrameNum', c_uint), #~chinese 帧号,代表第几帧图像 ~english Frame number, which indicates the frame sequence + ('nTimeStamp', int64_t), #~chinese 设备上报的时间戳 (设备上电从0开始,规则详见设备手册) + #~english Timestamp uploaded by the device. It starts from 0 when the device is powered on. Refer to the device user manual for detailed rules + ('bIsRectified', c_uint), #~chinese 是否校正 ~english Correction flag + ('enStreamType', Mv3dRgbdStreamType), #~chinese 流类型,用于区分图像(图像格式相同时) ~english Data stream type, used to distinguish data in the same image format + ('enCoordinateType', Mv3dRgbdCoordinateType), #~chinese 坐标系类型 ~english Coordinates type + + ('nReserved', c_byte * 4), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_IMAGE_DATA = _MV3D_RGBD_IMAGE_DATA_ + +class _MV3D_RGBD_FRAME_DATA_(Structure): + pass +# ch:图像帧数据 | en:Frame Data +_MV3D_RGBD_FRAME_DATA_._fields_ = [ + ('nImageCount', c_uint), #~chinese 图像个数,表示stImage数组的有效个数 ~english The number of images. It indicates the number of valid stImage arrays + ('stImageData', MV3D_RGBD_IMAGE_DATA * MV3D_RGBD_MAX_IMAGE_COUNT), #~chinese 图像数组,每一个代表一种类型的图像 ~english Image array, each one represents one type of images + ('nValidInfo', c_uint), #~chinese 帧有效信息:0(帧有效),1 << 0(丢包),1 << 1(触发标识符无效) + #~english Frame valid info: 0 (Frame is valid), 1 << 0 (lost package), 1 << 1 (trigger is not valid) + ('nTriggerId', c_uint), #~chinese 触发标记 ~english Trigger ID + ('nReserved', c_byte * 8), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_FRAME_DATA = _MV3D_RGBD_FRAME_DATA_ + +# ch:float格式2维点数据 | en:Float type two-dimension point data +class _MV3D_RGBD_POINT_2D_F32_(Structure): + pass +_MV3D_RGBD_POINT_2D_F32_._fileds_ = [ + ('fX', c_float), #~chinese X轴坐标 ~english X-dimension data + ('fY', c_float), #~chinese Y轴坐标 ~english Y-dimension data +] +MV3D_RGBD_POINT_2D_F32 = _MV3D_RGBD_POINT_2D_F32_ + +# ch:float格式3维点数据 | en:Float type two-dimension point data +class _MV3D_RGBD_POINT_3D_F32_(Structure): + pass +_MV3D_RGBD_POINT_3D_F32_._fileds_ = [ + ('fX', c_float), #~chinese X轴坐标 ~english X-dimension data + ('fY', c_float), #~chinese Y轴坐标 ~english Y-dimension data + ('fZ', c_float), #~chinese Z轴坐标 ~english Z-dimension data +] +MV3D_RGBD_POINT_3D_F32 = _MV3D_RGBD_POINT_3D_F32_ + +# ch:法向量点云数据 | en:Point cloud with normal vector data +class _MV3D_RGBD_POINT_XYZ_NORMALS_(Structure): + pass +_MV3D_RGBD_POINT_XYZ_NORMALS_._fileds_ = [ + ('stPoint3f', MV3D_RGBD_POINT_3D_F32), #~chinese 点云数据 ~english Point cloud data + ('stNormals', MV3D_RGBD_POINT_3D_F32), #~chinese 法向量数据 ~english Normal vector data +] +MV3D_RGBD_POINT_XYZ_NORMALS = _MV3D_RGBD_POINT_XYZ_NORMALS_ + +# ch:rgba数据 | en:rgba data +class _MV3D_RGBD_POINT_RGBA_(Structure): + pass +_MV3D_RGBD_POINT_RGBA_._fileds_ = [ + ('nR', c_uint8), #~chinese R通道数据 ~english R channel data + ('nG', c_uint8), #~chinese G通道数据 ~english G channel data + ('nB', c_uint8), #~chinese B通道数据 ~english B channel data + ('nA', c_uint8), #~chinese A通道数据 ~english A channel data +] +MV3D_RGBD_POINT_RGBA = _MV3D_RGBD_POINT_RGBA_ + +# ch:rgb信息 | en:rgb info +class _MV3D_RGBD_RGB_INFO_(Union): + pass +_MV3D_RGBD_RGB_INFO_._fileds_ = [ + ('stRgba', MV3D_RGBD_POINT_RGBA), #~chinese rgba信息 ~english rgba info + ('fRgb', c_float), #~chinese float格式rgb信息 ~english float type rgb info +] +MV3D_RGBD_RGB_INFO = _MV3D_RGBD_RGB_INFO_ + +# ch:纹理点云数据 | en:Textured point cloud data +class _MV3D_RGBD_POINT_XYZ_RGB_(Structure): + pass +_MV3D_RGBD_POINT_XYZ_RGB_._fields_ = [ + ('stPoint3f', MV3D_RGBD_POINT_3D_F32), #~chinese 点云数据 ~english Point cloud data + ('stRgbInfo', MV3D_RGBD_RGB_INFO), #~chinese rgb信息 ~english rgb info +] +MV3D_RGBD_POINT_XYZ_RGB = _MV3D_RGBD_POINT_XYZ_RGB_ + +# ch:带法向量的纹理点云数据 | en:Textured point cloud with normal vector data +class _MV3D_RGBD_POINT_XYZ_RGB_NORMALS_(Structure): + pass +_MV3D_RGBD_POINT_XYZ_RGB_NORMALS_._fields_ = [ + ('stRgbPoint', MV3D_RGBD_POINT_XYZ_RGB), #~chinese 彩色点云数据 ~english Color point cloud data + ('stNormals', MV3D_RGBD_POINT_3D_F32), #~chinese 法向量数据 ~english Normal vector data +] +MV3D_RGBD_POINT_XYZ_RGB_NORMALS = _MV3D_RGBD_POINT_XYZ_RGB_NORMALS_ + +# ch: UV图数据 | en:english UV map data +class _MV3D_RGBD_UV_DATA_(Structure): + pass +_MV3D_RGBD_UV_DATA_._fields_ = [ + ('nDataLen',c_uint), #~chinese 数据长度 ~english Data length + ('pData',POINTER(MV3D_RGBD_POINT_2D_F32)), #~chinese UV图数据 ~english UV Map data + + ('nReserved', c_byte * 8), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_UV_DATA = _MV3D_RGBD_UV_DATA_ + +#~ch: 深度图伪彩转换参数 | en: Depth to Color Image Conversion Parameters +class _MV3D_RGBD_CONVERT_COLOR_PAPRAM_(Structure): + pass +Mv3dRgbdConvertColorMapMode = c_int # enum +Mv3dRgbdConvertColorRangeMode = c_int # enum +_MV3D_RGBD_CONVERT_COLOR_PAPRAM_._fields_ = [ + ('enConvertColorMapMode',Mv3dRgbdConvertColorMapMode), #~chinese 颜色映射模式 ~english Color mapping mode + ('enConvertColorRangeMode',Mv3dRgbdConvertColorRangeMode), #~chinese 深度图转伪彩范围模式 ~english Depth Image to Color Image Range Mode + ('bExistInvalidValue',c_bool), #~chinese 无效值数量 ~english The number of invalid values + ('fInvalidValue',c_float * 8), #~chinese 无效值 ~english Invalid values + ('fRangeMinValue',c_float), #~chinese 范围模式为用户指定绝对值时,表示最小深度值;范围模式为用户指定百分比时,表示最小百分比[0.0,1.0] + #~english If the absolute value is chosen as the range mode, it represents the minimum depth value. Else if the percentage is chosen as the range mode, it represents the minimum percentage + ('fRangeMaxValue',c_float), #~chinese 范围模式为用户指定绝对值时,表示最大深度值;范围模式为用户指定百分比时,表示最大百分比[0.0,1.0] + #~english If the absolute value is chosen as the range mode, it represents the maximum depth value. Else if the percentage is chosen as the range mode, it represents the maximum percentage + ('nReserved', c_byte * 8), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_CONVERT_COLOR_PAPRAM = _MV3D_RGBD_CONVERT_COLOR_PAPRAM_ + +# ch:固件输出的图像附加信息 | en:Image Additional Information Output by Firmware +class _MV3D_RGBD_STREAM_CFG_(Structure): + pass +Mv3dRgbdImageType = c_int # enum + +_MV3D_RGBD_STREAM_CFG_._fields_ = [ + ('enImageType', Mv3dRgbdImageType), #~chinese 图像格式 ~english Image format + ('nWidth', c_uint), #~chinese 图像宽 ~english Image width + ('nHeight', c_uint), #~chinese 图像高 ~english Image height + + ('nReserved', c_byte * 32), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_STREAM_CFG = _MV3D_RGBD_STREAM_CFG_ + +# ch:固件输出的图像帧附加信息 | en:Frame Additional Information Output by Firmware +class _MV3D_RGBD_STREAM_CFG_LIST_(Structure): + pass +_MV3D_RGBD_STREAM_CFG_LIST_._fields_ = [ + ('nStreamCfgCount', c_uint), #~chinese 图像信息数量 ~english The number of image information + ('stStreamCfg', MV3D_RGBD_STREAM_CFG * MV3D_RGBD_MAX_IMAGE_COUNT), #~chinese 图像附加信息 ~english Image additional information + + ('nReserved', c_byte * 16), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_STREAM_CFG_LIST = _MV3D_RGBD_STREAM_CFG_LIST_ + +class _MV3D_RGBD_DEVICE_INFO_LIST_(Structure): + pass +_MV3D_RGBD_DEVICE_INFO_LIST_._fields_ = [ + ('DeviceInfo', MV3D_RGBD_DEVICE_INFO * 20), #~chinese 设备信息结构体数组,目前最大20 + #~english Device information struct, max number is 20 +] +MV3D_RGBD_DEVICE_INFO_LIST = _MV3D_RGBD_DEVICE_INFO_LIST_ + +# ch:相机内参,3x3 matrix | en: Camera Internal Parameters +# | fx| 0| cx| +# | 0| fy| cy| +# | 0| 0| 1| +class _MV3D_RGBD_CAMERA_INTRINSIC_(Structure): + pass +_MV3D_RGBD_CAMERA_INTRINSIC_._fields_ = [ + ('fData', c_float * 9), #~chinese 内参参数:fx,0,cx,0,fy,cy,0,0,1 + #~english Internal parameters: fx,0,cx,0,fy,cy,0,0,1 +] +MV3D_RGBD_CAMERA_INTRINSIC = _MV3D_RGBD_CAMERA_INTRINSIC_ + +class _MV3D_RGBD_CAMERA_DISTORTION_(Structure): + pass +_MV3D_RGBD_CAMERA_DISTORTION_._fields_ = [ + ('fData', c_float * 12), #~chinese 畸变系数:k1,k2,p1,p2,k3,k4,k5,k6,s1,s2,s3,s4 + #~english Distortion coefficient: k1,k2,p1,p2,k3,k4,k5,k6,s1,s2,s3,s4 +] +MV3D_RGBD_CAMERA_DISTORTION = _MV3D_RGBD_CAMERA_DISTORTION_ + +class _MV3D_RGBD_CALIB_INFO_(Structure): + pass +_MV3D_RGBD_CALIB_INFO_._fields_ = [ + ('stIntrinsic', MV3D_RGBD_CAMERA_INTRINSIC), #~chinese 相机内参 ~english Camera internal parameters + ('stDistortion', MV3D_RGBD_CAMERA_DISTORTION), #~chinese 畸变系数 ~english Camera distortion coefficient + ('nWidth', c_uint), #~chinese 图像宽 ~english Image width + ('nHeight', c_uint), #~chinese 图像高 ~english Image height + + ('nReserved', c_byte * 8), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_CALIB_INFO = _MV3D_RGBD_CALIB_INFO_ + +# ch:相机深度图转Rgb的外参,4x4 matrix | en:Camera Extrinsic Parameters of Depth Image to Rgb Image +# | r00| r01| r02| t0| +# | r10| r11| r12| t1| +# | r20| r21| r22| t2| +# | 0| 0| 0| 1| +class _MV3D_RGBD_CAMERA_EXTRINSIC_(Structure): + pass +_MV3D_RGBD_CAMERA_EXTRINSIC_._fields_ = [ + ('fData', c_float * 16), #~chinese 深度图转Rgb外参参数:r00,r01,r02,t0,r10,r11,r12,t1,r20,r21,r22,t2,0,0,0,1 + #~english Extrinsic parameters of depth image to rgb image: r00,r01,r02,t0,r10,r11,r12,t1,r20,r21,r22,t2,0,0,0,1 +] +MV3D_RGBD_CAMERA_EXTRINSIC = _MV3D_RGBD_CAMERA_EXTRINSIC_ + +# ch:相机参数信息 | en:Camera Parameters Information +class _MV3D_RGBD_CAMERA_PARAM_(Structure): + pass +_MV3D_RGBD_CAMERA_PARAM_._fields_ = [ + ('stDepthCalibInfo', MV3D_RGBD_CALIB_INFO), #~chinese 深度图内参和畸变矩阵信息 ~english Depth image intrinsic information and distortion coefficient + ('stRgbCalibInfo', MV3D_RGBD_CALIB_INFO), #~chinese rgb内参和畸变矩阵信息 ~english Rgb image intrinsic information and distortion coefficient + ('stDepth2RgbExtrinsic', MV3D_RGBD_CAMERA_EXTRINSIC), #~chinese 相机深度图转RGB的外参 ~english Camera extrinsic parameters of depth image to rgb image + ('nReserved', c_byte * 32), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_CAMERA_PARAM = _MV3D_RGBD_CAMERA_PARAM_ + +# ch:Int类型值 | en:Int Type Value +class _MV3D_RGBD_INTPARAM_(Structure): + pass +_MV3D_RGBD_INTPARAM_._fields_ = [ + ('nCurValue', int64_t), #~chinese 当前值 ~english Current value + ('nMax', int64_t), #~chinese 最大值 ~english The maximum value + ('nMin', int64_t), #~chinese 最小值 ~english The minimum value + ('nInc', int64_t), #~chinese 增量值 ~english The increment value +] +MV3D_RGBD_INTPARAM = _MV3D_RGBD_INTPARAM_ + +# ch:Enum类型值 | en:Enumeration Type Value +class _MV3D_RGBD_ENUMPARAM_(Structure): + pass +_MV3D_RGBD_ENUMPARAM_._fields_ = [ + ('nCurValue', c_uint), #~chinese 当前值 ~english Current value + ('nSupportedNum', c_uint), #~chinese 有效数据个数 ~english The number of valid data + ('nSupportValue', c_uint * MV3D_RGBD_MAX_ENUM_COUNT), #~chinese 支持的枚举类型 ~english The type of supported enumerations +] +MV3D_RGBD_ENUMPARAM = _MV3D_RGBD_ENUMPARAM_ + +# ch:Float类型值 | en:Float Type Value +class _MV3D_RGBD_FLOATPARAM_(Structure): + pass +_MV3D_RGBD_FLOATPARAM_._fields_ = [ + ('fCurValue', c_float), #~chinese 当前值 ~english Current value + ('fMax', c_float), #~chinese 最大值 ~english The maximum value + ('fMin', c_float), #~chinese 最小值 ~english The minimum value +] +MV3D_RGBD_FLOATPARAM = _MV3D_RGBD_FLOATPARAM_ + +# ch:String类型值 | en:String Type Value +class _MV3D_RGBD_STRINGPARAM_(Structure): + pass +_MV3D_RGBD_STRINGPARAM_._fields_ = [ + ('chCurValue', c_char * MV3D_RGBD_MAX_STRING_LENGTH), #~chinese 当前值 ~english Current value + ('nMaxLength', uint32_t), #~chinese 属性节点能设置字符的最大长度 ~english The maximum length of string +] +MV3D_RGBD_STRINGPARAM = _MV3D_RGBD_STRINGPARAM_ + +# ch:设备参数值 | en:Device Parameters +class _MV3D_RGBD_PARAM_(Structure): + pass + +Mv3dRgbdParamType = c_int # enum + +class MV3D_RGBD_PARAM_ParamInfo(Union): + pass +MV3D_RGBD_PARAM_ParamInfo._fields_=[ + ('bBoolParam', c_bool), #~chinese Bool类型参数 ~english Boolean type parameter + ('stIntParam', MV3D_RGBD_INTPARAM), #~chinese Int类型参数 ~english Int type parameter + ('stFloatParam', MV3D_RGBD_FLOATPARAM), #~chinese Float类型参数 ~english Float type parameter + ('stEnumParam', MV3D_RGBD_ENUMPARAM), #~chinese Enum类型参数 ~english Enum type parameter + ('stStringParam', MV3D_RGBD_STRINGPARAM), #~chinese String类型参数 ~english String type parameter +] + +_MV3D_RGBD_PARAM_._fields_=[ + ('enParamType', Mv3dRgbdParamType), + ('ParamInfo', MV3D_RGBD_PARAM_ParamInfo), + ('nReserved', c_byte*16), +] +MV3D_RGBD_PARAM = _MV3D_RGBD_PARAM_ + +# ch:异常信息 | en:Exception Information +class _MV3D_RGBD_EXCEPTION_INFO_(Structure): + pass +Mv3dRgbdDevException = c_int # enum +_MV3D_RGBD_EXCEPTION_INFO_._fields_=[ + ('enExceptionId',Mv3dRgbdDevException), #~chinese 异常ID ~english Exception ID + ('chExceptionDes',c_char*MV3D_RGBD_MAX_STRING_LENGTH), #~chinese 异常描述 ~english Exception description + ('nReserved',c_byte*4), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_EXCEPTION_INFO=_MV3D_RGBD_EXCEPTION_INFO_ + +# ch:文件存取 | en:File Access +class _MV3D_RGBD_FILE_ACCESS_(Structure): + pass +_MV3D_RGBD_FILE_ACCESS_._fields_ = [ + ('pUserFileName', c_char_p), #~chinese 用户文件名 ~english User file name + ('pDevFileName', c_char_p), #~chinese 设备文件名 ~english Device file name + + ('nReserved', c_byte*32), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_FILE_ACCESS = _MV3D_RGBD_FILE_ACCESS_ + +# ch:文件存取进度 | en:File Access Progress +class _MV3D_RGBD_FILE_ACCESS_PROGRESS_(Structure): + pass +_MV3D_RGBD_FILE_ACCESS_PROGRESS_._fields_ = [ + ('nCompleted', c_int64), #~chinese 已完成的长度 ~english Completed length + ('nTotal', c_int64), #~chinese 总长度 ~english Total length + + ('nReserved', c_byte*32), #~chinese 保留字节 ~english Reserved +] +MV3D_RGBD_FILE_ACCESS_PROGRESS = _MV3D_RGBD_FILE_ACCESS_PROGRESS_ + +__all__ = ['_MV3D_RGBD_VERSION_INFO_','MV3D_RGBD_VERSION_INFO','_MV3D_RGBD_DEVICE_NET_INFO_','MV3D_RGBD_DEVICE_NET_INFO','_MV3D_RGBD_DEVICE_USB_INFO_','MV3D_RGBD_DEVICE_USB_INFO', + '_MV3D_RGBD_DEVICE_INFO_','MV3D_RGBD_DEVICE_INFO','_MV3D_RGBD_IP_CONFIG_','MV3D_RGBD_IP_CONFIG','_MV3D_RGBD_IMAGE_DATA_','MV3D_RGBD_IMAGE_DATA', + '_MV3D_RGBD_FRAME_DATA_','MV3D_RGBD_FRAME_DATA','_MV3D_RGBD_STREAM_CFG_','MV3D_RGBD_STREAM_CFG','_MV3D_RGBD_STREAM_CFG_LIST_','MV3D_RGBD_STREAM_CFG_LIST', + '_MV3D_RGBD_DEVICE_INFO_LIST_', 'MV3D_RGBD_DEVICE_INFO_LIST','_MV3D_RGBD_CAMERA_INTRINSIC_','MV3D_RGBD_CAMERA_INTRINSIC','_MV3D_RGBD_CAMERA_DISTORTION_','MV3D_RGBD_CAMERA_DISTORTION', + '_MV3D_RGBD_CALIB_INFO_','MV3D_RGBD_CALIB_INFO','_MV3D_RGBD_CAMERA_EXTRINSIC_','MV3D_RGBD_CAMERA_EXTRINSIC','_MV3D_RGBD_CAMERA_PARAM_','MV3D_RGBD_CAMERA_PARAM', + '_MV3D_RGBD_INTPARAM_', 'MV3D_RGBD_INTPARAM','_MV3D_RGBD_ENUMPARAM_','MV3D_RGBD_ENUMPARAM','_MV3D_RGBD_FLOATPARAM_','MV3D_RGBD_FLOATPARAM', + '_MV3D_RGBD_STRINGPARAM_','MV3D_RGBD_STRINGPARAM','_MV3D_RGBD_PARAM_','MV3D_RGBD_PARAM','_MV3D_RGBD_EXCEPTION_INFO_','MV3D_RGBD_EXCEPTION_INFO','_MV3D_RGBD_POINT_RGBA_','MV3D_RGBD_POINT_RGBA', + '_MV3D_RGBD_RGB_INFO_','MV3D_RGBD_RGB_INFO','_MV3D_RGBD_FILE_ACCESS_','MV3D_RGBD_FILE_ACCESS', '_MV3D_RGBD_FILE_ACCESS_PROGRESS_', 'MV3D_RGBD_FILE_ACCESS_PROGRESS', + '_MV3D_RGBD_POINT_2D_F32_', 'MV3D_RGBD_POINT_2D_F32', '_MV3D_RGBD_POINT_3D_F32_','MV3D_RGBD_POINT_3D_F32','_MV3D_RGBD_POINT_XYZ_NORMALS_','MV3D_RGBD_POINT_XYZ_NORMALS', + '_MV3D_RGBD_POINT_XYZ_RGB_','MV3D_RGBD_POINT_XYZ_RGB', '_MV3D_RGBD_POINT_XYZ_RGB_NORMALS_','MV3D_RGBD_POINT_XYZ_RGB_NORMALS','_MV3D_RGBD_UV_DATA_', 'MV3D_RGBD_UV_DATA', + '_MV3D_RGBD_CONVERT_COLOR_PAPRAM_', 'MV3D_RGBD_CONVERT_COLOR_PAPRAM'] \ No newline at end of file diff --git a/Mv3dRgbdImport/__pycache__/Mv3dRgbdApi.cpython-311.pyc b/Mv3dRgbdImport/__pycache__/Mv3dRgbdApi.cpython-311.pyc new file mode 100644 index 0000000..e84577f Binary files /dev/null and b/Mv3dRgbdImport/__pycache__/Mv3dRgbdApi.cpython-311.pyc differ diff --git a/Mv3dRgbdImport/__pycache__/Mv3dRgbdDefine.cpython-311.pyc b/Mv3dRgbdImport/__pycache__/Mv3dRgbdDefine.cpython-311.pyc new file mode 100644 index 0000000..199ce34 Binary files /dev/null and b/Mv3dRgbdImport/__pycache__/Mv3dRgbdDefine.cpython-311.pyc differ diff --git a/Point.py b/Point.py new file mode 100644 index 0000000..1b1c795 --- /dev/null +++ b/Point.py @@ -0,0 +1,162 @@ +import numpy as np +from PIL import Image +import math + +import SimpleView_SaveImage +import config +from cat import clip_and_rotate_point_cloud, merge_point_clouds +from image import detect_large_holes + + +def tiff_depth_to_point_clouds(tiff_paths, sn, dedup=True): + """ + 将多个 TIFF 深度图转换为点云,并拼接在一起后生成 PCD 文件 + + :param tiff_paths: list of str, TIFF 深度图路径列表 + :param sn: str, 设备序列号,用于查找配置参数 + :param dedup: bool, 是否根据 (x, y) 去重,默认开启 + :return: list of [x, y, z], 合并后的点云数据 + """ + merged_points = [] + + # Step 1: 遍历每个 TIFF 文件,生成对应的点云 + for tiff_path in tiff_paths: + points = tiff_depth_to_point_cloud(tiff_path+".tiff", sn, dedup) + merged_points.extend([points]) + + # Step 2: 可选:使用 merge_point_clouds 对点云进行 x 轴拼接(若需要) + # 注意:如果每个点云已经带有偏移,则不需要再次拼接 + has_voids = True + if hasattr(config, 'CUT_CONFIG_MAP') and isinstance(config.CUT_CONFIG_MAP, dict) and (sn in config.CUT_CONFIG_MAP): + merged_points, xrange = merge_point_clouds(merged_points, config.CUT_CONFIG_MAP[sn],sn) + + real_holes = detect_large_holes(merged_points, sn, xrange) + if real_holes.__len__()==0: + has_voids=False + # Step 3: 写入最终的 PCD 文件 + output_pcd_path = config.save_path("pcd", f"{sn}_merged.pcd") + write_pcd(output_pcd_path, merged_points) + # print(f"Merged and saved to {output_pcd_path}") + return has_voids + + +def tiff_depth_to_point_cloud(tiff_path,sn, dedup=True): + """ + 将 TIFF 深度图转换为点云,基于给定的视场角计算相机内参 + + :param tiff_path: str, TIFF 深度图路径 + :param hfov_degrees: float or None, 水平视场角(单位:度) + :param vfov_degrees: float or None, 垂直视场角(单位:度) + :param output_ply_path: str or None, 输出 Pcd 文件路径(可选) + :param dedup: bool, 是否根据 (x, y) 去重,默认开启 + :return: list of [x, y, z] 点云数据 + """ + hfov_degrees = config.CAMERA_CONFIG_MAP[sn].get("x_angle") + max_z = config.CAMERA_CONFIG_MAP[sn].get("max_z") + vfov_degrees = config.CAMERA_CONFIG_MAP[sn].get("y_angle") + # plane_scaling_ratio = config.CAMERA_CONFIG_MAP[sn].get("plane_scaling_ratio") + # 加载 TIFF 图像 + depth_image = Image.open(tiff_path) + depth_array = np.array(depth_image, dtype=np.float32) + + height, width = depth_array.shape + + # 根据提供的 FOV 计算 fx/fy + if hfov_degrees is not None: + hfov_rad = math.radians(hfov_degrees) + fx = width / (2 * math.tan(hfov_rad / 2)) + fy = fx * height / width # 保持像素方形比例 + else: + vfov_rad = math.radians(vfov_degrees) + fy = height / (2 * math.tan(vfov_rad / 2)) + fx = fy * width / height # 保持像素方形比例 + + cx = width / 2 + cy = height / 2 + + print(f"Calculated intrinsics: fx={fx:.2f}, fy={fy:.2f}, cx={cx:.2f}, cy={cy:.2f}") + + points = [] + seen_xy = set() # 用于记录已添加的 (x, y) + + # 获取裁剪配置 + clip_config = config.CUT_CONFIG_MAP.get(sn) + if clip_config: + min_pt = np.array(clip_config.get("min_pt", [-np.inf] * 3)) + max_pt = np.array(clip_config.get("max_pt", [np.inf] * 3)) + rotation = np.array(clip_config.get("rotation", [1,0,0,0,1,0,0,0,1])).reshape(3, 3) + else: + min_pt = max_pt = rotation = None + + for v in range(height): + for u in range(width): + z = depth_array[v, u] # mm -> m + if z <= 0 or z > max_z: + continue + + x = (u - cx) * z / fx + y = (v - cy) * z / fy + + # 构造点并旋转(保留浮点精度) + point = np.array([x, y, z]) + if clip_config: + rotated_point = (rotation @ point.T).T + if not np.all(rotated_point >= min_pt) or not np.all(rotated_point <= max_pt): + continue + x_final, y_final, z_final = rotated_point + else: + x_final, y_final, z_final = point + + # 到这里才进行去重判断 + if dedup: + x_int = int(round(x_final)) + y_int = int(round(y_final)) + z_int = int(round(z_final)) + if (x_int, y_int) in seen_xy: + continue + seen_xy.add((x_int, y_int)) + # 保留浮点精度写入结果 + points.append([x_int, y_int, z_int]) + + + # 可选输出PLY文件用于可视化 + if config.CAMERA_CONFIG_MAP[sn].get("save_pcd"): + output_ply_path = config.save_path("pcd",sn+".pcd") + write_pcd(output_ply_path, points) + + return points + +def write_pcd(filename, points): + """ + 将点云写入 PCD 文件 + + :param filename: str, 输出 PCD 文件路径 + :param points: list of [x, y, z], 点云数据 + """ + with open(filename, 'w') as f: + # 写入 PCD 文件头 + f.write("# .PCD v0.7 - Point Cloud Data file format\n") + f.write(f"VERSION 0.7\n") + f.write("FIELDS x y z\n") + f.write("SIZE 4 4 4\n") # float 类型的大小是 4 字节 + f.write("TYPE F F F\n") # 每个字段的数据类型 + f.write(f"COUNT 1 1 1\n") # 每个字段的数量 + f.write(f"WIDTH {len(points)}\n") # 点数量 + f.write("HEIGHT 1\n") # 单行表示无结构点云 + f.write("VIEWPOINT 0 0 0 1 0 0 0\n") # 默认视角参数 + f.write(f"POINTS {len(points)}\n") # 总点数 + f.write("DATA ascii\n") # 数据部分以 ASCII 形式存储 + + # 写入点数据 + for point in points: + f.write(f"{point[0]} {point[1]} {point[2]}\n") + + print(f"Saved point cloud to {filename}") + + +if __name__ == '__main__': + paths = SimpleView_SaveImage.pic("00DA6823936") + tiff_depth_to_point_clouds(paths, "00DA6823936") + # tiff_depth_to_point_clouds(["D:/PycharmProjects/Hik3D/image/2025-06-24/depth/145209062_-Depth.tiff" + # ,"D:/PycharmProjects/Hik3D/image/2025-06-24/depth/145209062_-Depth.tiff" + # ,"D:/PycharmProjects/Hik3D/image/2025-06-24/depth/145209062_-Depth.tiff"], "00DA6823936") \ No newline at end of file diff --git a/SimpleView_SaveImage.py b/SimpleView_SaveImage.py new file mode 100644 index 0000000..450667e --- /dev/null +++ b/SimpleView_SaveImage.py @@ -0,0 +1,144 @@ +# -- coding: utf-8 -- +import threading +import msvcrt +import ctypes +import time +import os +import struct +from ctypes import * +from datetime import datetime + +from Mv3dRgbdImport.Mv3dRgbdDefine import * +from Mv3dRgbdImport.Mv3dRgbdApi import * +from Mv3dRgbdImport.Mv3dRgbdDefine import DeviceType_Ethernet, DeviceType_USB, DeviceType_Ethernet_Vir, DeviceType_USB_Vir, MV3D_RGBD_FLOAT_EXPOSURETIME, \ + ParamType_Float, ParamType_Int, ParamType_Enum, CoordinateType_Depth, MV3D_RGBD_FLOAT_Z_UNIT, MV3D_RGBD_OK, \ + FileType_BMP,FileType_TIFF,ImageType_Depth, ImageType_RGB8_Planar, ImageType_YUV420SP_NV12 ,ImageType_YUV420SP_NV21 , ImageType_YUV422, ImageType_Mono8 + +import config as configMap + +# 全局变量 +SN_MAP = {} # {sn: camera_instance} + + +def initialize_devices(): + nDeviceNum = ctypes.c_uint(0) + ret = Mv3dRgbd.MV3D_RGBD_GetDeviceNumber( + DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir, + byref(nDeviceNum) + ) + if ret != MV3D_RGBD_OK or nDeviceNum.value == 0: + print("Failed to get device number or no devices found.") + return + + stDeviceList = MV3D_RGBD_DEVICE_INFO_LIST() + Mv3dRgbd.MV3D_RGBD_GetDeviceList( + DeviceType_Ethernet | DeviceType_USB | DeviceType_Ethernet_Vir | DeviceType_USB_Vir, + pointer(stDeviceList.DeviceInfo[0]), 20, byref(nDeviceNum) + ) + + for i in range(nDeviceNum.value): + serial_number = ''.join(chr(c) for c in stDeviceList.DeviceInfo[i].chSerialNumber).rstrip('\x00') + print(f"Found device [{i}]: Serial Number: {serial_number}") + + camera = Mv3dRgbd() + + # 打开设备 + ret = camera.MV3D_RGBD_OpenDevice(pointer(stDeviceList.DeviceInfo[i])) + if ret != MV3D_RGBD_OK: + print(f"Failed to open device with SN: {serial_number}. Error code: {ret:#x}") + continue + + # 存入全局 map + SN_MAP[serial_number] = camera + print(f"Successfully added device {serial_number} to SN_MAP") + + +def pic(sn): + camera = SN_MAP.get(sn) + + if not camera: + print(f"No camera found for SN: {sn}") + return + + config = configMap.CAMERA_CONFIG_MAP.get(sn) + if not config: + print(f"No config found for SN: {sn}") + return + + time_on = config.get("time_on", 0) # 延时开始(毫秒) + time_off = config.get("time_off", 0) # 拍照总时长(毫秒) + time_hop = config.get("time_hop", 0) # 每次拍照间隔(毫秒) + + end_time = time.time() + (time_off / 1000.0) + print(f"Delaying start by {time_on}ms...") + time.sleep(time_on / 1000.0) # 转成秒 + + + frame_count = 0 + + saved_tiff_files = [] # 用于存储保存的 TIFF 文件路径 + print(f"Start continuous capturing for {time_off}ms...") + + # 开始取流 + ret = camera.MV3D_RGBD_Start() + if ret != MV3D_RGBD_OK: + print(f"Failed to start grabbing. Error code: {ret:#x}") + return + + try: + while time.time() < end_time: + stFrameData = MV3D_RGBD_FRAME_DATA() + + # 获取帧数据 + ret = camera.MV3D_RGBD_FetchFrame(pointer(stFrameData), 5000) + if ret == MV3D_RGBD_OK: + frame_count += 1 + + for i in range(stFrameData.nImageCount): + image_info = stFrameData.stImageData[i] + + # 保存深度图 + if image_info.enImageType == ImageType_Depth: + file_name = configMap.save_path("depth","-Depth") + ret_save = camera.MV3D_RGBD_SaveImage(pointer(image_info), FileType_TIFF, file_name) + print("Saved depth image." if ret_save == MV3D_RGBD_OK else "Failed to save depth image.") + if ret_save == MV3D_RGBD_OK: + saved_tiff_files.append(file_name) # 记录保存的 TIFF 文件路径 + # print(f"Saved depth image: {file_name}") + else: + print("Failed to save depth image.") + + # 保存彩色图 + elif image_info.enImageType in ( + ImageType_RGB8_Planar, ImageType_YUV420SP_NV12, + ImageType_YUV420SP_NV21, ImageType_YUV422 + ): + file_name = configMap.save_path("color","-_Color") + ret_save = camera.MV3D_RGBD_SaveImage(pointer(image_info), FileType_BMP, file_name) + print("Saved color image." if ret_save == MV3D_RGBD_OK else "Failed to save color image.") + + # 保存灰度图 + elif image_info.enImageType == ImageType_Mono8: + file_name = configMap.save_path("Mono","-_Mono") + ret_save = camera.MV3D_RGBD_SaveImage(pointer(image_info), FileType_BMP, file_name) + print("Saved mono image." if ret_save == MV3D_RGBD_OK else "Failed to save mono image.") + + else: + print(f"Unknown image type: {image_info.enImageType}") + + else: + print("Failed to fetch frame.") + + time.sleep(time_hop / 1000.0) # 控制采集频率 + + finally: + # 停止取流 + camera.MV3D_RGBD_Stop() + print("Continuous capture completed.") + return saved_tiff_files + + +initialize_devices() + +if __name__ == '__main__': + pic("00DA6823936") \ No newline at end of file diff --git a/__pycache__/Point.cpython-311.pyc b/__pycache__/Point.cpython-311.pyc new file mode 100644 index 0000000..782ed1b Binary files /dev/null and b/__pycache__/Point.cpython-311.pyc differ diff --git a/__pycache__/SimpleView_SaveImage.cpython-311.pyc b/__pycache__/SimpleView_SaveImage.cpython-311.pyc new file mode 100644 index 0000000..eea7f62 Binary files /dev/null and b/__pycache__/SimpleView_SaveImage.cpython-311.pyc differ diff --git a/__pycache__/cat.cpython-311.pyc b/__pycache__/cat.cpython-311.pyc new file mode 100644 index 0000000..dea9f36 Binary files /dev/null and b/__pycache__/cat.cpython-311.pyc differ diff --git a/__pycache__/config.cpython-311.pyc b/__pycache__/config.cpython-311.pyc new file mode 100644 index 0000000..01b272a Binary files /dev/null and b/__pycache__/config.cpython-311.pyc differ diff --git a/__pycache__/image.cpython-311.pyc b/__pycache__/image.cpython-311.pyc new file mode 100644 index 0000000..f27d7f0 Binary files /dev/null and b/__pycache__/image.cpython-311.pyc differ diff --git a/app.png b/app.png new file mode 100644 index 0000000..0c88f81 Binary files /dev/null and b/app.png differ diff --git a/build.cmd b/build.cmd new file mode 100644 index 0000000..3c4bd19 --- /dev/null +++ b/build.cmd @@ -0,0 +1,28 @@ +pyinstaller ^ + --name=Hik3DApp ^ + --icon=app.png ^ + --add-data "dlls;_internal\\dlls" ^ + --hidden-import=cv2.cv2 ^ + --hidden-import=numpy.core._methods ^ + --hidden-import=numpy.lib.format ^ + --hidden-import=scipy.__config__ ^ + --hidden-import=scipy._distributor_init ^ + --hidden-import=scipy.sparse.csgraph._validation ^ + --hidden-import=scipy.special._ellip_harm_2 ^ + --hidden-import=scipy._cyutility ^ + --hidden-import=scipy._lib._ccallback ^ + --hidden-import=scipy.linalg.cython_blas ^ + --hidden-import=scipy.linalg.cython_lapack ^ + --hidden-import=scipy.optimize._highs._highs_constants ^ + --hidden-import=scipy.optimize._highs._highs_wrapper ^ + --hidden-import=sklearn.utils._weight_vector ^ + --hidden-import=sklearn.utils._weight_vector_fast ^ + --hidden-import=sklearn.tree._utils ^ + --exclude-module=tkinter ^ + --exclude-module=PyQt5 ^ + --clean ^ + main.py + +xcopy /E /I /Y config dist\Hik3DApp\config + +xcopy /E /I /Y dlls dist\Hik3DApp\_internal\dlls \ No newline at end of file diff --git a/cat.py b/cat.py new file mode 100644 index 0000000..0209052 --- /dev/null +++ b/cat.py @@ -0,0 +1,66 @@ +import numpy as np +import config as con + +def clip_and_rotate_point_cloud(points, config): + """ + 对点云先旋转,再裁剪 + + :param points: list of [x, y, z], 原始点云数据 + :param config: dict, 包含 min_pt, max_pt, rotation 的配置 + :return: list of [x, y, z], 旋转并裁剪后的点云 + """ + + # 提取配置参数 + min_pt = np.array(config.get("min_pt", [-np.inf] * 3)) + max_pt = np.array(config.get("max_pt", [np.inf] * 3)) + rotation = np.array(config.get("rotation", [1, 0, 0, 0, 1, 0, 0, 0, 1])).reshape(3, 3) + + # 转换为 NumPy 数组 + points = np.array(points, dtype=np.float64) + + # 1. 先旋转:应用旋转矩阵 + rotated_points = (rotation @ points.T).T + + # 2. 再裁剪:保留落在 min_pt ~ max_pt 范围内的点 + mask = np.all((rotated_points >= min_pt) & (rotated_points <= max_pt), axis=1) + clipped_points = rotated_points[mask] + + return clipped_points.tolist() + + + + +def merge_point_clouds(clouds, config,sn): + """ + 将多个点云沿 x 轴依次拼接在一起 + + :param clouds: list of (list of [x, y, z]), 多个点云 + :return: list of [x, y, z], 合并后的点云 + """ + + min_pt = config.get("min_pt", [0, 0, 0]) + max_pt = config.get("max_pt", [0, 0, 0]) + # 返回 x 方向的区域宽度 + + merged = [] + current_x_offset = 0 + + reverse_order = con.CAMERA_CONFIG_MAP[sn].get("reverse_order", False) + for cloud in reversed(clouds) if reverse_order else clouds: + if not cloud: + continue + # 添加偏移后写入结果 + offset_cloud = [[p[0] + current_x_offset, p[1], p[2]] for p in cloud] + merged.extend(offset_cloud) + + # 获取当前相机采集区域的 x 宽度 + x_width = float(max_pt[0] - min_pt[0]) + + # 更新下一个点云的偏移量(当前偏移 + 当前区域宽度) + # 在下一次删除 + current_x_offset += x_width + + + return merged,current_x_offset+min_pt[0] + + diff --git a/config.py b/config.py new file mode 100644 index 0000000..b230331 --- /dev/null +++ b/config.py @@ -0,0 +1,77 @@ +import os +import json +from datetime import datetime + +# 全局配置字典 +CAMERA_CONFIG_MAP = {} # {sn: config_dict} +CUT_CONFIG_MAP = {} # {filename_without_ext: config_dict} +DIRECTION_CAMERA = {} + +def load_camera_configs(config_dir="./config/camera"): + """ + 加载 camera 配置,按 sn 建立映射 + """ + if not os.path.exists(config_dir): + print(f"[ERROR] Camera config directory does not exist: {config_dir}") + return + + for filename in os.listdir(config_dir): + if filename.endswith(".json"): + file_path = os.path.join(config_dir, filename) + try: + with open(file_path, "r", encoding="utf-8") as f: + config = json.load(f) + sn = config.get("sn") + if sn: + CAMERA_CONFIG_MAP[sn] = config + DIRECTION_CAMERA[config.get("direction")] = sn + print(f"Loaded camera config: {sn}") + else: + print(f"[WARN] No 'sn' found in {filename}") + except Exception as e: + print(f"[ERROR] Failed to load {file_path}: {e}") +load_camera_configs() + +def load_cut_configs(config_dir="./config/cut"): + """ + 加载 cut 配置,按文件名(不含扩展名)建立映射 + """ + if not os.path.exists(config_dir): + print(f"[ERROR] Cut config directory does not exist: {config_dir}") + return + + for filename in os.listdir(config_dir): + if filename.endswith(".json"): + file_path = os.path.join(config_dir, filename) + name_without_ext = os.path.splitext(filename)[0] + try: + with open(file_path, "r", encoding="utf-8") as f: + config = json.load(f) + CUT_CONFIG_MAP[name_without_ext] = config + print(f"Loaded cut config: {name_without_ext}") + except Exception as e: + print(f"[ERROR] Failed to load {file_path}: {e}") + + +def load_configs(): + CAMERA_CONFIG_MAP = {} # {sn: config_dict} + CUT_CONFIG_MAP = {} # {filename_without_ext: config_dict} + DIRECTION_CAMERA = {} + load_camera_configs() + load_cut_configs() + +load_configs() + +def save_path(type,end): + # 创建保存目录 + today = datetime.now().strftime("%Y-%m-%d") + output_dir = os.path.join(".", "image",today,type) + os.makedirs(output_dir, exist_ok=True) + + timestamp = datetime.now().strftime("%H%M%S%f")[:-3] # 精确到毫秒 + + file_name_prefix = f"{timestamp}_"+end + + # 构造完整路径 + save_path = os.path.join(output_dir,file_name_prefix) + return save_path \ No newline at end of file diff --git a/config/camera/00DA6823936.json b/config/camera/00DA6823936.json new file mode 100644 index 0000000..55333d6 --- /dev/null +++ b/config/camera/00DA6823936.json @@ -0,0 +1,13 @@ +{ + "sn": "00DA6823936", + "direction": "1", + "x_angle": 55, + "y_angle": 84, + "save_pcd": true, + "resolution": 8, + "max_z": 2000, + "reverse_order": false, + "time_on": 300, + "time_off": 3500, + "time_hop": 500 +} \ No newline at end of file diff --git a/config/cut/00DA6823936.json b/config/cut/00DA6823936.json new file mode 100644 index 0000000..37c2314 --- /dev/null +++ b/config/cut/00DA6823936.json @@ -0,0 +1,24 @@ +{ + "floorHeight": 1, + "max_pt": [ + 59.17729568481445, + -177.37328052520752, + 823.2836303710938 + ], + "min_pt": [ + 0, + -1263.9830322265625, + 200.47930908203125 + ], + "rotation": [ + -0.0070345401763916016, + -0.9998821020126343, + 0.013652533292770386, + 0.4579751193523407, + -0.015358328819274902, + -0.8888324499130249, + 0.88893723487854, + -2.9802322387695312e-08, + 0.45802903175354004 + ] +} diff --git a/config/cut/00DA6823936_A.json b/config/cut/00DA6823936_A.json new file mode 100644 index 0000000..7717188 --- /dev/null +++ b/config/cut/00DA6823936_A.json @@ -0,0 +1,24 @@ +{ + "floorHeight": 1, + "max_pt": [ + 103.20252990722656, + -169.6024932861328, + 182.84439086914062 + ], + "min_pt": [ + 16.854652404785156, + -1234.1793212890625, + 153.4544677734375 + ], + "rotation": [ + -0.006754159927368164, + -0.9998819828033447, + 0.013793319463729858, + 0.43973052501678467, + -0.015358209609985352, + -0.8979983329772949, + 0.8981043100357056, + 0, + 0.4397825002670288 + ] +} diff --git a/config/cut/00DA6823936_B.json b/config/cut/00DA6823936_B.json new file mode 100644 index 0000000..37c2314 --- /dev/null +++ b/config/cut/00DA6823936_B.json @@ -0,0 +1,24 @@ +{ + "floorHeight": 1, + "max_pt": [ + 59.17729568481445, + -177.37328052520752, + 823.2836303710938 + ], + "min_pt": [ + 0, + -1263.9830322265625, + 200.47930908203125 + ], + "rotation": [ + -0.0070345401763916016, + -0.9998821020126343, + 0.013652533292770386, + 0.4579751193523407, + -0.015358328819274902, + -0.8888324499130249, + 0.88893723487854, + -2.9802322387695312e-08, + 0.45802903175354004 + ] +} diff --git a/config/配置文件说明.txt b/config/配置文件说明.txt new file mode 100644 index 0000000..e69de29 diff --git a/dlls/MV3D/Win64_x64/CLAllSerial_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/CLAllSerial_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..8e2c911 Binary files /dev/null and b/dlls/MV3D/Win64_x64/CLAllSerial_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/CLProtocol_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/CLProtocol_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..8c7ec20 Binary files /dev/null and b/dlls/MV3D/Win64_x64/CLProtocol_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/CLSerCOM.dll b/dlls/MV3D/Win64_x64/CLSerCOM.dll new file mode 100644 index 0000000..04eaa0d Binary files /dev/null and b/dlls/MV3D/Win64_x64/CLSerCOM.dll differ diff --git a/dlls/MV3D/Win64_x64/CommonParameters.ini b/dlls/MV3D/Win64_x64/CommonParameters.ini new file mode 100644 index 0000000..c0818d8 --- /dev/null +++ b/dlls/MV3D/Win64_x64/CommonParameters.ini @@ -0,0 +1,36 @@ +;该配置文件列出了部分可配置的参数,其他可配置参数请参考软件安装路径下Development\Documentations\工业相机SDK可配置化参数表.xlsx +;修改配置后上层应用程序要重新启动 +;不分设备类型的通用参数 +[COMMON] +;设置SDK内部图像缓存节点个数,若不调用接口(MV_CC_SetImageNodeNum)主动设置,默认为1,除双U口相机外 +;双U口相机SDK内部多分配2个节点即ImageNodeNum+2,默认节点个数为3 +ImageNodeNum=1 +;设置为1,表示设置系统时间精度;若不设置则为默认windows时钟精度 +SetTimeFlag = 0 +;默认不开启; 设置为1,表示开启生成崩溃MiniDump文件; +MiniDumpFlag = 0 + +;网口相机相关参数 +[GIGE] +;设置GVCP命令超时时间,默认500ms,范围:0-10000ms +GvcpTimeout=500 + +;设置取流模式 +;若存在GE1104采集卡模拟标准网卡环境,则虚拟网卡下第一个相机走PCIE驱动模式取流,默认值为0; +;若修改为1,则表示走普通模式取流; +AcquisitionDriveMode=0 + +;U口相机相关参数 +[U3V] +;设置U3V的传输包大小,Byte,默认为1M,rang:>=0x400 +TransferSize=1048576 + +;CameraLink相机相关参数 +[CAML] + +;图像处理相关的参数 +[IMG_PROCESSING] +;设置插值算法类型,0-快速 1-均衡 2-最优 3-最优+(默认为最优) +BayerCvtQuality=2 +;设置插值算法处理线程个数,0-自适应 其他-具体线程个数(1,2,3,...)(默认线程个数为4) +BayerCvtThreadNum=4 \ No newline at end of file diff --git a/dlls/MV3D/Win64_x64/GCBase_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/GCBase_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..641edc5 Binary files /dev/null and b/dlls/MV3D/Win64_x64/GCBase_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/GenApi_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/GenApi_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..ba577e8 Binary files /dev/null and b/dlls/MV3D/Win64_x64/GenApi_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/Log_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/Log_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..fc420b8 Binary files /dev/null and b/dlls/MV3D/Win64_x64/Log_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/MVGigEVisionSDK3D.dll b/dlls/MV3D/Win64_x64/MVGigEVisionSDK3D.dll new file mode 100644 index 0000000..e63d17a Binary files /dev/null and b/dlls/MV3D/Win64_x64/MVGigEVisionSDK3D.dll differ diff --git a/dlls/MV3D/Win64_x64/MathParser_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/MathParser_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..eb281ee Binary files /dev/null and b/dlls/MV3D/Win64_x64/MathParser_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/MediaProcess3D.dll b/dlls/MV3D/Win64_x64/MediaProcess3D.dll new file mode 100644 index 0000000..59facd5 Binary files /dev/null and b/dlls/MV3D/Win64_x64/MediaProcess3D.dll differ diff --git a/dlls/MV3D/Win64_x64/Microsoft.VC90.CRT.manifest b/dlls/MV3D/Win64_x64/Microsoft.VC90.CRT.manifest new file mode 100644 index 0000000..ac71535 --- /dev/null +++ b/dlls/MV3D/Win64_x64/Microsoft.VC90.CRT.manifest @@ -0,0 +1,13 @@ + + + + + + + diff --git a/dlls/MV3D/Win64_x64/Microsoft.VC90.DebugCRT.manifest b/dlls/MV3D/Win64_x64/Microsoft.VC90.DebugCRT.manifest new file mode 100644 index 0000000..345d949 --- /dev/null +++ b/dlls/MV3D/Win64_x64/Microsoft.VC90.DebugCRT.manifest @@ -0,0 +1,6 @@ + + + + + Mmb6ThWjkCLJ1kFcb6VeXbKgZSQ= QwAibePQKRW3vDa/c/P+zMttGvk= K7zTyjEv60CJbG2B1wTDE6+zlmk= + \ No newline at end of file diff --git a/dlls/MV3D/Win64_x64/MvCameraControl3D.dll b/dlls/MV3D/Win64_x64/MvCameraControl3D.dll new file mode 100644 index 0000000..f57c30f Binary files /dev/null and b/dlls/MV3D/Win64_x64/MvCameraControl3D.dll differ diff --git a/dlls/MV3D/Win64_x64/MvProducerVIR3D.dll b/dlls/MV3D/Win64_x64/MvProducerVIR3D.dll new file mode 100644 index 0000000..3846034 Binary files /dev/null and b/dlls/MV3D/Win64_x64/MvProducerVIR3D.dll differ diff --git a/dlls/MV3D/Win64_x64/MvRender.dll b/dlls/MV3D/Win64_x64/MvRender.dll new file mode 100644 index 0000000..b25c315 Binary files /dev/null and b/dlls/MV3D/Win64_x64/MvRender.dll differ diff --git a/dlls/MV3D/Win64_x64/MvUsb3vTL3D.dll b/dlls/MV3D/Win64_x64/MvUsb3vTL3D.dll new file mode 100644 index 0000000..d680795 Binary files /dev/null and b/dlls/MV3D/Win64_x64/MvUsb3vTL3D.dll differ diff --git a/dlls/MV3D/Win64_x64/NodeMapData_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/NodeMapData_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..484ee4d Binary files /dev/null and b/dlls/MV3D/Win64_x64/NodeMapData_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/XmlParser_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/XmlParser_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..a4b278f Binary files /dev/null and b/dlls/MV3D/Win64_x64/XmlParser_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/avutil-57.dll b/dlls/MV3D/Win64_x64/avutil-57.dll new file mode 100644 index 0000000..8a785d2 Binary files /dev/null and b/dlls/MV3D/Win64_x64/avutil-57.dll differ diff --git a/dlls/MV3D/Win64_x64/libmmd.dll b/dlls/MV3D/Win64_x64/libmmd.dll new file mode 100644 index 0000000..8becb5e Binary files /dev/null and b/dlls/MV3D/Win64_x64/libmmd.dll differ diff --git a/dlls/MV3D/Win64_x64/libusb0.dll b/dlls/MV3D/Win64_x64/libusb0.dll new file mode 100644 index 0000000..af6c382 Binary files /dev/null and b/dlls/MV3D/Win64_x64/libusb0.dll differ diff --git a/dlls/MV3D/Win64_x64/libwinpthread-1.dll b/dlls/MV3D/Win64_x64/libwinpthread-1.dll new file mode 100644 index 0000000..2a6f9c0 Binary files /dev/null and b/dlls/MV3D/Win64_x64/libwinpthread-1.dll differ diff --git a/dlls/MV3D/Win64_x64/log4cpp_MD_VC120_v3_0_MV_3D.dll b/dlls/MV3D/Win64_x64/log4cpp_MD_VC120_v3_0_MV_3D.dll new file mode 100644 index 0000000..a175f7d Binary files /dev/null and b/dlls/MV3D/Win64_x64/log4cpp_MD_VC120_v3_0_MV_3D.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcm90.dll b/dlls/MV3D/Win64_x64/msvcm90.dll new file mode 100644 index 0000000..45fdb91 Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcm90.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcp120.dll b/dlls/MV3D/Win64_x64/msvcp120.dll new file mode 100644 index 0000000..60a9c0a Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcp120.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcp90.dll b/dlls/MV3D/Win64_x64/msvcp90.dll new file mode 100644 index 0000000..a1727ca Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcp90.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcr100.dll b/dlls/MV3D/Win64_x64/msvcr100.dll new file mode 100644 index 0000000..6a02bc4 Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcr100.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcr120.dll b/dlls/MV3D/Win64_x64/msvcr120.dll new file mode 100644 index 0000000..c58afec Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcr120.dll differ diff --git a/dlls/MV3D/Win64_x64/msvcr90.dll b/dlls/MV3D/Win64_x64/msvcr90.dll new file mode 100644 index 0000000..0ae568a Binary files /dev/null and b/dlls/MV3D/Win64_x64/msvcr90.dll differ diff --git a/dlls/MV3D/Win64_x64/pthreadGC2.dll b/dlls/MV3D/Win64_x64/pthreadGC2.dll new file mode 100644 index 0000000..841d4a2 Binary files /dev/null and b/dlls/MV3D/Win64_x64/pthreadGC2.dll differ diff --git a/dlls/MV3D/Win64_x64/pthreadVC2.dll b/dlls/MV3D/Win64_x64/pthreadVC2.dll new file mode 100644 index 0000000..165b4d2 Binary files /dev/null and b/dlls/MV3D/Win64_x64/pthreadVC2.dll differ diff --git a/dlls/MV3D/Win64_x64/svml_dispmd.dll b/dlls/MV3D/Win64_x64/svml_dispmd.dll new file mode 100644 index 0000000..859050b Binary files /dev/null and b/dlls/MV3D/Win64_x64/svml_dispmd.dll differ diff --git a/dlls/MV3D/Win64_x64/swscale-6.dll b/dlls/MV3D/Win64_x64/swscale-6.dll new file mode 100644 index 0000000..34879aa Binary files /dev/null and b/dlls/MV3D/Win64_x64/swscale-6.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/HikStl2Vet.dll b/dlls/Mv3dRgbdSDK/Win64_x64/HikStl2Vet.dll new file mode 100644 index 0000000..5f60a08 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/HikStl2Vet.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/Mv3DDataProcess.dll b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3DDataProcess.dll new file mode 100644 index 0000000..ad06e94 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3DDataProcess.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dCalibUtil.dll b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dCalibUtil.dll new file mode 100644 index 0000000..b906809 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dCalibUtil.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbd.dll b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbd.dll new file mode 100644 index 0000000..04061da Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbd.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdCfg.ini b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdCfg.ini new file mode 100644 index 0000000..745da45 --- /dev/null +++ b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdCfg.ini @@ -0,0 +1,98 @@ +# Don't modify this configuration file if you don't know what are you doing. +# -------------------------------------------------------------------------- +# 1.LogConfig:日志配置 +# 1.1.LogSize:日志大小 +# 单位:MB,默认值:100,仅支持整数; +# 当配置的值大于1000时,内部按1000生效; +# 当配置的值小于5时,内部按5生效; + +# 2.CameraConfig:相机配置 +# 2.1.BufferNode:取流数据节点 +# 表示SDK内部图像缓存节点个数 +# 默认值:5,仅支持配置大于或等于1的整数值; +# 当配置大于5时,可能导致实时性下降,不要轻易改动; +# 2.2.DeviceFilterEnable:枚举RGB-D设备使能 +# 开启:1,关闭:0; 默认值:1 +# 当开启时,仅枚举RGB-D设备; + +# 3.Debug:调试配置 +# 3.1.DebugMode:调试模式开关 +# 开启:1,关闭:0; 默认值:0 +# 当开启时,会打印较多日志,并开启core; + +# 4.Thread:线程配置 +# 4.1.RectThread:异步矫正使能 +# 开启:1,关闭:0; 默认值:1 +# 当开启时,SDK内部会对Chunk通道的RGB进行异步矫正,增加图像帧率; +# 4.2.RectTimeOut:异步矫正超时时间 +# 表示等待异步矫正算法处理完成信号的最大时间; +# 单位:ms,默认值:1000 + +# 5.CameraLog:相机日志 +# 5.1.CameraLogEnable:相机日志使能 +# 开启:1,关闭:0; 默认值:1 +# 当开启时,SDK会保存相机日志至本地文件夹 +# 5.2.CameraLogPort:日志远程端口 +# 默认值:514 +# 5.3.CameraLogLevel:日志等级 +# 1:error,2:warning,3:info,4:debug; 默认值:3 +# 5.4.CameraLogSize:日志大小 +# 单位:MB,默认值:100,仅支持整数 + +# -------------------------------------------------------------------------- +# 1.LogConfig: Log config +# 1.1.LogSize: Log size. +# Unit: MB; Default: 100; only support integer. +# +# 2.CameraConfig: Camera config +# 2.1.BufferNode: Fetch data buffer node. +# Number of image cache nodes in SDK. +# Default: 5, only integer values greater than or equal to 1 can be configured. +# When the configuration is greater than 5, the real-time performance may decrease, so do not change it easily. +# 2.2.DeviceFilterEnable: Enumerate RGB-D devices switch. +# Open: 1; Close: 0; Default: 1 +# When switch open, only enumerate RGB-D devices. + +# 3.Debug: Debug config +# 3.1.DebugMode: Debug mode switch. +# Open: 1; Close: 0; Default: 0 +# When debug mode open, more logs are printed and core is enabled. +# +# 4.Thread: Thread config +# 4.1.RectThread: Multithread switch. +# Open: 1; Close: 0; Default: 1 +# When multithread open, the sdk uses multiple threads for rgb correction of chunk channel to increase the image frame rate. +# 4.2.RectTimeOut: Multithread wait times +# The maximum time waiting for the multithreaded correction algorithm to complete +# Unit: ms; Default: 1000 + +# 5.CameraLog: Camera log +# 5.1.CameraLogEnable: Camera log switch. +# Open: 1; Close: 0; Default: 1 +# When switch open, camera log will be saved to local file. +# 5.2.CameraLogPort: Device log remote port +# Default: 514 +# 5.3.CameraLogLevel: Log level +# 1: error; 2: warning; 3: info; 4: debug; Default: 3 +# 5.4.CameraLogSize: Log size +# Unit: MB; Default: 100; only support integer. + +[LogConfig] +LogSize=100 + +[CameraConfig] +BufferNode=5 +DeviceFilterEnable=1 + +[Debug] +DebugMode=0 + +[Thread] +RectThread=1 +RectTimeOut=1000 + +[CameraLog] +CameraLogEnable=0 +CameraLogPort=8192 +CameraLogLevel=3 +CameraLogSize=100 \ No newline at end of file diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdSDK.dll b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdSDK.dll new file mode 100644 index 0000000..3c104ab Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/Mv3dRgbdSDK.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/MvUdp.dll b/dlls/Mv3dRgbdSDK/Win64_x64/MvUdp.dll new file mode 100644 index 0000000..958dd92 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/MvUdp.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/assimp-vc142-mt.dll b/dlls/Mv3dRgbdSDK/Win64_x64/assimp-vc142-mt.dll new file mode 100644 index 0000000..59b02e9 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/assimp-vc142-mt.dll differ diff --git a/dlls/Mv3dRgbdSDK/Win64_x64/qhull_r.dll b/dlls/Mv3dRgbdSDK/Win64_x64/qhull_r.dll new file mode 100644 index 0000000..2d797e0 Binary files /dev/null and b/dlls/Mv3dRgbdSDK/Win64_x64/qhull_r.dll differ diff --git a/image.py b/image.py new file mode 100644 index 0000000..e4122cc --- /dev/null +++ b/image.py @@ -0,0 +1,212 @@ +import numpy as np +import cv2 +import matplotlib.pyplot as plt + +from scipy.ndimage import label + +import config + + +def point_cloud_to_2d_image(points, resolution=1.0, x_range=(17, 275), y_range=(-129, -1227)): + """ + 将点云转换为 2D 图像(X-Y 平面),每个像素值表示对应位置的 Z 值平均值 + """ + if not isinstance(points, np.ndarray): + points = np.array(points) + + if len(points) == 0: + raise ValueError("点云为空") + + x_min, x_max = x_range + y_min, y_max = y_range + + width = int((x_max - x_min) / resolution) + 1 + height = int((y_max - y_min) / resolution) + 1 + + image = np.zeros((height, width), dtype=np.float32) + count_map = np.zeros((height, width), dtype=np.int32) + + for x, y, z in points: + xi = int((x - x_min) / resolution) + yi = int((y - y_min) / resolution) + + if 0 <= xi < width and 0 <= yi < height: + image[yi, xi] += z + count_map[yi, xi] += 1 + + # 防止除零错误 + count_map[count_map == 0] = 1 + image /= count_map + + return image, (x_min, y_min) + + +def detect_holes_by_density(density_map, density_threshold_ratio=0.5, min_area=100): + """ + 基于点云密度图识别空洞区域 + + :param density_map: 2D numpy array, 每个像素表示该位置点云密度 + :param density_threshold_ratio: 密度低于均值的 ratio 倍时视为空洞候选 + :param min_area: 最小空洞面积(像素数) + :return: list of ((cx, cy), area),空洞中心和面积(图像坐标) + """ + # 计算邻域平均密度(3x3窗口) + avg_density = np.zeros_like(density_map) + for i in range(density_map.shape[0]): + for j in range(density_map.shape[1]): + # 取 3x3 邻域 + neighbors = density_map[ + max(0, i - 1):min(i + 2, density_map.shape[0]), + max(0, j - 1):min(j + 2, density_map.shape[1]) + ] + avg_density[i, j] = np.mean(neighbors) + + # 构建空洞候选区:密度低于邻域平均值的 50% + binary_map = (density_map < avg_density * density_threshold_ratio).astype(np.uint8) + + # 连通域分析 + structure = np.array([[1, 1, 1], + [1, 1, 1], + [1, 1, 1]]) + labeled_map, num_features = label(binary_map, structure=structure) + + holes = [] + for label_id in range(1, num_features + 1): + coords = np.where(labeled_map == label_id) + hole_pixel_count = len(coords[0]) + + if hole_pixel_count >= min_area: + cx = np.mean(coords[1]) # x 坐标(列) + cy = np.mean(coords[0]) # y 坐标(行) + area = hole_pixel_count + holes.append(((cx, cy), area)) + + return holes + + +def detect_black_regions(binary_mask, min_area=10): + """ + 检测图像中的黑色连通区域(值为 0 的区域) + + :param binary_mask: 2D numpy array, 二值图(0 表示黑色区域) + :param min_area: int, 最小面积阈值,小于该值的区域会被忽略 + :return: list of dict, 包含每个区域的信息: + [ + { + 'id': int, + 'center': (cx, cy), + 'area': int, + 'coordinates': [(x1,y1), (x2,y2), ...] + }, + ... + ] + """ + # 确保输入是二值图像(0 是黑) + binary = (binary_mask == 0).astype(np.uint8) + + # 使用连通域分析 + structure = np.array([[1, 1, 1], + [1, 1, 1], + [1, 1, 1]]) + labeled_map, num_features = label(binary, structure=structure) + + regions = [] + + for label_id in range(1, num_features + 1): + coords = np.where(labeled_map == label_id) + area = len(coords[0]) + + if area >= min_area: + cx = np.mean(coords[1]) # x 坐标(列) + cy = np.mean(coords[0]) # y 坐标(行) + + regions.append(((cx, cy),area)) + + + return regions +def convert_image_holes_to_real(holes, offset, resolution): + real_holes = [] + x_min, y_min = offset + for ((cx, cy), area) in holes: + real_x = x_min + cx * resolution + real_y = y_min + cy * resolution + real_holes.append(((real_x, real_y), area * resolution ** 2)) + return real_holes + + +def visualize_holes_on_image(image, holes, output_path=None): + """ + 在图像上画出检测到的空洞中心和轮廓 + """ + # 彩色化灰度图用于可视化 + color_image = cv2.cvtColor(image, cv2.COLOR_GRAY2BGR) + + for (cx, cy), _ in holes: + # 绘制圆形标注空洞中心 + cv2.circle(color_image, (int(cx), int(cy)), radius=5, color=(0, 0, 255), thickness=-1) + + # 显示图像 + # plt.figure(figsize=(10, 8)) + plt.imshow(cv2.cvtColor(color_image, cv2.COLOR_BGR2RGB)) + # plt.title("Detected Holes") + plt.axis("off") + output_path = config.save_path("image", "_holes.png") + if output_path: + plt.savefig(output_path, bbox_inches='tight', dpi=200) + print(f"Saved visualization to {output_path}") + # plt.show() + +def read_pcd_points(pcd_path): + """ + 从 .pcd 文件中提取点云坐标 (x, y, z) + + :param pcd_path: str, PCD 文件路径 + :return: list of [x, y, z], 点云坐标列表 + """ + points = [] + data_started = False + + with open(pcd_path, 'r') as f: + for line in f: + if line.startswith("DATA"): + data_started = True + continue + if data_started: + parts = line.strip().split() + if len(parts) >= 3: + try: + x = float(parts[0]) + y = float(parts[1]) + z = float(parts[2]) + points.append([x, y, z]) + except ValueError: + continue + return points + +def detect_large_holes(points,sn, x_max): + + # 2. 生成 2D 图像 + x_range = (config.CUT_CONFIG_MAP[sn]["min_pt"][0],x_max) # 手动指定 X 范围 + y_range = (config.CUT_CONFIG_MAP[sn]["min_pt"][1], config.CUT_CONFIG_MAP[sn]["max_pt"][1]) # 注意:这里要保证 y_min < y_max,否则反转一下 + resolution = config.CAMERA_CONFIG_MAP[sn].get("resolution") + image, offset = point_cloud_to_2d_image(points, resolution=resolution, x_range=x_range, y_range=y_range) + + # 3. 图像归一化用于可视化 + normalized_image = cv2.normalize(image, None, 0, 255, cv2.NORM_MINMAX).astype(np.uint8) + + # 4. 检测空洞 + holes = detect_black_regions(normalized_image, min_area=20) + + # 5. 可视化空洞 + visualize_holes_on_image(normalized_image, holes) + + # 6. 输出真实世界坐标 + real_holes = convert_image_holes_to_real(holes, offset, resolution) + return real_holes + +if __name__ == '__main__': + points = read_pcd_points("D:/PycharmProjects/Hik3D/image/2025-06-25/pcd/182109899_00DA6823936_merged.pcd") + sn = "00DA6823936" + x_max = 326 + detect_large_holes(points,sn, x_max) + \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..1af8476 --- /dev/null +++ b/main.py @@ -0,0 +1,62 @@ +# 这是一个示例 Python 脚本。 + +# 按 Shift+F10 执行或将其替换为您的代码。 +# 按 双击 Shift 在所有地方搜索类、文件、工具窗口、操作和设置。 +import SimpleView_SaveImage as simple +import config +from Point import tiff_depth_to_point_clouds + +from flask import Flask, jsonify, request + +app = Flask(__name__) + +# 示例接口:GET 请求 +@app.route("/config/update") +def home(): + config.load_configs() + return "Hello, this service config update!" + +# 示例接口:返回 JSON 数据 +@app.route("/api/data") +def get_data(): + data = {"message": "This is some data", "status": "OK"} + return jsonify(data) + +# 示例接口:接收参数 +# 示例接口:接收参数 +@app.route("/api/compute/") +def compute(direction): + try: + sn = config.DIRECTION_CAMERA[direction] + except KeyError: + return jsonify({"message": "", "status": "ERROR", "error": f"Direction '{direction}' not found in DIRECTION_CAMERA"}), 400 + + try: + tiff_paths = simple.pic(sn) + except Exception as e: + return jsonify({"message": "", "status": "ERROR", "error": f"Failed to get TIFF paths: {str(e)}"}), 500 + + try: + rest = tiff_depth_to_point_clouds(tiff_paths, sn, dedup=True) + except Exception as e: + return jsonify({"message": "", "status": "ERROR", "error": f"Point cloud processing failed: {str(e)}"}), 500 + + print(rest) + return jsonify({"message": rest, "status": "OK"}) + +@app.errorhandler(Exception) +def handle_exception(e): + # 处理所有未被捕获的异常 + return jsonify({ + "message": "", + "status": "ERROR", + "error": str(e) + }), 500 + + +if __name__ == "__main__": + from waitress import serve + + print("Serving on http://0.0.0.0:5000") + serve(app, host='0.0.0.0', port=5000) + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..edaf210 Binary files /dev/null and b/requirements.txt differ