-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils.go
94 lines (75 loc) · 2.41 KB
/
utils.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package evm
import (
"image"
"gocv.io/x/gocv"
)
type VideoProperties struct {
fps int
height int
width int
fcount int
channels int
isRGB int
}
func InitVideoProperties(vid gocv.VideoCapture) VideoProperties {
fps := vid.Get(gocv.VideoCaptureFPS)
height := vid.Get(gocv.VideoCaptureFrameHeight)
width := vid.Get(gocv.VideoCaptureFrameWidth)
fcount := vid.Get(gocv.VideoCaptureFrameCount)
channels := vid.Get(gocv.VideoCaptureChannel)
isRGB := vid.Get(gocv.VideoCaptureConvertRGB)
Props := VideoProperties{fps: int(fps), height: int(height), width: int(width), fcount: int(fcount), channels: int(channels), isRGB: int(isRGB)}
return Props
}
func GetCroppingRect(Props VideoProperties) image.Rectangle {
width := 2
height := 2
for width < (Props.width)/2 {
width = width * 2
}
for height < (Props.height)/2 {
height = height * 2
}
hdc := (Props.height - height) / 2
wdc := (Props.width - width) / 2
return image.Rect(wdc, hdc, wdc+width, hdc+height)
}
func MakePyrKernel(img gocv.Mat, up bool) image.Point {
Rows := img.Rows()
Cols := img.Cols()
if up {
if Rows%2 == 1 {
Rows += 1
}
if Cols%2 == 1 {
Cols += 1
}
}
return image.Pt(Rows/2, Cols/2)
}
func CalcGaussandLapl(img *gocv.Mat, gauss *gocv.Mat, lapl *gocv.Mat) (err error) {
temp := img.Clone()
gocv.PyrDown(*img, gauss, MakePyrKernel(*img, false), gocv.BorderDefault)
gocv.PyrUp(*gauss, &temp, image.Pt(gauss.Rows()*2, gauss.Cols()*2), gocv.BorderDefault)
gocv.Subtract(*img, temp, lapl)
return nil
}
func ImageTo64float(img gocv.Mat) gocv.Mat {
img.ConvertTo(&img, gocv.MatTypeCV64FC3)
return img
}
func ImageTo8Int(img gocv.Mat) gocv.Mat {
img.ConvertTo(&img, gocv.MatTypeCV8UC3)
return img
}
func ReconstructImageFromPyramid(Pyr Pyramid) *gocv.Mat {
Result := Pyr[len(Pyr)-1].Clone()
for i := len(Pyr) - 2; i >= 0; i-- {
gocv.PyrUp(Result, &Result, image.Pt(Result.Rows()*2, Result.Cols()*2), gocv.BorderDefault)
//fmt.Println("Try to add Pyr with shape (" + fmt.Sprint(Pyr[i].Size()) + ") and Result with shape (" + fmt.Sprint(Result.Size()) + ")")
//fmt.Println("Try to add Pyr with type (" + fmt.Sprint(Pyr[i].Type().String()) + ") and Result with shape (" + fmt.Sprint(Result.Type().String()) + ")")
//fmt.Println("Try to add Pyr with channels (" + fmt.Sprint(Pyr[i].Channels()) + ") and Result with shape (" + fmt.Sprint(Result.Channels()) + ")")
gocv.Add(Result, Pyr[i], &Result)
}
return &Result
}