-
Notifications
You must be signed in to change notification settings - Fork 1
/
detecter.go
41 lines (37 loc) · 1.02 KB
/
detecter.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
package detecter
/*
#include <stdlib.h>
#include <stdbool.h>
#include "openvision/common/common.h"
#include "openvision/pose/detecter.h"
*/
import "C"
import (
"unsafe"
openvision "github.com/bububa/openvision/go"
"github.com/bububa/openvision/go/common"
)
// Detecter represents deteter interface
type Detecter interface {
common.Estimator
HasKeypoints() bool
Detect(img *common.Image) ([]common.ObjectInfo, error)
}
// Detect detect pose rect using detecter
func Detect(d Detecter, img *common.Image) ([]common.ObjectInfo, error) {
imgWidth := img.WidthF64()
imgHeight := img.HeightF64()
data := img.Bytes()
cObjs := common.NewCObjectInfoVector()
defer common.FreeCObjectInfoVector(cObjs)
errCode := C.detect_pose(
(C.IPoseDetecter)(d.Pointer()),
(*C.uchar)(unsafe.Pointer(&data[0])),
C.int(imgWidth),
C.int(imgHeight),
(*C.ObjectInfoVector)(unsafe.Pointer(cObjs)))
if errCode != 0 {
return nil, openvision.DetectPoseError(int(errCode))
}
return common.GoObjectInfoVector(cObjs, imgWidth, imgHeight), nil
}