bef_effect_ai_slam.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273
  1. #ifndef _BEF_EFFECT_AI_SLAM_H
  2. #define _BEF_EFFECT_AI_SLAM_H
  3. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  4. #include <jni.h>
  5. #endif
  6. #include "bef_effect_ai_public_define.h"
  7. typedef unsigned long long bef_ai_slam_handle;
  8. typedef enum bef_ai_slam_image_color
  9. {
  10. BEF_AI_SLAM_RGB = 0,
  11. BEF_AI_SLAM_BGR,
  12. BEF_AI_SLAM_GRAY,
  13. }bef_ai_slam_image_color;
  14. typedef enum bef_ai_slam_device_orientation
  15. {
  16. BEF_AI_SLAM_Portrait = 0, // android: protrait
  17. BEF_AI_SLAM_LandscapeLeft,
  18. BEF_AI_SLAM_UpsideDown,
  19. BEF_AI_SLAM_LandscapeRight, // android: landscape
  20. }bef_ai_slam_device_orientation;
  21. typedef struct bef_ai_slam_camera_intrinsic{
  22. float fx; // focal length x
  23. float fy; // focal length y
  24. float cx; // optical center x
  25. float cy; // optical center y
  26. }bef_ai_slam_camera_intrinsic;
  27. typedef enum {
  28. BEF_AI_SLAM_480P = 0,
  29. BEF_AI_SLAM_720P,
  30. BEF_AI_SLAM_360P,
  31. BEF_AI_SLAM_180P
  32. }bef_ai_slam_resolution;
  33. typedef enum {
  34. BEF_AI_SLAM_High_Accuracy = 0,
  35. BEF_AI_SLAM_Medium_Accuracy,
  36. BEF_AI_SLAM_Low_Accuracy
  37. }bef_ai_slam_accuracy_level;
  38. typedef enum {
  39. BEF_AI_SLAM_Tracking_ERROR = -1, // Unknown error
  40. BEF_AI_SLAM_Tracking_INIT = 0, // Initialization state
  41. BEF_AI_SLAM_Tracking_TRACKING, // Tracking
  42. BEF_AI_SLAM_Tracking_LOST, // Tracking lost
  43. }bef_ai_slam_tracking_state;
  44. typedef struct bef_ai_slam_camera_info
  45. {
  46. bef_ai_slam_image_color color;
  47. int is_front;
  48. bef_ai_slam_device_orientation oriention;
  49. bef_ai_slam_camera_intrinsic camera_intrinsic;
  50. int disable_internal_time_delay; // disable the internal correction of time delay
  51. float horizontal_fov; // not used
  52. bef_ai_slam_resolution resolution;
  53. bool low_texture_enhanced; // disable it to speed up but worse results on low-texture regions
  54. bef_ai_slam_accuracy_level level;// default value is Medium, use Low for faster version
  55. int is_video; // use video mode
  56. int run_gba; // use gba
  57. int easy_init;
  58. // use fast initialization
  59. int width;
  60. int height;
  61. int enable_fusion;
  62. int enable_multi_planes;
  63. int enable_normal_model;
  64. }bef_ai_slam_camera_info;
  65. typedef struct bef_ai_slam_imu_info
  66. {
  67. int has_accelerometer; // TYPE_ACCELEROMETER
  68. int has_gyroscope; // TYPE_GYROSCOPE
  69. int has_gravity; // TYPE_GRAVITY
  70. int has_orientation; // TYPE_GAME_ROTATION_VECTOR or TYPE_ROTATION_VECTOR
  71. }bef_ai_slam_imu_info;
  72. typedef struct bef_ai_slam_imu_data
  73. {
  74. double acc[3]; // userAcceleration + gravity
  75. double gyro[3]; // gyro
  76. double gra[3]; // deprecated
  77. double wRb[9]; // attitude
  78. double time_stamp; // unit: second
  79. }bef_ai_slam_imu_data;
  80. typedef enum bef_ai_slam_imu_data_type{
  81. BEF_AI_SLAM_IMU_ACCELEROMETER = 0,
  82. BEF_AI_SLAM_IMU_GYROSCOPE,
  83. BEF_AI_SLAM_IMU_GRAVITY
  84. }bef_ai_slam_imu_data_type;
  85. typedef struct bef_ai_slam_click_flag {
  86. int is_clicked;
  87. float x; // normalized [0, 1] with screen width, which is the size of getIntrinsic
  88. float y; // normalized [0, 1] with screen height, which is the size of getIntrinsic
  89. }bef_ai_slam_click_flag;
  90. typedef struct bef_ai_slam_pose{
  91. float R[9]; // row major 3x3 rotation matrix
  92. float T[3]; // 3x1 translation matrix
  93. bef_ai_slam_tracking_state state;
  94. int plane_detected; // planeDetected 1, otherwise 0
  95. double time_stamp; // time for pose (unit is second), 0 for no time
  96. }bef_ai_slam_pose;
  97. typedef struct bef_ai_slam_plane {
  98. int has_plane; // 1 for detected plane, 0 for none
  99. float normal[3]; // plane normal in world frame
  100. float offset; // signed distance from world origin to plane in world frame.
  101. float origin_world[3]; // plane origin in world frame
  102. float origin[2]; // plane origin on image
  103. float* boundary; // plane boundary polygon on image [x1, y1, x2, y2, ...] (NULL if no boundary or
  104. // out of frame)
  105. int boundary_size; // plane boundary vertex size (not array size)
  106. int* plane_points_ids;
  107. int plane_points_size;
  108. }bef_ai_slam_plane;
  109. typedef struct bef_ai_slam_feature_points
  110. {
  111. int point_size; // number of points
  112. float* points; // points: [x1, y1, x2, y2, ...] (NULL if no points)
  113. float* depths; // depths: [d1, d2, ...] (NULL if no points or depths)
  114. int* ids; // ids: [i1, i2, ...] (NULL if no points of ids)
  115. }bef_ai_slam_feature_points;
  116. typedef enum {
  117. BEF_AI_SLAM_HorizontalPlaneTracking = 2,
  118. BEF_AI_SLAM_RegionTracking,
  119. }bef_ai_slam_version;
  120. /// Init camera info
  121. /// @param info camera info result
  122. BEF_SDK_API bef_effect_result_t
  123. bef_effect_ai_slam_init_camera_info(bef_ai_slam_camera_info* info);
  124. /// create slam handle
  125. /// @param handle ret handle
  126. /// @param modelPath slam model path
  127. /// @param deviceName device name
  128. /// @param camera camera info
  129. /// @param imu imu info data
  130. /// @param version different slam version
  131. BEF_SDK_API bef_effect_result_t
  132. bef_effect_ai_slam_create(bef_ai_slam_handle *handle, const char* modelPath, const char* deviceName, bef_ai_slam_camera_info* camera, bef_ai_slam_imu_info imu, bef_ai_slam_version version);
  133. /// change slam version
  134. /// @param version slam version
  135. BEF_SDK_API bef_effect_result_t
  136. bef_effect_ai_slam_set_version(bef_ai_slam_handle handle, bef_ai_slam_version version);
  137. /// set imu info, only ios use
  138. /// @param handle created slam handle
  139. /// @param imuData imudata
  140. BEF_SDK_API bef_effect_result_t
  141. bef_effect_ai_slam_set_imuinfo(bef_ai_slam_handle handle, const bef_ai_slam_imu_data* imuData);
  142. /// set detail imu info, android only
  143. /// @param handle created slam handle
  144. /// @param type device sensor type
  145. /// @param x x
  146. /// @param y y
  147. /// @param z z
  148. /// @param timeStamp timeStamp
  149. BEF_SDK_API bef_effect_result_t
  150. bef_effect_ai_slam_set_detail_imuinfo(bef_ai_slam_handle handle, bef_ai_slam_imu_data_type type, double x, double y, double z, double timeStamp);
  151. /// set rotation vector, android only
  152. /// @param handle created slam handle
  153. /// @param rb[9] rotation vectiron
  154. /// @param timeStamp timeStamp
  155. BEF_SDK_API bef_effect_result_t
  156. bef_effect_ai_slam_set_rotation_vector(bef_ai_slam_handle handle, const double rb[9], double timeStamp);
  157. /// slam detect plane and calc hitpoint when needed
  158. /// @param created slam handle
  159. /// @param image image buffer data
  160. /// @param width image buffer width
  161. /// @param height image buffer height
  162. /// @param channels image channels
  163. /// @param imageStride image stride
  164. /// @param timeStamp timeStamp
  165. /// @param flag click flag
  166. /// @param pose camera pose
  167. BEF_SDK_API bef_effect_result_t
  168. bef_effect_ai_slam_detect(bef_ai_slam_handle handle, const unsigned char* image, int width, int height, int channels,
  169. int imageStride, double timeStamp , bef_ai_slam_click_flag flag, bef_ai_slam_pose* pose);
  170. /// get slam pose, call this function when camera pose is available
  171. /// @param handle slam handle
  172. /// @param cameraPose camera pose from uppder function
  173. /// @param forceFacing 1
  174. /// @param flag click flog
  175. /// @param retPose plane pose
  176. BEF_SDK_API bef_effect_result_t
  177. bef_effect_ai_slam_get_plane_pose(bef_ai_slam_handle handle, bef_ai_slam_pose cameraPose, int forceFacing, bef_ai_slam_click_flag flag,
  178. bef_ai_slam_pose* retPose);
  179. /// get plane info, current no use
  180. /// @param handle slam handle
  181. /// @param cameraPose camera pose
  182. /// @param returnBoundary returnBoundary
  183. /// @param plane plane info
  184. BEF_SDK_API bef_effect_result_t
  185. bef_effect_ai_slam_get_plane(bef_ai_slam_handle handle, bef_ai_slam_pose cameraPose, int returnBoundary, bef_ai_slam_plane* plane);
  186. /// release plane info
  187. /// @param plane release plane addr
  188. BEF_SDK_API bef_effect_result_t
  189. bef_effect_ai_slam_release_plane(bef_ai_slam_handle, bef_ai_slam_plane* plane);
  190. /// get feature points
  191. /// @param handle slam handle
  192. /// @param points feature points
  193. BEF_SDK_API bef_effect_result_t
  194. bef_effect_ai_slam_get_feature_points(bef_ai_slam_handle handle, bef_ai_slam_feature_points* points);
  195. /// release feature points
  196. /// @param points feature points
  197. BEF_SDK_API void
  198. bef_effect_ai_slam_release_feature_points(bef_ai_slam_handle, bef_ai_slam_feature_points* points);
  199. /// get camera intrincis
  200. /// @param device_name device name
  201. /// @param param_file device camera intrinsic file
  202. /// @param width image buffer width
  203. /// @param height image buffer height
  204. /// @param intrinsic camera instrinsic
  205. BEF_SDK_API bef_effect_result_t
  206. bef_effect_ai_slam_get_intrinsic(bef_ai_slam_handle, const char* device_name, const char* param_file, int width, int height, bef_ai_slam_camera_intrinsic* intrinsic);
  207. /// reset slam handle
  208. BEF_SDK_API bef_effect_result_t
  209. bef_effect_ai_slam_reset(bef_ai_slam_handle);
  210. /// destroy slam handle
  211. BEF_SDK_API bef_effect_result_t
  212. bef_effect_ai_slam_destroy(bef_ai_slam_handle);
  213. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  214. /// check license offline
  215. /// @param env JNIEnv
  216. /// @param context jobject
  217. /// @param handle slam handle
  218. /// @param licensePath license path
  219. BEF_SDK_API bef_effect_result_t
  220. bef_effect_ai_slam_check_license(JNIEnv *env, jobject context, bef_ai_slam_handle handle, const char* licensePath);
  221. #elif TARGET_OS_IPHONE
  222. /// check license offline
  223. /// @param handle slam handle
  224. /// @param licensePath license path
  225. BEF_SDK_API bef_effect_result_t
  226. bef_effect_ai_slam_check_license(bef_ai_slam_handle handle, const char* licensePath);
  227. #endif
  228. /// check license online
  229. /// @param handle slam handle
  230. /// @param licensePath license path
  231. BEF_SDK_API bef_effect_result_t
  232. bef_effect_ai_slam_check_online_license(bef_ai_slam_handle handle, const char *licensePath);
  233. #endif