-
Notifications
You must be signed in to change notification settings - Fork 0
/
imgproc_test.go
53 lines (46 loc) · 1.35 KB
/
imgproc_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package opencv
import (
//"fmt"
"testing"
)
func TestExam2(t *testing.T) {
//例子url:
//http://docs.opencv.org/2.4.13.2/modules/imgproc/doc/histograms.html
hsv := NewMat()
//fmt.Println("hsv", hsv.String())
src := Imread("testdata/100100.png")
//fmt.Println("src", src.String())
CvtColor(NewInputArrayWithMat(src), NewOutputArrayWithMat(hsv), CV_BGR2HSV)
//fmt.Println("hsv", hsv.String())
hbins, sbins := 30, 32
histSize := []int{hbins, sbins}
hranges := []float32{0, 180}
sranges := []float32{0, 256}
ranges := [][]float32{hranges, sranges}
channels := []int{0, 1}
mat := NewMat()
hist := NewMat()
CalcHist(hsv, 1, channels, NewInputArrayWithMat(mat), NewOutputArrayWithMat(hist),
2, histSize, ranges)
maxVal := float64(0)
MinMaxLocWithInputArray(src, nil, &maxVal)
//fmt.Println("maxval1", maxVal)
var scale int = 10
histImg := NewMatZeros(sbins*scale, hbins*10, CV_8UC3)
//fmt.Println("histImg", histImg)
//fmt.Println("hist", histImg)
for h := 1; h < hbins; h++ {
for s := 2; s < sbins; s++ {
binVal := float32(100)
intensity := CvRound(float64(binVal) * 255 / maxVal)
Rectangle(histImg,
NewPoint(h*scale, s*scale),
NewPoint((h+1)*scale-1, (s+1)*scale-1),
NewScalarWithAll(float64(intensity)),
)
}
}
Imshow("source", NewInputArrayWithMat(src))
Imshow("h-s histogram", NewInputArrayWithMat(histImg))
Waitkey(0)
}