- 图漾深度相机SDK相关理论基础
目标
- 通过SDK提供的C++接口,拉取图像相机的视频流,解码成RGB图和深度图
参考示例使用到的接口
- SimpleView_FetchFrame
选择设备
1
2
3
4
5
/// @brief Update current interfaces.
/// call before TYGetInterfaceList
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
TY_CAPI TYUpdateInterfaceList ();
1
2
3
4
5
6
/// @brief Get number of current interfaces.
/// @param [out] pNumIfaces Number of interfaces.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_NULL_POINTER deviceNumber is NULL.
TY_CAPI TYGetInterfaceNumber (uint32_t* pNumIfaces);
1
2
3
4
5
6
7
8
9
///@see TYGetInterfaceList
typedef struct TY_INTERFACE_INFO
{
char name[32];
char id[32];
TY_INTERFACE_TYPE type;
char reserved[4];
TY_DEVICE_NET_INFO netInfo; // only meaningful when TYIsNetworkInterface(type)
}TY_INTERFACE_INFO;
1
2
3
4
5
6
7
8
/// @brief Get interface info list.
/// @param [out] pIfaceInfos Array of interface infos to be filled.
/// @param [in] bufferCount Array size of interface infos.
/// @param [out] filledCount Number of filled TY_INTERFACE_INFO.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_NULL_POINTER pIfaceInfos or filledCount is NULL.
TY_CAPI TYGetInterfaceList (TY_INTERFACE_INFO* pIfaceInfos, uint32_t bufferCount, uint32_t* filledCount);
1
2
3
4
5
6
7
8
//------------------------------------------------------------------------------
// inlines
//------------------------------------------------------------------------------
static inline bool TYIsNetworkInterface(int32_t interfaceType)
{
return (interfaceType == TY_INTERFACE_ETHERNET) ||
(interfaceType == TY_INTERFACE_IEEE80211);
}
1
2
typedef void* TY_INTERFACE_HANDLE; ///<Interface handle
typedef void* TY_DEV_HANDLE;///<Device Handle
1
2
3
4
5
6
7
8
9
/// @brief Open specified interface.
/// @param [in] ifaceID Interface ID string, can be get from TY_INTERFACE_INFO.
/// @param [out] outHandle Handle of opened interface.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_NULL_POINTER ifaceID or outHandle is NULL.
/// @retval TY_STATUS_INVALID_INTERFACE Interface not found.
/// @see TYGetInterfaceList
TY_CAPI TYOpenInterface (const char* ifaceID, TY_INTERFACE_HANDLE* outHandle);
1
2
3
4
5
6
/// @brief Update current connected devices.
/// @param [in] ifaceHandle Interface handle.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_INVALID_INTERFACE Invalid interface handle.
TY_CAPI TYUpdateDeviceList (TY_INTERFACE_HANDLE ifaceHandle);
1
2
3
4
5
6
7
8
/// @brief Get number of current connected devices.
/// @param [in] ifaceHandle Interface handle.
/// @param [out] deviceNumber Number of connected devices.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_INVALID_INTERFACE Invalid interface handle.
/// @retval TY_STATUS_NULL_POINTER deviceNumber is NULL.
TY_CAPI TYGetDeviceNumber (TY_INTERFACE_HANDLE ifaceHandle, uint32_t* deviceNumber);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
///@see TYGetDeviceList
typedef struct TY_DEVICE_BASE_INFO
{
TY_INTERFACE_INFO iface;
char id[32];///<device serial number
char vendorName[32];
char userDefinedName[32];
char modelName[32];///<device model name
TY_VERSION_INFO hardwareVersion; ///<deprecated
TY_VERSION_INFO firmwareVersion;///<deprecated
union {
TY_DEVICE_NET_INFO netInfo;
TY_DEVICE_USB_INFO usbInfo;
};
char buildHash[256];
char configVersion[256];
char reserved[256];
}TY_DEVICE_BASE_INFO;
1
2
3
4
5
6
7
8
9
10
/// @brief Get device info list.
/// @param [in] ifaceHandle Interface handle.
/// @param [out] deviceInfos Device info array to be filled.
/// @param [in] bufferCount Array size of deviceInfos.
/// @param [out] filledDeviceCount Number of filled TY_DEVICE_BASE_INFO.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_INVALID_INTERFACE Invalid interface handle.
/// @retval TY_STATUS_NULL_POINTER deviceInfos or filledDeviceCount is NULL.
TY_CAPI TYGetDeviceList (TY_INTERFACE_HANDLE ifaceHandle, TY_DEVICE_BASE_INFO* deviceInfos, uint32_t bufferCount, uint32_t* filledDeviceCount);
1
2
3
4
5
6
/// @brief Close interface.
/// @param [in] ifaceHandle Interface to be closed.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_NOT_INITED TYInitLib not called.
/// @retval TY_STATUS_INVALID_INTERFACE Interface not found.
TY_CAPI TYCloseInterface (TY_INTERFACE_HANDLE ifaceHandle);
获取一帧图
1
2
3
4
//------------------------------------------------------------------------------
// C API
//------------------------------------------------------------------------------
#define TY_CAPI TY_EXTC TY_EXPORT TY_STATUS TY_STDC
1
2
typedef void* TY_INTERFACE_HANDLE; ///<Interface handle
typedef void* TY_DEV_HANDLE;///<Device Handle
1
2
3
4
5
6
7
8
typedef struct TY_FRAME_DATA
{
void* userBuffer; ///< Pointer to user enqueued buffer, user should enqueue this buffer in the end of callback
int32_t bufferSize; ///< Size of userBuffer
int32_t validCount; ///< Number of valid data
int32_t reserved[6]; ///< Reserved: reserved[0],laser_val;
TY_IMAGE_DATA image[10]; ///< Buffer data, max to 10 images per frame, each buffer data could be an image or something else.
}TY_FRAME_DATA;
1
2
3
4
5
6
7
8
9
10
11
/// @brief Fetch one frame.
/// @param [in] hDevice Device handle.
/// @param [out] frame Frame data to be filled.
/// @param [in] timeout Timeout in milliseconds. <0 for infinite.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_INVALID_HANDLE Invalid device handle.
/// @retval TY_STATUS_NULL_POINTER frame is NULL.
/// @retval TY_STATUS_IDLE Device capturing is not started.
/// @retval TY_STATUS_WRONG_MODE Callback has been registered, this function is disabled.
/// @retval TY_STATUS_TIMEOUT Timeout.
TY_CAPI TYFetchFrame (TY_DEV_HANDLE hDevice, TY_FRAME_DATA* frame, int32_t timeout);
ISP 接口
- 简介
- 图像格式转换,将图像流转换为rgb图片
1
typedef void* TY_ISP_HANDLE;
1
TYISP_CAPI TYISPCreate(TY_ISP_HANDLE *handle);
1
2
//create a isp handle to convert raw image(color bayer format) to rgb image
ASSERT_OK(TYISPCreate(&hColorIspHandle));
1
2
3
//Init code can be modified in common.hpp
//NOTE: Should set RGB image format & size before init ISP
ASSERT_OK(ColorIspInitSetting(hColorIspHandle, hDevice));
1
2
///@breif called by main thread to update & control device status for ISP
TYISP_CAPI TYISPUpdateDevice(TY_ISP_HANDLE handle);
1
TYISP_CAPI TYISPRelease(TY_ISP_HANDLE *handle);
图像缓冲区
1
2
3
4
5
6
7
8
9
/// @brief Enqueue a user allocated buffer.
/// @param [in] hDevice Device handle.
/// @param [in] buffer Buffer to be enqueued.
/// @param [in] bufferSize Size of the input buffer.
/// @retval TY_STATUS_OK Succeed.
/// @retval TY_STATUS_INVALID_HANDLE Invalid device handle.
/// @retval TY_STATUS_NULL_POINTER buffer is NULL.
/// @retval TY_STATUS_WRONG_SIZE The input buffer is not large enough.
TY_CAPI TYEnqueueBuffer (TY_DEV_HANDLE hDevice, void* buffer, uint32_t bufferSize);
点云数据处理
深度数据图 ==> 点云
- TYMapDepthImageToPoint3d 转换深度数据图为点云,输入深度相机的标定数据,深度图宽、高、和深度图,输出点云。数值为 0 的无效深度点映射为 (NAN, NAN, NAN)。
1 2 3 4 5
TY_CAPI TYMapDepthImageToPoint3d (const TY_CAMERA_CALIB_INFO* src_calib, int32_t imageW, int32_t imageH, const uint16_t* depth, TY_VECT_3F* point3d, float f_scale_unit = 1.0f);
映射彩色图 到 深度图坐标
- TYMapRGBImageToDepthCoordinate 映射彩色图到深度图坐标。输入深度图标定数据、深度图宽和高、深度图、彩色图标定数据、彩色图宽和高、彩色图,输出映射后的彩色图像数据。
1 2 3 4 5 6 7
static inline TY_STATUS TYMapRGBImageToDepthCoordinate( const TY_CAMERA_CALIB_INFO* depth_calib, uint32_t depthW, uint32_t depthH, const uint16_t* depth, const TY_CAMERA_CALIB_INFO* color_calib, uint32_t rgbW, uint32_t rgbH, const uint8_t* inRgb, uint8_t* mappedRgb, float f_scale_unit = 1.0f);
图像处理
畸变矫正
- TYUndistortImage 畸变校正,可对传感器组件输出的图像做畸变处理,支持的数据格式包括:TY_PIXEL_FORMAT_MONO、TY_PIXEL_FORMAT_RGB、TY_PIXEL_FORMAT_BGR。输入参数为传感器标定数据、未矫正原始图像和期望的图像内参(输入为 NULL 则使用传感器原有内参),输出校正后的图像数据。
1 2 3 4 5
TY_CAPI TYUndistortImage (const TY_CAMERA_CALIB_INFO *srcCalibInfo , const TY_IMAGE_DATA *srcImage , const TY_CAMERA_INTRINSIC *cameraNewIntrinsic , TY_IMAGE_DATA *dstImage );