Use native Go image.Rectangle type

This commit is contained in:
Kagami Hiiragi
2018-04-04 21:03:15 +03:00
parent 0c3ac8eef9
commit c627f1a583
3 changed files with 11 additions and 6 deletions

View File

@@ -108,9 +108,9 @@ faceret* facerec_recognize(facerec* rec, const char* img_path, int max_faces) {
ret->num_faces = descrs.size();
if (ret->num_faces == 0)
return ret;
ret->rectangles = (int32_t*)malloc(ret->num_faces * RECT_SIZE);
ret->rectangles = (long*)malloc(ret->num_faces * RECT_SIZE);
for (int i = 0; i < ret->num_faces; i++) {
int32_t* dst = ret->rectangles + i * 4;
long* dst = ret->rectangles + i * 4;
dst[0] = rects[i].left();
dst[1] = rects[i].top();
dst[2] = rects[i].right();

View File

@@ -5,6 +5,7 @@ package dlib
// #include "facerec.h"
import "C"
import (
"image"
"unsafe"
)
@@ -20,7 +21,7 @@ type FaceRec struct {
// Face structure.
type Face struct {
Rectangle [rectLen]int32
Rectangle image.Rectangle
Descriptor [descrLen]float32
}
@@ -64,7 +65,7 @@ func (rec *FaceRec) recognize(imgPath string, maxFaces int) (faces []Face, err e
rDataLen := numFaces * rectLen
rDataPtr := unsafe.Pointer(ret.rectangles)
rData := (*[1 << 30]int32)(rDataPtr)[:rDataLen:rDataLen]
rData := (*[1 << 30]C.long)(rDataPtr)[:rDataLen:rDataLen]
dDataLen := numFaces * descrLen
dDataPtr := unsafe.Pointer(ret.descriptors)
@@ -72,7 +73,11 @@ func (rec *FaceRec) recognize(imgPath string, maxFaces int) (faces []Face, err e
for i := 0; i < numFaces; i++ {
face := Face{}
copy(face.Rectangle[:], rData[i*rectLen:(i+1)*rectLen])
x0 := int(rData[i*rectLen])
y0 := int(rData[i*rectLen+1])
x1 := int(rData[i*rectLen+2])
y1 := int(rData[i*rectLen+3])
face.Rectangle = image.Rect(x0, y0, x1, y1)
copy(face.Descriptor[:], dData[i*descrLen:(i+1)*descrLen])
faces = append(faces, face)
}

View File

@@ -19,7 +19,7 @@ typedef struct facerec {
typedef struct faceret {
int num_faces;
int32_t* rectangles;
long* rectangles;
float* descriptors;
const char* err_str;
err_code err_code;