-
Notifications
You must be signed in to change notification settings - Fork 870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
facemark #1124
Open
xyjwsj
wants to merge
2
commits into
hybridgroup:dev
Choose a base branch
from
xyjwsj:dev
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
facemark #1124
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ count.out | |
.idea/ | ||
contrib/data.yaml | ||
contrib/testOilPainting.png | ||
lbfmodel.yaml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "facemarkLBF.h" | ||
|
||
LBPHFaceMark CreateLBPHFaceMark() { | ||
return new cv::Ptr<cv::face::Facemark>(cv::face::FacemarkLBF::create()); | ||
} | ||
|
||
void LBPHFaceMark_LoadModel(LBPHFaceMark fm, const char* model) { | ||
(*fm)->loadModel(model); | ||
} | ||
|
||
bool LBPHFaceMark_Fit(LBPHFaceMark fm, Mat frame, struct Rects faces, Points2fVector landmarks) { | ||
std::vector<cv::Rect> _faces; | ||
|
||
for (int i = 0; i < faces.length; ++i) { | ||
_faces.push_back(cv::Rect( | ||
faces.rects[i].x, | ||
faces.rects[i].y, | ||
faces.rects[i].width, | ||
faces.rects[i].height | ||
)); | ||
} | ||
return (*fm)->fit(*frame, _faces, *landmarks); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package contrib | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include "facemarkLBF.h" | ||
#include "../core.h" | ||
*/ | ||
import "C" | ||
import ( | ||
"gocv.io/x/gocv" | ||
"image" | ||
"unsafe" | ||
) | ||
|
||
type LBPHFaceMark struct { | ||
p C.LBPHFaceMark | ||
} | ||
|
||
func NewLBPHFaceMark() *LBPHFaceMark { | ||
return &LBPHFaceMark{p: C.CreateLBPHFaceMark()} | ||
} | ||
|
||
func (mark *LBPHFaceMark) LoadModel(model string) { | ||
cName := C.CString(model) | ||
defer C.free(unsafe.Pointer(cName)) | ||
C.LBPHFaceMark_LoadModel(mark.p, cName) | ||
} | ||
|
||
// LBPHFaceMark_Fit(LBPHFaceMark fm, Mat frame, struct Rects faces, Points2fVector landmarks) | ||
func (mark *LBPHFaceMark) Fit(img gocv.Mat, faceBox []image.Rectangle) (bool, [][]gocv.Point2f) { | ||
|
||
bboxesRectArr := []C.struct_Rect{} | ||
for _, v := range faceBox { | ||
bbox := C.struct_Rect{ | ||
x: C.int(v.Min.X), | ||
y: C.int(v.Min.Y), | ||
width: C.int(v.Size().X), | ||
height: C.int(v.Size().Y), | ||
} | ||
bboxesRectArr = append(bboxesRectArr, bbox) | ||
} | ||
|
||
bboxesRects := C.Rects{ | ||
rects: (*C.Rect)(&bboxesRectArr[0]), | ||
length: C.int(len(faceBox)), | ||
} | ||
|
||
points2fVector := gocv.NewPoints2fVector() | ||
result := bool(C.LBPHFaceMark_Fit( | ||
mark.p, | ||
C.Mat(img.Ptr()), | ||
bboxesRects, | ||
C.Points2fVector(points2fVector.P()), | ||
)) | ||
|
||
return result, points2fVector.ToPoints() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#ifndef _OPENCV3_FACE_H_ | ||
#define _OPENCV3_FACE_H_ | ||
|
||
#ifdef __cplusplus | ||
#include <opencv2/opencv.hpp> | ||
#include <opencv2/face.hpp> | ||
|
||
extern "C" { | ||
#endif | ||
|
||
#include "../core.h" | ||
|
||
#ifdef __cplusplus | ||
typedef cv::Ptr<cv::face::Facemark>* LBPHFaceMark; | ||
#else | ||
typedef void* LBPHFaceMark; | ||
#endif | ||
|
||
struct PredictResponse { | ||
int label; | ||
double confidence; | ||
}; | ||
|
||
LBPHFaceMark CreateLBPHFaceMark(); | ||
void LBPHFaceMark_LoadModel(LBPHFaceMark fm, const char* model); //Points2fVector | ||
bool LBPHFaceMark_Fit(LBPHFaceMark fm, Mat frame, struct Rects faces, Points2fVector landmarks); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //_OPENCV3_FACE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package contrib | ||
|
||
import ( | ||
"log" | ||
"testing" | ||
) | ||
|
||
func TestNewLBPHFaceMark(t *testing.T) { | ||
mark := NewLBPHFaceMark() | ||
log.Println(mark) | ||
} | ||
|
||
func TestLBPHFaceMark_LoadModel(t *testing.T) { | ||
mark := NewLBPHFaceMark() | ||
log.Println(mark) | ||
//mark.LoadModel("") | ||
//log.Println("success") | ||
} | ||
|
||
func TestLBPHFaceMark_Fit(t *testing.T) { | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you mean to actually call this in the test? Seems like that is the case from the test name.