-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathface.go
90 lines (77 loc) · 2.83 KB
/
face.go
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
package main
/*
#cgo CFLAGS: -I./ArcSoft_ArcFace_Linux_x64_V3.0/inc -I/usr/include -I/usr/local/include
#cgo CXXFLAGS: -std=c++11 -I./ArcSoft_ArcFace_Linux_x64_V3.0/inc -I/usr/include -I/usr/local/include -I/usr/include/opencv
#cgo LDFLAGS: -lstdc++ -L${SRCDIR}/ArcSoft_ArcFace_Linux_x64_V3.0/lib/linux_x64 -larcsoft_face -larcsoft_face_engine
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_core.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_imgproc.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_highgui.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_flann.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_photo.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_features2d.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_contrib.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_legacy.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_ts.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_objdetect.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_ocl.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_stitching.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_superres.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_calib3d.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libopencv_gpu.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libpng.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libjpeg.a
#cgo LDFLAGS: -L/usr/lib/x86_64-linux-gnu -l:libtiff.a
#cgo LDFLAGS: -Wl,-rpath=./
#include "face.h"
*/
import "C"
import (
// "gocv.io/x/gocv"
// "log"
"unsafe"
)
type Handle unsafe.Pointer
func initEngine() Handle {
APPID := "D617np8jyKt1jN9gMr7ENbTJ1XvRWsQAsvdAehMKvqzr"
SDKKEY := "BTeyKLCYBzfrNLQduGUwfyRZkDQU4RB2b3UJZjjuppLU"
return Handle(C.initEngine(C.CString(APPID), C.CString(SDKKEY)))
}
func extract(filePath string, handle Handle ) []byte{
// handle := C.initEngine(C.CString(APPID), C.CString(SDKKEY))
feature := C.extract(C.CString(filePath), unsafe.Pointer(handle))
if feature.featureSize > 0 {
return C.GoBytes(unsafe.Pointer(feature.feature), feature.featureSize)
}else{
return nil
}
}
type EnginePool struct {
cached chan Handle
size int
}
func NewEnginePool(size int) *EnginePool {
x := EnginePool{}
x.cached = make(chan Handle, size)
x.size = size
return &x
}
func (c *EnginePool) Get() Handle {
var res Handle
select {
case res = <-c.cached:
// fmt.Println("---get--")
default:
// fmt.Println("---create one--")
res = Handle(initEngine())
}
return res
}
func (p *EnginePool) Put(c Handle) {
select {
case p.cached <- c:
// fmt.Println("---put--")
default:
c = nil
// fmt.Println("---destroy--")
}
}