From 4c69183dab4979f7131b345543c7b1c2ee8dd458 Mon Sep 17 00:00:00 2001 From: diegohce Date: Fri, 30 Aug 2024 13:59:57 -0300 Subject: [PATCH] added missing Empty method --- contrib/face.cpp | 4 ++++ contrib/face.go | 4 ++++ contrib/face.h | 4 ++++ contrib/face_recognizer.go | 6 ++++++ contrib/face_test.go | 2 ++ 5 files changed, 20 insertions(+) diff --git a/contrib/face.cpp b/contrib/face.cpp index 9f1bf50e..7d8f458d 100644 --- a/contrib/face.cpp +++ b/contrib/face.cpp @@ -1,5 +1,9 @@ #include "face.h" +bool FaceRecognizer_Empty(FaceRecognizer fr) { + return (*fr)->empty(); +} + void FaceRecognizer_Train(FaceRecognizer fr, Mats mats, IntVector labels_in) { std::vector labels; diff --git a/contrib/face.go b/contrib/face.go index ae4ec4b8..925cf40c 100644 --- a/contrib/face.go +++ b/contrib/face.go @@ -25,6 +25,10 @@ type LBPHFaceRecognizer struct { p C.LBPHFaceRecognizer } +func (fr *LBPHFaceRecognizer) Empty() bool { + return faceRecognizer_Empty(C.FaceRecognizer(fr.p)) +} + // NewLBPHFaceRecognizer creates a new LBPH Recognizer model. // // For further information, see: diff --git a/contrib/face.h b/contrib/face.h index 9f3cbeb3..96fa6e2c 100644 --- a/contrib/face.h +++ b/contrib/face.h @@ -23,6 +23,7 @@ struct PredictResponse { double confidence; }; +bool FaceRecognizer_Empty(FaceRecognizer fr); void FaceRecognizer_Train(FaceRecognizer fr, Mats images, IntVector labels); void FaceRecognizer_Update(FaceRecognizer fr, Mats images, IntVector labels); int FaceRecognizer_Predict(FaceRecognizer fr, Mat sample); @@ -44,6 +45,9 @@ int LBPHFaceRecognizer_GetGridX(LBPHFaceRecognizer fr); int LBPHFaceRecognizer_GetGridY(LBPHFaceRecognizer fr); void LBPHFaceRecognizer_Close(LBPHFaceRecognizer fr); + + + #ifdef __cplusplus } #endif diff --git a/contrib/face_recognizer.go b/contrib/face_recognizer.go index adba987c..1b087e94 100644 --- a/contrib/face_recognizer.go +++ b/contrib/face_recognizer.go @@ -12,6 +12,7 @@ import ( ) type FaceRecognizer interface { + Empty() bool Train(images []gocv.Mat, labels []int) Update(newImages []gocv.Mat, newLabels []int) Predict(sample gocv.Mat) int @@ -23,6 +24,11 @@ type FaceRecognizer interface { Close() error } +func faceRecognizer_Empty(fr C.FaceRecognizer) bool { + b := C.FaceRecognizer_Empty(fr) + return bool(b) +} + func faceRecognizer_Train(fr C.FaceRecognizer, images []gocv.Mat, labels []int) { cparams := []C.int{} for _, v := range labels { diff --git a/contrib/face_test.go b/contrib/face_test.go index 3ab3419c..b01ac8de 100644 --- a/contrib/face_test.go +++ b/contrib/face_test.go @@ -14,6 +14,8 @@ func TestLBPHFaceRecognizer_Methods(t *testing.T) { t.Errorf("Invalid NewLBPHFaceRecognizer call %v", model) } + model.Empty() + labels := []int{1, 1, 1, 1, 2, 2, 2, 2} images := []gocv.Mat{ gocv.IMRead("./att_faces/s1/1.pgm", gocv.IMReadGrayScale),