forked from Kagami/go-face
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gocv.cc
110 lines (97 loc) · 2.93 KB
/
gocv.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// +build gocv
#include <dlib/opencv.h>
#include <opencv2/core/core.hpp>
#include <opencv2/core/types_c.h>
#include "facerec.h"
#include "tracker.h"
#include "gocv.h"
using namespace dlib;
facesret* facerec_detect_from_mat(facerec* rec, const void *mat,int type) {
FaceRec* cls = (FaceRec*)(rec->cls);
facesret* ret = (facesret*)calloc(1, sizeof(facesret));
image_t img;
try {
cv::Mat *mat_img = (cv::Mat*)mat;
if (!mat_img) {
ret->err_code = UNKNOWN_ERROR;
return ret;
}
IplImage ipl_img = cvIplImage(*mat_img);
if (mat_img->channels() > 1) {
cv_image<bgr_pixel> dlib_img(&ipl_img);
assign_image(img, dlib_img);
} else {
cv_image<uchar> dlib_img(&ipl_img);
assign_image(img, dlib_img);
}
} catch(image_load_error& e) {
ret->err_str = strdup(e.what());
ret->err_code = IMAGE_LOAD_ERROR;
return ret;
} catch (std::exception& e) {
ret->err_str = strdup(e.what());
ret->err_code = UNKNOWN_ERROR;
return ret;
}
return cls->detect(ret, img, type);
}
facesret* start_track_from_mat(tracker* tr, const void *mat,int x1, int y1, int x2, int y2) {
Tracker* cls = (Tracker*)(tr->cls);
facesret* ret = (facesret*)calloc(1, sizeof(facesret));
image_t img;
try {
cv::Mat *mat_img = (cv::Mat*)mat;
if (!mat_img) {
ret->err_code = UNKNOWN_ERROR;
return ret;
}
IplImage ipl_img = cvIplImage(*mat_img);
if (mat_img->channels() > 1) {
cv_image<bgr_pixel> dlib_img(&ipl_img);
assign_image(img, dlib_img);
} else {
cv_image<uchar> dlib_img(&ipl_img);
assign_image(img, dlib_img);
}
cls->StartTrack(img,rectangle(x1,y1,x2,y2));
} catch(image_load_error& e) {
ret->err_str = strdup(e.what());
ret->err_code = IMAGE_LOAD_ERROR;
return ret;
} catch (std::exception& e) {
ret->err_str = strdup(e.what());
ret->err_code = UNKNOWN_ERROR;
return ret;
}
return ret;
}
update_ret* update_track_from_mat(tracker* tr, const void *mat) {
Tracker* cls = (Tracker*)(tr->cls);
update_ret* ret = (update_ret*)calloc(1, sizeof(update_ret));
image_t img;
try {
cv::Mat *mat_img = (cv::Mat*)mat;
if (!mat_img) {
ret->err_code = UNKNOWN_ERROR;
return ret;
}
IplImage ipl_img = cvIplImage(*mat_img);
if (mat_img->channels() > 1) {
cv_image<bgr_pixel> dlib_img(&ipl_img);
assign_image(img, dlib_img);
} else {
cv_image<uchar> dlib_img(&ipl_img);
assign_image(img, dlib_img);
}
ret->confidence = cls->Update(img);
} catch(image_load_error& e) {
ret->err_str = strdup(e.what());
ret->err_code = IMAGE_LOAD_ERROR;
return ret;
} catch (std::exception& e) {
ret->err_str = strdup(e.what());
ret->err_code = UNKNOWN_ERROR;
return ret;
}
return ret;
}