bef_effect_ai_object_tracking.h 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. #ifndef _BEF_EFFECT_AI_OBJECT_TRACKING_H
  2. #define _BEF_EFFECT_AI_OBJECT_TRACKING_H
  3. #include "bef_effect_ai_public_define.h"
  4. typedef unsigned long long bef_ai_object_tracking_handle;
  5. typedef enum {
  6. /// Original speed, slowest, but the accuracy is the highest
  7. bef_ai_object_tracking_speed_orig = 0,
  8. /// First level speed-up, faster compared with original speed, at the cost
  9. /// of some accucacy
  10. bef_ai_object_tracking_speed_up1 = 1,
  11. /// Second level speed-up, even faster than SpeedUp1, at the cost of more
  12. /// accuracy
  13. bef_ai_object_tracking_speed_up2 = 2,
  14. } bef_ai_object_tracking_speed;
  15. typedef struct bef_ai_object_tracking_param{
  16. /// Whether redetection is needed when tracking is lost.
  17. /// Default to true.
  18. bool needRedetection;
  19. /// Whether we need to reset tracking state. Reseting tracking states is
  20. /// used for tracking in recorded videos (e.g. pinning stickers), but for
  21. /// realtime videos (e.g. camera capture session) it is not needed and
  22. /// should be set to false.\n Default to true.
  23. bool needReset;
  24. /// Whether we perform texture evaluation for user-inputed bounding box.
  25. /// This is to help filtering out some bounding boxes that are certained
  26. /// to be hard to track, such as bounding boxes with no textures inside
  27. /// and at its surroundings.\n
  28. /// Default to true.\n
  29. bool needInitialBboxEvaluation;
  30. /// Padding for bounding box search area. Larger number
  31. /// leads to more robust tracking due to looking at larger areas, but
  32. /// at the cost of longer computation time per frame.\n
  33. /// Default value is 1.2, generally range from 1.0 to 2.0.
  34. float padding;
  35. /// @name Tracking related parameters
  36. /// Model potential scaling/rotating changes.\n
  37. /// track***Step: step size of each level of scale/angle change.\n
  38. /// trackNum***: number of levels for scale/angle change.\n
  39. /// More explanation: scale/level change works in both directions. For
  40. /// example, when the trackNumAngle is 3 and trackAngleStep is 15.f, this
  41. /// means the tracking algorithm will model 3 different scenarios: -15
  42. /// degrees, 0 degree and +15 degrees. Similar for scaling, when
  43. /// trackScaleStep is 2.0 and trackNumScale is 3, the algorithm will
  44. /// model original size, original size * 2, and original size / 2.\n
  45. /// trackNumScale and trackNumAngle should be odd numbers. When even numbers
  46. /// are used, the algorithm will add 1 to trackNumScale/trackNumAngle to
  47. /// make them odd numbers.\n Default values:\n trackAngleStep: 15.f (15
  48. /// degree)\n trackScaleStep: 1.1f\n trackNumScale: 3\n trackNumAngle: 3\n
  49. ///@{
  50. float trackAngleStep;
  51. float trackScaleStep;
  52. int trackNumScale;
  53. int trackNumAngle;
  54. ///@}
  55. /// @name Detection related parameters.
  56. /// detect***Step and detectNum*** behaves
  57. /// similar to tracking related parameters.\n
  58. /// detect***GridNum: number of segments per horizontal/vertical direction
  59. /// of the image. In each frame, we look into one position in each segment
  60. /// in horizontal/vertical direction. Thus, if detectHorizontalGridNum is 3
  61. /// and detectVerticalGridNum is 2, we will look into 2*3 = 6 positions
  62. /// each frame.\n
  63. /// default values:\n
  64. /// detectAngleStep: 15.f (15 degree)\n
  65. /// detectScaleStep: 2.f\n
  66. /// detectNumScale: 3\n
  67. /// detectNumAngle: 3\n
  68. /// detectHorizontalGridNum: 2\n
  69. /// detectVerticalGridNum: 2\n
  70. ///@{
  71. float detectAngleStep;
  72. float detectScaleStep;
  73. int detectNumScale;
  74. int detectNumAngle;
  75. int detectHorizontalGridNum;
  76. int detectVerticalGridNum;
  77. ///@}
  78. /// @name Feature score thresholds for detection/tracking
  79. /// Tracking has only one threshold, while detection has two: a
  80. /// candidate proposal threshold and a candidate confirmation threshold.
  81. /// Generally the candidate proposal threshold could be smaller than
  82. /// tracking threshold, and the condidate confirmation threshold is
  83. /// larger than tracking threshold.\n
  84. /// default values:\n
  85. /// trackThresh: 0.15f\n
  86. /// detectProposeCandidateThresh: 0.8f * trackThresh;\n
  87. /// detectConfirmCandidateThresh: 2.f * trackThresh;\n
  88. ///@{
  89. float trackThresh;
  90. float detectProposeCandidateThresh;
  91. float detectConfirmCandidateThresh;
  92. ///@}
  93. /// Control general tracking speed. See Bingo_ObjectTracking_Speed for
  94. /// details
  95. bef_ai_object_tracking_speed speed;
  96. }bef_ai_object_tracking_param;
  97. typedef enum {
  98. bef_ai_object_tracking_init_bbox_invalid_handle = -1,
  99. /// bounding box initialization success
  100. bef_ai_object_tracking_init_bbox_success = 0,
  101. /// Image in bbox has no texture.
  102. bef_ai_object_tracking_init_bbox_no_texture = 1,
  103. /// Image failes during initial bounding box tracking step
  104. bef_ai_object_tracking_init_bbox_image_feature_extract_fail = 2,
  105. } bef_ai_object_tracking_init_bbox_status;
  106. // general definition of bounding box
  107. typedef struct bef_ai_object_tracking_bounding_box
  108. {
  109. float centerX;
  110. float centerY; // center position of bounding box
  111. float width;
  112. float height; // please refer to image above for width and height definition
  113. float rotateAngle; // clockwise rotate angle, in range [0, 360)
  114. } bef_ai_object_tracking_bounding_box;
  115. typedef enum {
  116. bef_ai_object_tracking_status_unavailable = 0,
  117. bef_ai_object_tracking_status_tracked = 1,
  118. bef_ai_object_tracking_status_losing = 2,
  119. bef_ai_object_tracking_status_lost = 3,
  120. } bef_ai_object_tracking_status;
  121. typedef struct bef_ai_object_tracking_bbox
  122. {
  123. bef_ai_object_tracking_bounding_box bbox;
  124. float timestamp;
  125. /// StatusTracked or StatusLost
  126. bef_ai_object_tracking_status status;
  127. } bef_ai_object_tracking_bbox;
  128. BEF_SDK_API bef_effect_result_t
  129. bef_ai_object_tracking_create(bef_ai_object_tracking_handle *handle);
  130. BEF_SDK_API bef_effect_result_t
  131. bef_ai_object_tracking_destroy(bef_ai_object_tracking_handle handle);
  132. BEF_SDK_API bef_effect_result_t
  133. bef_ai_object_tracking_init(bef_ai_object_tracking_handle handle, const char* modelPath, bef_ai_object_tracking_param *param);
  134. BEF_SDK_API void
  135. bef_ai_object_tracking_get_default_param(bef_ai_object_tracking_handle handle, bef_ai_object_tracking_param* param);
  136. BEF_SDK_API bef_ai_object_tracking_init_bbox_status
  137. bef_ai_object_tracking_set_initial_bbox(bef_ai_object_tracking_handle handle, const unsigned char* image, bef_ai_pixel_format format, int width, int height, int channels,
  138. int imageStride, bef_ai_object_tracking_bbox* initialBox);
  139. BEF_SDK_API bef_effect_result_t
  140. bef_ai_object_tracking_track_frame(bef_ai_object_tracking_handle handle, const unsigned char* image, bef_ai_pixel_format format, int width, int height, int channels,
  141. int imageStride, float timeStamp, bef_ai_object_tracking_bbox* result);
  142. #if defined(__ANDROID__) || defined(TARGET_OS_ANDROID)
  143. #include <jni.h>
  144. /// check license offline
  145. /// @param env JNIEnv
  146. /// @param context jobject
  147. /// @param handle bef_ai_object_tracking_handle
  148. /// @param licensePath license path
  149. BEF_SDK_API bef_effect_result_t
  150. bef_ai_object_tracking_check_license(JNIEnv *env, jobject context, bef_ai_object_tracking_handle handle, const char* licensePath);
  151. #elif TARGET_OS_IPHONE
  152. /// check license offline
  153. /// @param bef_ai_object_tracking_handle handle
  154. /// @param licensePath license path
  155. BEF_SDK_API bef_effect_result_t
  156. bef_ai_object_tracking_check_license(bef_ai_object_tracking_handle handle, const char* licensePath);
  157. #endif
  158. /// check license online
  159. /// @param bef_ai_object_tracking_handle handle
  160. /// @param licensePath license path
  161. BEF_SDK_API bef_effect_result_t
  162. bef_ai_object_tracking_check_online_license(bef_ai_object_tracking_handle handle, const char *licensePath);
  163. #endif