Skip to content

Commit fb0a687

Browse files
asm-jaimelazywei
authored andcommitted
Added Laplace (#112)
* Added Laplace * add test Laplacian as fuction for blur detection * add files for test blur
1 parent 17047d8 commit fb0a687

File tree

4 files changed

+62
-0
lines changed

4 files changed

+62
-0
lines changed

images/blurry-false.png

362 KB
Loading

images/blurry-true.png

218 KB
Loading

opencv/cv.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,15 @@ func Smooth(src, dst *IplImage, smoothtype,
5656
// double param3 CV_DEFAULT(0),
5757
// double param4 CV_DEFAULT(0));
5858

59+
/* Laplace The function calculates the Laplacian */
60+
func Laplace(src, dst *IplImage, aperture_size int) {
61+
C.cvLaplace(unsafe.Pointer(src), unsafe.Pointer(dst), C.int(aperture_size))
62+
}
63+
64+
//CVAPI(void) cvLaplace( const CvArr* src,
65+
// CvArr* dst,
66+
// int aperture_size CV_DEFAULT(3) );
67+
5968
/*
6069
ConvertScale converts one image to another with optional linear transformation.
6170
*/

opencv/cv_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package opencv
2+
3+
import (
4+
"errors"
5+
// "fmt"
6+
"path"
7+
"runtime"
8+
"testing"
9+
)
10+
11+
func GetFocusFromFile(file string) (err error, focus float64) {
12+
src := LoadImage(file)
13+
14+
if src == nil {
15+
return errors.New("LoadImage fail"), focus
16+
}
17+
18+
dst := CreateImage(src.Width(), src.Height(), src.Depth(), src.Channels())
19+
20+
Laplace(src, dst, 3)
21+
22+
_, sigma := MeanStdDevWithMask(dst, nil)
23+
24+
focus = sigma.Val()[0] * sigma.Val()[0]
25+
return err, focus
26+
}
27+
28+
func TestBlurredImgs(t *testing.T) {
29+
30+
// case different blur on image
31+
{
32+
_, currentfile, _, _ := runtime.Caller(0)
33+
34+
fileBlurryFalse := path.Join(path.Dir(currentfile), "../images/blurry-false.png")
35+
err, focusBlurryFalse := GetFocusFromFile(fileBlurryFalse)
36+
if err != nil {
37+
t.Error("err get focus for blurry-false: ", err)
38+
}
39+
40+
fileBlurryTrue := path.Join(path.Dir(currentfile), "../images/blurry-true.png")
41+
err, focusBlurryTrue := GetFocusFromFile(fileBlurryTrue)
42+
if err != nil {
43+
t.Error("err get focus for blurry-true: ", err)
44+
}
45+
46+
if focusBlurryTrue > focusBlurryFalse {
47+
t.Error("err value focuses, blurry-true should be lesser blurry-false: ", err)
48+
}
49+
// fmt.Println("blyrry-false: ", focusBlurryFalse)
50+
// fmt.Println("blyrry-true: ", focusBlurryTrue)
51+
52+
}
53+
}

0 commit comments

Comments
 (0)