forked from hybridgroup/gocv
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
07c5c53
commit 0e1148f
Showing
5 changed files
with
118 additions
and
1 deletion.
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
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,13 @@ | ||
#include "bgsegm.h" | ||
|
||
BackgroundSubtractorCNT BackgroundSubtractorCNT_Create() { | ||
return new cv::Ptr<cv::bgsegm::BackgroundSubtractorCNT>(cv::bgsegm::createBackgroundSubtractorCNT()); | ||
} | ||
|
||
void BackgroundSubtractorCNT_Close(BackgroundSubtractorCNT b) { | ||
delete b; | ||
} | ||
|
||
void BackgroundSubtractorCNT_Apply(BackgroundSubtractorCNT b, Mat src, Mat dst) { | ||
(*b)->apply(*src, *dst); | ||
} |
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,50 @@ | ||
package contrib | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include "bgsegm.h" | ||
*/ | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
|
||
"gocv.io/x/gocv" | ||
) | ||
|
||
// BackgroundSubtractorCNT is a wrapper around the cv::BackgroundSubtractorCNT. | ||
type BackgroundSubtractorCNT struct { | ||
// C.BackgroundSubtractorCNT | ||
p unsafe.Pointer | ||
} | ||
|
||
// NewBackgroundSubtractorCNT returns a new BackgroundSubtractor algorithm | ||
// of type CNT. CNT is Background subtraction algorithm based on counting. | ||
// About as fast as MOG2 on a high end system. More than twice faster than MOG2 on cheap hardware (benchmarked on Raspberry Pi3). | ||
// Algorithm by Sagi Zeevi | ||
// | ||
// For further details, please see: | ||
// https://docs.opencv.org/3.4/de/dca/classcv_1_1bgsegm_1_1BackgroundSubtractorCNT.html | ||
// | ||
func NewBackgroundSubtractorCNT() BackgroundSubtractorCNT { | ||
return BackgroundSubtractorCNT{p: unsafe.Pointer(C.BackgroundSubtractorCNT_Create())} | ||
} | ||
|
||
// Close BackgroundSubtractorCNT. | ||
func (b *BackgroundSubtractorCNT) Close() error { | ||
C.BackgroundSubtractorCNT_Close((C.BackgroundSubtractorCNT)(b.p)) | ||
b.p = nil | ||
|
||
return nil | ||
} | ||
|
||
// Apply computes a foreground mask using the current BackgroundSubtractorCNT. | ||
// | ||
// For further details, please see: | ||
// https://docs.opencv.org/3.4/de/dca/classcv_1_1bgsegm_1_1BackgroundSubtractorCNT.html | ||
// | ||
func (b *BackgroundSubtractorCNT) Apply(src gocv.Mat, dst *gocv.Mat) { | ||
C.BackgroundSubtractorCNT_Apply((C.BackgroundSubtractorCNT)(b.p), (C.Mat)(src.Ptr()), (C.Mat)(dst.Ptr())) | ||
|
||
return | ||
} |
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,26 @@ | ||
#ifndef _OPENCV3_VIDEO_H_ | ||
#define _OPENCV3_VIDEO_H_ | ||
|
||
#ifdef __cplusplus | ||
#include <opencv2/opencv.hpp> | ||
#include <opencv2/bgsegm.hpp> | ||
extern "C" { | ||
#endif | ||
|
||
#include "../core.h" | ||
|
||
#ifdef __cplusplus | ||
typedef cv::Ptr<cv::bgsegm::BackgroundSubtractorCNT>* BackgroundSubtractorCNT; | ||
#else | ||
typedef void* BackgroundSubtractorCNT; | ||
#endif | ||
|
||
BackgroundSubtractorCNT BackgroundSubtractorCNT_Create(); | ||
void BackgroundSubtractorCNT_Close(BackgroundSubtractorCNT b); | ||
void BackgroundSubtractorCNT_Apply(BackgroundSubtractorCNT b, Mat src, Mat dst); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //_OPENCV3_VIDEO_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,28 @@ | ||
package contrib | ||
|
||
import ( | ||
"testing" | ||
"gocv.io/x/gocv" | ||
v "gocv.io/x/gocv/contrib" | ||
) | ||
|
||
func TestCNT(t *testing.T) { | ||
img := gocv.IMRead("../images/face.jpg", gocv.IMReadColor) | ||
if img.Empty() { | ||
t.Error("Invalid Mat in CNT test") | ||
} | ||
defer img.Close() | ||
|
||
dst := gocv.NewMat() | ||
defer dst.Close() | ||
|
||
cnt := v.NewBackgroundSubtractorCNT() | ||
defer cnt.Close() | ||
|
||
cnt.Apply(img, &dst) | ||
|
||
if dst.Empty() { | ||
t.Error("Error in TestCNT test") | ||
} | ||
} | ||
|