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
b090d9e
commit 4e522f1
Showing
6 changed files
with
97 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,6 @@ | ||
#include "photo.h" | ||
|
||
void SeamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags) { | ||
cv::Point pt(p.x, p.y); | ||
cv::seamlessClone(*src, *dst, *mask, pt, *blend, flags); | ||
} |
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,36 @@ | ||
package gocv | ||
|
||
/* | ||
#include <stdlib.h> | ||
#include "photo.h" | ||
*/ | ||
import "C" | ||
import "image" | ||
|
||
//SeamlessCloneFlags seamlessClone algorithm flags | ||
type SeamlessCloneFlags int | ||
|
||
const ( | ||
// NormalClone The power of the method is fully expressed when inserting objects with complex outlines into a new background. | ||
NormalClone SeamlessCloneFlags = iota | ||
|
||
// MixedClone The classic method, color-based selection and alpha masking might be time consuming and often leaves an undesirable halo. Seamless cloning, even averaged with the original image, is not effective. Mixed seamless cloning based on a loose selection proves effective. | ||
MixedClone | ||
|
||
// MonochromeTransfer Monochrome transfer allows the user to easily replace certain features of one object by alternative features. | ||
MonochromeTransfer | ||
) | ||
|
||
// SeamlessClone blend two image by Poisson Blending. | ||
// | ||
// For further details, please see: | ||
// https://docs.opencv.org/master/df/da0/group__photo__clone.html#ga2bf426e4c93a6b1f21705513dfeca49d | ||
// | ||
func SeamlessClone(src, dst, mask Mat, p image.Point, blend *Mat, flags SeamlessCloneFlags) { | ||
cp := C.struct_Point{ | ||
x: C.int(p.X), | ||
y: C.int(p.Y), | ||
} | ||
|
||
C.SeamlessClone(src.p, dst.p, mask.p, cp, blend.p, C.int(flags)) | ||
} |
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,18 @@ | ||
#ifndef _OPENCV3_PHOTO_H_ | ||
#define _OPENCV3_PHOTO_H_ | ||
|
||
#ifdef __cplusplus | ||
#include <opencv2/opencv.hpp> | ||
|
||
extern "C" { | ||
#endif | ||
|
||
#include "core.h" | ||
|
||
void SeamlessClone(Mat src, Mat dst, Mat mask, Point p, Mat blend, int flags); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //_OPENCV3_PHOTO_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,13 @@ | ||
package gocv | ||
|
||
func (c SeamlessCloneFlags) String() string { | ||
switch c { | ||
case NormalClone: | ||
return "normal-clone" | ||
case MixedClone: | ||
return "mixed-clone" | ||
case MonochromeTransfer: | ||
return "monochrome-transfer" | ||
} | ||
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,23 @@ | ||
package gocv | ||
|
||
import ( | ||
"image" | ||
"testing" | ||
) | ||
|
||
func TestSeamlessClone(t *testing.T) { | ||
src := NewMatWithSize(20, 20, MatTypeCV8UC3) | ||
defer src.Close() | ||
dst := NewMatWithSize(30, 30, MatTypeCV8UC3) | ||
defer dst.Close() | ||
blend := NewMatWithSize(dst.Rows(), dst.Cols(), dst.Type()) | ||
defer blend.Close() | ||
mask := src.Clone() | ||
defer mask.Close() | ||
|
||
center := image.Point{dst.Cols() / 2, dst.Rows() / 2} | ||
SeamlessClone(src, dst, mask, center, &blend, NormalClone) | ||
if blend.Empty() || dst.Rows() != blend.Rows() || dst.Cols() != blend.Cols() { | ||
t.Error("Invlalid SeamlessClone test") | ||
} | ||
} |