Skip to content

Commit

Permalink
feat: add NewSURFWithParams func
Browse files Browse the repository at this point in the history
  • Loading branch information
Cartermel committed Oct 14, 2023
1 parent e2db8f8 commit 2881e97
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 1 deletion.
5 changes: 4 additions & 1 deletion contrib/xfeatures2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@


SURF SURF_Create() {
// TODO: params
return new cv::Ptr<cv::xfeatures2d::SURF>(cv::xfeatures2d::SURF::create());
}

SURF SURF_CreateWithParams(double hessianThreshold, int nOctaves, int nOctaveLayers, bool extended, bool upright) {
return new cv::Ptr<cv::xfeatures2d::SURF>(cv::xfeatures2d::SURF::create(hessianThreshold, nOctaves, nOctaveLayers, extended, upright));
}

void SURF_Close(SURF d) {
delete d;
}
Expand Down
8 changes: 8 additions & 0 deletions contrib/xfeatures2d.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ func NewSURF() SURF {
return SURF{p: unsafe.Pointer(C.SURF_Create())}
}

// NewSURF returns a new SURF algorithm algorithm with parameters
//
// For further details, please see:
// https://docs.opencv.org/master/d5/df7/classcv_1_1xfeatures2d_1_1SURF.html#a436553ca44d9a2238761ddbee5b395e5
func NewSURFWithParams(hessianThreshold float64, nOctaves int, nOctaveLayers int, extended bool, upright bool) SURF {
return SURF{p: unsafe.Pointer(C.SURF_CreateWithParams(C.double(hessianThreshold), C.int(nOctaves), C.int(nOctaveLayers), C.bool(extended), C.bool(upright)))}
}

// Close SURF.
func (d *SURF) Close() error {
C.SURF_Close((C.SURF)(d.p))
Expand Down
1 change: 1 addition & 0 deletions contrib/xfeatures2d.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ typedef void* SURF;
#endif

SURF SURF_Create();
SURF SURF_CreateWithParams(double hessianThreshold, int nOctaves, int nOctaveLayers, bool extended, bool upright);
void SURF_Close(SURF f);
struct KeyPoints SURF_Detect(SURF f, Mat src);
struct KeyPoints SURF_DetectAndCompute(SURF f, Mat src, Mat mask, Mat desc);
Expand Down
36 changes: 36 additions & 0 deletions contrib/xfeatures2d_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,39 @@ func TestSURF(t *testing.T) {
t.Error("Invalid Mat desc in SURF DetectAndCompute")
}
}

func TestSURFWithParams(t *testing.T) {
testNonFree := os.Getenv("OPENCV_ENABLE_NONFREE")
if testNonFree == "" {
t.Skip("Skipping SURFWithParams test since OPENCV_ENABLE_NONFREE was not set")
}

img := gocv.IMRead("../images/face.jpg", gocv.IMReadGrayScale)
if img.Empty() {
t.Error("Invalid Mat in SURF test")
}
defer img.Close()

dst := gocv.NewMat()
defer dst.Close()

si := NewSURFWithParams(100, 4, 3, false, false)
defer si.Close()

kp := si.Detect(img)
if len(kp) == 512 {
t.Errorf("Invalid KeyPoint array in SURF Detect: %d", len(kp))
}

mask := gocv.NewMat()
defer mask.Close()

kp2, desc := si.DetectAndCompute(img, mask)
if len(kp2) == 512 {
t.Errorf("Invalid KeyPoint array in SURF DetectAndCompute: %d", len(kp2))
}

if desc.Empty() {
t.Error("Invalid Mat desc in SURF DetectAndCompute")
}
}

0 comments on commit 2881e97

Please sign in to comment.