Skip to content

Commit

Permalink
Rename funcs names
Browse files Browse the repository at this point in the history
  • Loading branch information
Danile71 committed Feb 12, 2020
1 parent 53e19db commit 3caf75f
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 45 deletions.
42 changes: 21 additions & 21 deletions face.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func NewRecognizer() (rec *Recognizer, err error) {
return
}

func (rec *Recognizer) SetShape(shapePredictorPath string) (err error) {
func (rec *Recognizer) SetShapeModel(shapePredictorPath string) (err error) {
if !fileExists(shapePredictorPath) {
err = errors.New(fmt.Sprintf("File '%s' not found!", shapePredictorPath))
return
Expand All @@ -97,7 +97,7 @@ func (rec *Recognizer) SetShape(shapePredictorPath string) (err error) {
return
}

func (rec *Recognizer) SetDescriptor(resnetPath string) (err error) {
func (rec *Recognizer) SetDescriptorModel(resnetPath string) (err error) {
if !fileExists(resnetPath) {
err = errors.New(fmt.Sprintf("File '%s' not found!", resnetPath))
return
Expand All @@ -108,7 +108,7 @@ func (rec *Recognizer) SetDescriptor(resnetPath string) (err error) {
return
}

func (rec *Recognizer) SetCNN(cnnResnetPath string) (err error) {
func (rec *Recognizer) SetCNNModel(cnnResnetPath string) (err error) {
if !fileExists(cnnResnetPath) {
err = errors.New(fmt.Sprintf("File '%s' not found!", cnnResnetPath))
return
Expand All @@ -119,7 +119,7 @@ func (rec *Recognizer) SetCNN(cnnResnetPath string) (err error) {
return
}

func (rec *Recognizer) SetGender(genderPath string) (err error) {
func (rec *Recognizer) SetGenderModel(genderPath string) (err error) {
if !fileExists(genderPath) {
err = errors.New(fmt.Sprintf("File '%s' not found!", genderPath))
return
Expand All @@ -130,7 +130,7 @@ func (rec *Recognizer) SetGender(genderPath string) (err error) {
return
}

func (rec *Recognizer) SetAge(agePath string) (err error) {
func (rec *Recognizer) SetAgeModel(agePath string) (err error) {
if !fileExists(agePath) {
err = errors.New(fmt.Sprintf("File '%s' not found!", agePath))
return
Expand All @@ -142,22 +142,22 @@ func (rec *Recognizer) SetAge(agePath string) (err error) {
}

func (rec *Recognizer) SetSize(size int) {
C.facerec_config_size(rec.ptr, C.ulong(size))
C.facerec_config_set_size(rec.ptr, C.ulong(size))
}

func (rec *Recognizer) SetPadding(padding float32) {
C.facerec_config_padding(rec.ptr, C.double(padding))
C.facerec_config_set_padding(rec.ptr, C.double(padding))
}

func (rec *Recognizer) SetJittering(jittering int) {
C.facerec_config_jittering(rec.ptr, C.int(jittering))
C.facerec_config_set_jittering(rec.ptr, C.int(jittering))
}

func (rec *Recognizer) SetMinImageSize(minImageSize int) {
C.facerec_config_min_image_size(rec.ptr, C.int(minImageSize))
C.facerec_config_set_min_image_size(rec.ptr, C.int(minImageSize))
}

func (rec *Recognizer) detectBuffer(type_ int, imgData []byte) (faces []Face, err error) {
func (rec *Recognizer) detectFromBuffer(type_ int, imgData []byte) (faces []Face, err error) {
if len(imgData) == 0 {
err = ImageLoadError("Empty image")
return
Expand All @@ -167,7 +167,7 @@ func (rec *Recognizer) detectBuffer(type_ int, imgData []byte) (faces []Face, er
cType := C.int(type_)
var ptr C.image_pointer

ret := C.facerec_detect_buffer(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&ptr)), cImgData, cLen, cType)
ret := C.facerec_detect_from_buffer(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&ptr)), cImgData, cLen, cType)
defer C.free(unsafe.Pointer(ret))

if ret.err_str != nil {
Expand Down Expand Up @@ -200,7 +200,7 @@ func (rec *Recognizer) detectBuffer(type_ int, imgData []byte) (faces []Face, er
return
}

func (rec *Recognizer) detectFile(type_ int, file string) (faces []Face, err error) {
func (rec *Recognizer) detectFromFile(type_ int, file string) (faces []Face, err error) {
if !fileExists(file) {
err = ImageLoadError(fmt.Sprintf("File '%s' not found!", file))
return
Expand All @@ -210,7 +210,7 @@ func (rec *Recognizer) detectFile(type_ int, file string) (faces []Face, err err
cFile := C.CString(file)
defer C.free(unsafe.Pointer(cFile))
var ptr *C.image_pointer
ret := C.facerec_detect_file(rec.ptr, ptr, cFile, cType)
ret := C.facerec_detect_from_file(rec.ptr, ptr, cFile, cType)
defer C.free(unsafe.Pointer(ret))

if ret.err_str != nil {
Expand Down Expand Up @@ -247,21 +247,21 @@ func (rec *Recognizer) detectFile(type_ int, file string) (faces []Face, err err
// left to right. Empty list is returned if there are no faces, error is
// returned if there was some error while decoding/processing image.
// Only JPEG format is currently supported. Thread-safe.
func (rec *Recognizer) Detect(imgData []byte) (faces []Face, err error) {
return rec.detectBuffer(0, imgData)
func (rec *Recognizer) DetectFromBuffer(imgData []byte) (faces []Face, err error) {
return rec.detectFromBuffer(0, imgData)
}

func (rec *Recognizer) DetectCNN(imgData []byte) (faces []Face, err error) {
return rec.detectBuffer(1, imgData)
func (rec *Recognizer) DetectFromBufferCNN(imgData []byte) (faces []Face, err error) {
return rec.detectFromBuffer(1, imgData)
}

// Same as Recognize but accepts image path instead.
func (rec *Recognizer) DetectFromFile(imgPath string) (faces []Face, err error) {
return rec.detectFile(0, imgPath)
return rec.detectFromFile(0, imgPath)
}

func (rec *Recognizer) DetectFromFileCNN(imgPath string) (faces []Face, err error) {
return rec.detectFile(1, imgPath)
return rec.detectFromFile(1, imgPath)
}

func (rec *Recognizer) GetGender(face *Face) {
Expand All @@ -270,7 +270,7 @@ func (rec *Recognizer) GetGender(face *Face) {
x1 := C.int(face.Rectangle.Max.X)
y1 := C.int(face.Rectangle.Max.Y)

face.Gender = Gender(int(C.facerec_gender(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&face.imagePointer)), x, y, x1, y1)))
face.Gender = Gender(int(C.facerec_get_gender(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&face.imagePointer)), x, y, x1, y1)))
}

func (rec *Recognizer) GetAge(face *Face) {
Expand All @@ -279,7 +279,7 @@ func (rec *Recognizer) GetAge(face *Face) {
x1 := C.int(face.Rectangle.Max.X)
y1 := C.int(face.Rectangle.Max.Y)

face.Age = int(C.facerec_age(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&face.imagePointer)), x, y, x1, y1))
face.Age = int(C.facerec_get_age(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&face.imagePointer)), x, y, x1, y1))
}

func (rec *Recognizer) Recognize(face *Face) error {
Expand Down
2 changes: 1 addition & 1 deletion gocv.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

using namespace dlib;

facesret* facerec_detect_mat(facerec* rec, image_pointer *p, const void *mat,int type) {
facesret* facerec_detect_from_mat(facerec* rec, image_pointer *p, const void *mat,int type) {
facesret* ret = (facesret*)calloc(1, sizeof(facesret));
image_t img;
std::vector<rectangle> rects;
Expand Down
12 changes: 6 additions & 6 deletions gocv.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ import (
"gocv.io/x/gocv"
)

func (rec *Recognizer) detectMat(type_ int, mat gocv.Mat) (faces []Face, err error) {
func (rec *Recognizer) detectFromMat(type_ int, mat gocv.Mat) (faces []Face, err error) {
cType := C.int(type_)
var ptr C.image_pointer

ret := C.facerec_detect_mat(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&ptr)), unsafe.Pointer(mat.Ptr()), cType)
ret := C.facerec_detect_from_mat(rec.ptr, (*C.image_pointer)(unsafe.Pointer(&ptr)), unsafe.Pointer(mat.Ptr()), cType)
defer C.free(unsafe.Pointer(ret))

if ret.err_str != nil {
Expand Down Expand Up @@ -55,10 +55,10 @@ func (rec *Recognizer) detectMat(type_ int, mat gocv.Mat) (faces []Face, err err
return
}

func (rec *Recognizer) DetectMat(mat gocv.Mat) (faces []Face, err error) {
return rec.detectMat(0, mat)
func (rec *Recognizer) DetectFromMat(mat gocv.Mat) (faces []Face, err error) {
return rec.detectFromMat(0, mat)
}

func (rec *Recognizer) DetectMatCNN(mat gocv.Mat) (faces []Face, err error) {
return rec.detectMat(1, mat)
func (rec *Recognizer) DetectFromMatCNN(mat gocv.Mat) (faces []Face, err error) {
return rec.detectFromMat(1, mat)
}
2 changes: 1 addition & 1 deletion gocv.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
extern "C" {
#endif

facesret* facerec_detect_mat(facerec* rec, image_pointer *p, const void *mat,int type);
facesret* facerec_detect_from_mat(facerec* rec, image_pointer *p, const void *mat,int type);

#ifdef __cplusplus
}
Expand Down
16 changes: 8 additions & 8 deletions wrapper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,22 @@ facerec* facerec_init() {
return rec;
}

void facerec_config_size(facerec* rec, unsigned long size) {
void facerec_config_set_size(facerec* rec, unsigned long size) {
FaceRec* cls = (FaceRec*)(rec->cls);
cls->setSize(size);
}

void facerec_config_padding(facerec* rec, double padding) {
void facerec_config_set_padding(facerec* rec, double padding) {
FaceRec* cls = (FaceRec*)(rec->cls);
cls->setPadding(padding);
}

void facerec_config_jittering(facerec* rec, int jittering) {
void facerec_config_set_jittering(facerec* rec, int jittering) {
FaceRec* cls = (FaceRec*)(rec->cls);
cls->setJittering(jittering);
}

void facerec_config_min_image_size(facerec* rec, int min_image_size) {
void facerec_config_set_min_image_size(facerec* rec, int min_image_size) {
FaceRec* cls = (FaceRec*)(rec->cls);
cls->setMinImageSize(min_image_size);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ void facerec_set_age(facerec* rec, const char *file) {
cls->setAge(file);
}

facesret* facerec_detect_file(facerec* rec, image_pointer *p, const char* file,int type) {
facesret* facerec_detect_from_file(facerec* rec, image_pointer *p, const char* file,int type) {
facesret* ret = (facesret*)calloc(1, sizeof(facesret));
image_t img;
std::vector<rectangle> rects;
Expand All @@ -93,7 +93,7 @@ facesret* facerec_detect_file(facerec* rec, image_pointer *p, const char* file,i
return facerec_detect(ret, p, rec, img, type);
}

facesret* facerec_detect_buffer(facerec* rec, image_pointer *p, unsigned char* img_data, int len,int type) {
facesret* facerec_detect_from_buffer(facerec* rec, image_pointer *p, unsigned char* img_data, int len,int type) {
facesret* ret = (facesret*)calloc(1, sizeof(facesret));
image_t img;
std::vector<rectangle> rects;
Expand Down Expand Up @@ -149,15 +149,15 @@ faceret* facerec_recognize(facerec* rec, image_pointer *p, int x, int y, int x1,
return ret;
}

int facerec_gender(facerec* rec, image_pointer *p, int x, int y, int x1, int y1) {
int facerec_get_gender(facerec* rec, image_pointer *p, int x, int y, int x1, int y1) {
FaceRec* cls = (FaceRec*)(rec->cls);
image_t img = *((image_t*)p->p);
rectangle r = rectangle(x,y,x1,y1);

return cls->gender(img, r);
}

int facerec_age(facerec* rec, image_pointer *p, int x, int y, int x1, int y1) {
int facerec_get_age(facerec* rec, image_pointer *p, int x, int y, int x1, int y1) {
FaceRec* cls = (FaceRec*)(rec->cls);
image_t img = *((image_t*)p->p);
rectangle r = rectangle(x,y,x1,y1);
Expand Down
20 changes: 12 additions & 8 deletions wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,13 @@ typedef struct faceret {
#define SHAPE_LEN 2

facerec* facerec_init();
facesret* facerec_detect_file(facerec*, image_pointer *, const char*,int);
facesret* facerec_detect_buffer(facerec*, image_pointer *, unsigned char*, int, int);
facesret* facerec_detect_from_file(facerec*, image_pointer *, const char*,int);
facesret* facerec_detect_from_buffer(facerec*, image_pointer *, unsigned char*, int, int);
faceret* facerec_recognize(facerec*, image_pointer*, int, int, int, int);
int facerec_gender(facerec* rec, image_pointer *, int, int, int, int);
int facerec_age(facerec* rec, image_pointer *, int, int, int, int);

int facerec_get_gender(facerec* rec, image_pointer *, int, int, int, int);
int facerec_get_age(facerec* rec, image_pointer *, int, int, int, int);

void facerec_set_cnn(facerec* , const char *);
void facerec_set_shape(facerec* , const char *);
void facerec_set_descriptor(facerec* , const char *);
Expand All @@ -59,10 +61,12 @@ void facerec_set_age(facerec* , const char *);
void facerec_set_samples(facerec*, const float*, const int32_t*, int);
int facerec_classify(facerec*, const float*, float);
void facerec_free(facerec*);
void facerec_config_size(facerec* rec, unsigned long size);
void facerec_config_padding(facerec* rec, double padding);
void facerec_config_jittering(facerec* rec, int jittering);
void facerec_config_min_image_size(facerec* rec, int min_image_size);

void facerec_config_set_size(facerec* rec, unsigned long size);
void facerec_config_set_padding(facerec* rec, double padding);
void facerec_config_set_jittering(facerec* rec, int jittering);
void facerec_config_set_min_image_size(facerec* rec, int min_image_size);

void image_pointer_free(image_pointer* p);

#ifdef __cplusplus
Expand Down

0 comments on commit 3caf75f

Please sign in to comment.