hyper_lpr_sdk.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. //
  2. // Created by tunm on 2023/1/25.
  3. //
  4. #ifndef ZEPHYRLPR_HYPER_LPR_SDK_H
  5. #define ZEPHYRLPR_HYPER_LPR_SDK_H
  6. #include <stdint.h>
  7. #if defined(_WIN32)
  8. #ifdef HYPER_BUILD_SHARED_LIB
  9. #define HYPER_CAPI_EXPORT __declspec(dllexport)
  10. #else
  11. #define HYPER_CAPI_EXPORT
  12. #endif
  13. #else
  14. #define HYPER_CAPI_EXPORT __attribute__((visibility("default")))
  15. #endif // _WIN32
  16. #ifdef __cplusplus
  17. extern "C" {
  18. #endif
  19. /**
  20. * API Result - API调用结果
  21. * */
  22. typedef int HREESULT;
  23. typedef enum HResultCode{
  24. Ok = 0,
  25. Err = -1,
  26. } HResultCode;
  27. /**
  28. * camera stream format - 支持的相机流格式
  29. * Contains several common camera stream formats on the market -
  30. * 包含了几款市面上常见的相机流格式
  31. */
  32. typedef enum HLPR_ImageFormat {
  33. STREAM_RGB = 0, ///< Image in RGB format - RGB排列格式的图像
  34. STREAM_BGR = 1, ///< Image in BGR format (Opencv Mat default) - BGR排列格式的图像(OpenCV的Mat默认)
  35. STREAM_RGBA = 2, ///< Image in RGB with alpha channel format - 带alpha通道的RGB排列格式的图像
  36. STREAM_BGRA = 3, ///< Image in BGR with alpha channel format - 带alpha通道的BGR排列格式的图像
  37. STREAM_YUV_NV12 = 4, ///< Image in YUV NV12 format - YUV NV12排列的图像格式
  38. STREAM_YUV_NV21 = 5, ///< Image in YUV NV21 format - YUV NV21排列的图像格式
  39. } HLPR_ImageFormat;
  40. /**
  41. * Camera picture corner mode - 相机画面转角模式
  42. * To cope with the rotation of some devices, four image rotation modes are provided here -
  43. * 为应对某些设备的画面自带旋转,这里提供四种图像旋转模式
  44. */
  45. typedef enum HLPR_Rotation {
  46. CAMERA_ROTATION_0 = 0, ///< 0 degree - 0
  47. CAMERA_ROTATION_90 = 1, ///< 90 degree - 90
  48. CAMERA_ROTATION_180 = 2, ///< 180 degree - 180
  49. CAMERA_ROTATION_270 = 3, ///< 270 degree - 270
  50. } HLPR_Rotation;
  51. /**
  52. * Image Buffer Data struct - 图像数据流结构
  53. * */
  54. typedef struct HLPR_ImageData {
  55. uint8_t *data; ///< Image data stream - 图像数据流
  56. int width; ///< Width of the image - 宽
  57. int height; ///< Height of the image - 高
  58. HLPR_ImageFormat format; ///< Format of the image - 传入需要解析数据流格式
  59. HLPR_Rotation rotation; ///< The rotation Angle of the image - 图像的画面旋转角角度
  60. } HLPR_ImageData, *P_HLPR_ImageData;
  61. /**
  62. * Plate layers - 车牌层数
  63. * */
  64. typedef enum HLPR_PlateLayers {
  65. PLATE_LAYERS_MONO = 0, ///< 单层车牌
  66. PLATE_LAYERS_DOUBLE, ///< 双层车牌
  67. } HLPR_Layers;
  68. /**
  69. * Detector Level - 检测器等级
  70. * */
  71. typedef enum HLPR_DetectLevel {
  72. DETECT_LEVEL_LOW = 0, ///< 高开销检测模式 (推荐)
  73. DETECT_LEVEL_HIGH, ///< 低开销检测模式
  74. } HLPR_DetectLevel;
  75. /**
  76. * PlateType Type - 车牌类型(中国)
  77. * */
  78. typedef enum HLPR_PlateType {
  79. PLATE_TYPE_UNKNOWN = -1, ///< 未知车牌
  80. PLATE_TYPE_BLUE = 0, ///< 蓝牌
  81. PLATE_TYPE_YELLOW_SINGLE = 1, ///< 黄牌单层
  82. PLATE_TYPE_WHILE_SINGLE = 2, ///< 白牌单层
  83. PLATE_TYPE_GREEN = 3, ///< 绿牌新能源
  84. PLATE_TYPE_BLACK_HK_MACAO = 4, ///< 黑牌港澳
  85. PLATE_TYPE_HK_SINGLE = 5, ///< 香港单层
  86. PLATE_TYPE_HK_DOUBLE = 6, ///< 香港双层
  87. PLATE_TYPE_MACAO_SINGLE = 7, ///< 澳门单层
  88. PLATE_TYPE_MACAO_DOUBLE = 8, ///< 澳门双层
  89. PLATE_TYPE_YELLOW_DOUBLE = 9, ///< 黄牌双层
  90. } HLPR_PlateType;
  91. /**
  92. * Plate Result - 车牌检测结果
  93. * */
  94. typedef struct HLPR_PlateResult {
  95. float x1; ///< 左上角点x坐标
  96. float y1; ///< 左上角点y坐标
  97. float x2; ///< 右下角点x坐标
  98. float y2; ///< 右下角点y坐标
  99. HLPR_PlateType type; ///< 车牌类型
  100. float text_confidence; ///< 置信度
  101. char code[128]; ///< 车牌号码字符串
  102. } HLPR_PlateResult, *P_HLPR_PlateResult;
  103. /**
  104. * Plate Result List - 车牌检测结果列表
  105. * */
  106. typedef struct HLPR_PlateResultList {
  107. unsigned long plate_size; ///< 车牌数量
  108. P_HLPR_PlateResult plates; ///< 检测车牌结果列表
  109. } HLPR_PlateResultList, *P_HLPR_PlateResultList;
  110. /**
  111. * HyperLPR Context Instantiating parameters - Context的实例化参数对象
  112. * */
  113. typedef struct HLPR_ContextConfiguration {
  114. char *models_path; ///< 模型文件地址
  115. int max_num; ///< 识别最大数量
  116. int threads; ///< 线程数 (推荐1)
  117. bool use_half; ///< 是否使用半精度推理模式
  118. float box_conf_threshold; ///< 检测框阈值
  119. float nms_threshold; ///< 非极大值抑制阈值
  120. float rec_confidence_threshold; ///< 识别置信度阈值
  121. HLPR_DetectLevel det_level; ///< 检测器等级(推荐low)
  122. } HLPR_ContextConfiguration, *P_HLPR_ContextConfiguration;
  123. /**
  124. * Data Buffer - 数据缓冲流
  125. * */
  126. typedef struct HLPR_DataBuffer HLPR_DataBuffer, *P_HLPR_DataBuffer;
  127. /**
  128. * The runtime object after HyperLPR is instantiated - 实例化运行时的Context对象
  129. * */
  130. typedef struct HLPR_Context HLPR_Context, *P_HLPR_Context;
  131. /************************************************************************
  132. * Carry parameters to create a data buffer stream instantiation object.
  133. * 携带创建数据缓冲流实例化对象.
  134. * [out] return: Model instant handle - 返回实例化后的指针句柄
  135. ************************************************************************/
  136. HYPER_CAPI_EXPORT extern P_HLPR_DataBuffer HLPR_CreateDataBuffer(
  137. P_HLPR_ImageData data // [in] Image Buffer Data struct - 图像数据流结构
  138. );
  139. /************************************************************************
  140. * Create a data buffer stream instantiation object.
  141. * 创建数据缓冲流实例化对象.
  142. * [out] return: Model instant handle - 返回实例化后的指针句柄
  143. ************************************************************************/
  144. HYPER_CAPI_EXPORT extern P_HLPR_DataBuffer HLPR_CreateDataBufferEmpty();
  145. /************************************************************************
  146. * Set the DataBuffer rotation mode.
  147. * 设置DataBuffer旋转模式.
  148. * [out] Result Code - 返回结果码
  149. ************************************************************************/
  150. HYPER_CAPI_EXPORT extern HREESULT HLPR_DataBufferSetData(
  151. P_HLPR_DataBuffer buffer, // [in] DataBuffer handle - 相机流组件的句柄指针
  152. const uint8_t *data, // [in] Raw data stream - 原始的数据流
  153. int width, // [in] Image width - 图像宽度
  154. int height // [in] Image height - 图像高度
  155. );
  156. /************************************************************************
  157. * Set the DataBuffer data format.
  158. * 设置DataBuffer数据格式.
  159. * [out] Result Code - 返回结果码
  160. ************************************************************************/
  161. HYPER_CAPI_EXPORT extern HREESULT HLPR_DataBufferSetRotationMode(
  162. P_HLPR_DataBuffer buffer, // [in] DataBuffer handle - 数据流组件的句柄指针
  163. HLPR_Rotation mode // [in] DataBuffer mode - 数据流组件旋转模式
  164. );
  165. /************************************************************************
  166. * Set the DataBuffer rotation mode.
  167. * 设置DataBuffer旋转模式.
  168. * [out] Result Code - 返回结果码
  169. ************************************************************************/
  170. HYPER_CAPI_EXPORT extern HREESULT HLPR_DataBufferSetStreamFormat(
  171. P_HLPR_DataBuffer buffer, // [in] DataBuffer handle - 数据流组件的句柄指针
  172. HLPR_ImageFormat mode // [in] DataBuffer data format - 数据流组件数据格式
  173. );
  174. /************************************************************************
  175. * Releases the DataBuffer object that has been instantiated.
  176. * 释放已经被实例化后的模型对象.
  177. * [out] Result Code - 返回结果码
  178. ************************************************************************/
  179. HYPER_CAPI_EXPORT extern HREESULT HLPR_ReleaseDataBuffer(
  180. P_HLPR_DataBuffer buffer // [in] DataBuffer handle - 相机流组件的句柄指针
  181. );
  182. /************************************************************************
  183. * Create a data Context instantiation object.
  184. * 创建Context实例化对象.
  185. * [out] Result Code - 返回结果码
  186. ************************************************************************/
  187. HYPER_CAPI_EXPORT extern P_HLPR_Context HLPR_CreateContext(
  188. P_HLPR_ContextConfiguration configuration // [in] Context configuration - 配置表
  189. );
  190. /************************************************************************
  191. * Query the Context instantiation state.
  192. * 查询实例化后的状态.
  193. * [out] Result Code - 返回结果码
  194. ************************************************************************/
  195. HYPER_CAPI_EXPORT extern HREESULT HLPR_ContextQueryStatus(
  196. P_HLPR_Context ctx // [in] Context handle - Context的指针句柄
  197. );
  198. /************************************************************************
  199. * Update Data Buffer Stream.
  200. * 喂入数据流并更新进行车牌识别.
  201. * [out] Result Code - 返回结果码
  202. ************************************************************************/
  203. HYPER_CAPI_EXPORT extern HREESULT HLPR_ContextUpdateStream(
  204. P_HLPR_Context ctx, // [in] Context handle - Context的指针句柄
  205. P_HLPR_DataBuffer buffer, // [in] DataBuffer handle - 数据流组件的句柄指针
  206. P_HLPR_PlateResultList results // [out] Results List - 返回结果的列表
  207. );
  208. /************************************************************************
  209. * Release Context.
  210. * 释放Context的实例化对象.
  211. * [out] Result Code - 返回结果码
  212. ************************************************************************/
  213. HYPER_CAPI_EXPORT extern HREESULT HLPR_ReleaseContext(
  214. P_HLPR_Context ctx // [in] Context handle - Context的指针句柄
  215. );
  216. //HYPER_CAPI_EXPORT extern HREESULT HLPR_DataBufferTest(P_HLPR_DataBuffer buffer, const char *save_path);
  217. #ifdef __cplusplus
  218. }
  219. #endif
  220. #endif //ZEPHYRLPR_HYPER_LPR_SDK_H