mirror of
https://github.com/hybridgroup/gocv
synced 2025-08-25 08:41:04 +08:00
photo: add Decolor() function
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
@@ -197,7 +197,7 @@ Your pull requests will be greatly appreciated!
|
||||
- [ ] [createTonemapDrago](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga72bf92bb6b8653ee4be650ac01cf50b6)
|
||||
- [ ] [createTonemapMantiuk](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#ga3b3f3bf083b7515802f039a6a70f2d21)
|
||||
- [ ] [createTonemapReinhard](https://docs.opencv.org/master/d6/df5/group__photo__hdr.html#gadabe7f6bf1fa96ad0fd644df9182c2fb)
|
||||
- [ ] [decolor](https://docs.opencv.org/master/d4/d32/group__photo__decolor.html#ga4864d4c007bda5dacdc5e9d4ed7e222c)
|
||||
- [X] [decolor](https://docs.opencv.org/master/d4/d32/group__photo__decolor.html#ga4864d4c007bda5dacdc5e9d4ed7e222c)
|
||||
|
||||
- [ ] stitching. Images stitching
|
||||
- [ ] [Stitcher](https://docs.opencv.org/4.x/d2/d8d/classcv_1_1Stitcher.html)
|
||||
|
@@ -222,3 +222,12 @@ OpenCVResult PhotoInpaint(Mat src, Mat mask, Mat dst, float inpaint_radius, int
|
||||
return errorResult(e.code, e.what());
|
||||
}
|
||||
}
|
||||
|
||||
OpenCVResult Decolor(Mat src, Mat grey, Mat boost) {
|
||||
try {
|
||||
cv::decolor(*src, *grey, *boost);
|
||||
return successResult();
|
||||
} catch(const cv::Exception& e) {
|
||||
return errorResult(e.code, e.what());
|
||||
}
|
||||
}
|
||||
|
10
photo.go
10
photo.go
@@ -317,3 +317,13 @@ const (
|
||||
func Inpaint(src Mat, mask Mat, dst *Mat, inpaintRadius float32, algorithmType InpaintMethods) error {
|
||||
return OpenCVResult(C.PhotoInpaint(C.Mat(src.Ptr()), C.Mat(mask.Ptr()), C.Mat(dst.Ptr()), C.float(inpaintRadius), C.int(algorithmType)))
|
||||
}
|
||||
|
||||
// Decolor Transforms a color image to a grayscale image.
|
||||
// It is a basic tool in digital printing, stylized black-and-white photograph rendering,
|
||||
// and in many single channel image processing applications
|
||||
//
|
||||
// For further details, please see:
|
||||
// https://docs.opencv.org/4.x/d4/d32/group__photo__decolor.html#ga4864d4c007bda5dacdc5e9d4ed7e222c
|
||||
func Decolor(src Mat, grey *Mat, boost *Mat) error {
|
||||
return OpenCVResult(C.Decolor(src.p, grey.p, boost.p))
|
||||
}
|
||||
|
1
photo.h
1
photo.h
@@ -50,6 +50,7 @@ OpenCVResult PencilSketch(Mat src, Mat dst1, Mat dst2, float sigma_s, float sigm
|
||||
OpenCVResult Stylization(Mat src, Mat dst, float sigma_s, float sigma_r);
|
||||
|
||||
OpenCVResult PhotoInpaint(Mat src, Mat mask, Mat dst, float inpaint_radius, int algorithm_type);
|
||||
OpenCVResult Decolor(Mat src, Mat grey, Mat boost);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@@ -260,3 +260,29 @@ func TestInpaint(t *testing.T) {
|
||||
t.Error("Invalid inpaint test")
|
||||
}
|
||||
}
|
||||
|
||||
func TestDecolor(t *testing.T) {
|
||||
img := IMRead("images/face-detect.jpg", IMReadColor)
|
||||
if img.Empty() {
|
||||
t.Error("Invalid read of Mat in Decolor test")
|
||||
}
|
||||
defer img.Close()
|
||||
|
||||
grey := NewMat()
|
||||
defer grey.Close()
|
||||
|
||||
boost := NewMat()
|
||||
defer boost.Close()
|
||||
|
||||
if err := Decolor(img, &grey, &boost); err != nil {
|
||||
t.Error("Error in Decolor test", err)
|
||||
}
|
||||
|
||||
if grey.Empty() || img.Rows() != grey.Rows() || img.Cols() != grey.Cols() {
|
||||
t.Error("Error in Decolor test")
|
||||
}
|
||||
|
||||
if boost.Empty() || img.Rows() != boost.Rows() || img.Cols() != boost.Cols() {
|
||||
t.Error("Error in Decolor test")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user