C++ 的接口
```c++
typedef enum {
YT_IMG_BGR_8UC3,
YT_IMG_RGB_8UC3,
YT_IMG_GRAY_8UC1,
YT_IMG_DEPTH_16UC1,
} yt_img_type;
typedef struct yt_image_t {
unsigned char *data;
int width;
int height;
yt_img_type type;
} yt_image;
typedef struct yt_rect_t {
int x;
int y;
int width;
int height;
} yt_rect;
typedef struct yt_pointf_t {
float x;
float y;
} yt_pointf;
/**
* @brief 追踪接口,适合于视频流检测,内部封装了检测、5点配准、稳定模块,具有内部状态
*
* @param[in] handle 实例句柄
* @param[in] image 图片,图片类型:YT_IMG_BGR_8UC3
* @param[out] tracked_faces 人脸追踪结果
* @param[out] tracked_faces_count 检测到的人脸数量
* @return YT_SUCCESS:成功,其他:失败
*/
YT_PUBLIC int yt_face_tracker_track(yt_handle handle, const yt_image image, yt_tracked_face **tracked_faces, int *tracked_faces_count);
C#代码
public enum yt_img_type
{
YT_IMG_BGR_8UC3,
YT_IMG_RGB_8UC3,
YT_IMG_GRAY_8UC1,
YT_IMG_DEPTH_16UC1,
}
public struct yt_image
{
public IntPtr data;
public int width;
public int height;
public yt_img_type type;
};
public struct yt_pointf
{
float x;
float y;
}
public struct yt_rect_t
{
int x;
int y;
int width;
int height;
}
public struct yt_tracked_face_t
{
yt_pointf face_5_points;
yt_pointf face_rect;
int frame_id; ///< 帧ID
int trace_id; ///< 轨迹ID
bool consecutive; ///< 轨迹是否存在
float pitch; ///< 人脸俯仰角
float yaw; ///< 人脸偏航角
float roll; ///< 人脸翻滚角
}
```c#
[DllImport(@"libYTFaceTracker.dll", CallingConvention = CallingConvention.Cdecl)]
private extern static int yt_face_tracker_detect(IntPtr handle, yt_image image, yt_face_tracker_param_t param, ref IntPtr yt_tracked_face, ref int tracked_faces_count);
Mat mat = new Mat(@"\_MG_0721.JPG");
yt_image yt_img = new yt_image
{
data = mat.Data,
width = 1616,
height = 1077,
type = yt_img_type.YT_IMG_BGR_8UC3
};
YTFaceTrackerHelper.yt_face_tracker_param_t param= new yt_face_tracker_param_t
{
min_face_size = 50,
max_face_size = 100,
threshold =70.0f,
bigger_face_mode = 0,
detect_interval = 6
};
yt_tracked_face_t s = new yt_tracked_face_t();
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(s));
Marshal.StructureToPtr(s, ptr, false);
int factcount = 0;
result = face_tracker_detect(Handle, yt_img, param, ref ptr, ref factcount);
执行后提示错误:尝试读取或写入受保护的内存。这通常指示其他内存已损坏