-
Notifications
You must be signed in to change notification settings - Fork 0
/
Timeline_test.go
208 lines (153 loc) · 4.5 KB
/
Timeline_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
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
package evm
import (
"fmt"
"sync"
"testing"
"gocv.io/x/gocv"
)
func TestMain(t *testing.T) {
var file string = "moritz1.mp4"
var levels int = 6
vid, err := gocv.VideoCaptureFile(file)
if err != nil {
fmt.Println(err)
return
}
defer vid.Close()
Props := InitVideoProperties(*vid)
Egypt := make([]Pyramid, Props.fcount)
CroppingRect := GetCroppingRect(Props)
SpaTiPyr := CreateTimePyramid(levels, Props.fcount, CroppingRect.Dy(), CroppingRect.Dx(), 3)
OutPut, err := gocv.VideoWriterFile(("processed_" + file), vid.CodecString(), vid.Get(gocv.VideoCaptureFPS), CroppingRect.Dx(), CroppingRect.Dy(), true)
if err != nil {
fmt.Println(err)
return
}
defer OutPut.Close()
OutputFrame := gocv.NewMat()
defer OutputFrame.Close()
window := gocv.NewWindow("Std_out")
defer window.Close()
window2 := gocv.NewWindow("2")
defer window2.Close()
window3 := gocv.NewWindow("3")
defer window2.Close()
window4 := gocv.NewWindow("4")
defer window2.Close()
window5 := gocv.NewWindow("5")
defer window2.Close()
window6 := gocv.NewWindow("6")
defer window2.Close()
//window7 := gocv.NewWindow("7")
//defer window2.Close()
window_result := gocv.NewWindow("Result")
defer window2.Close()
img := gocv.NewMat()
defer img.Close()
gaussian_img := gocv.NewMat()
defer gaussian_img.Close()
laplacian_img := gocv.NewMat()
defer laplacian_img.Close()
//imges := []gocv.Mat
fmt.Println(img.Channels())
fmt.Println(Props)
for i := 0; i < Props.fcount; i++ {
if ok := vid.Read(&img); !ok {
fmt.Printf("Device closed: %v\n", file)
return
}
if img.Empty() {
continue
}
img_temp := img.Region(CroppingRect)
img = ImageTo64float(img_temp)
Egypt[i] = CreatePyramid(img, levels)
SpaTiPyr.AddPyramid(Egypt[i], i)
OutputFrame = ReconstructImageFromPyramid(Egypt[i]).Clone()
BGR := gocv.Split(OutputFrame)
gocv.Merge(BGR, &OutputFrame)
OutPut.Write(ImageTo8Int(OutputFrame))
//Result.ConvertTo(&Result, gocv.MatTypeCV8UC3)
//fft.FFT2Real()
window2.IMShow(ImageTo8Int(Egypt[i][0].Clone()))
window3.IMShow(ImageTo8Int(Egypt[i][1].Clone()))
window4.IMShow(ImageTo8Int(Egypt[i][2].Clone()))
window5.IMShow(ImageTo8Int(Egypt[i][3].Clone()))
window6.IMShow(ImageTo8Int(Egypt[i][4].Clone()))
//window7.IMShow(TemporalPyramid[i][5])
window_result.IMShow(ImageTo8Int(OutputFrame))
window.IMShow(ImageTo8Int(img.Clone()))
//fmt.Println(img.Size())
//fmt.Println(img.Size())
window.WaitKey(32)
}
BGRamp := []float64{float64(-10), float64(-10), float64(80)}
fil, err := CreateFilter(Props.fps, 0.9, 1.2, 4, BGRamp)
if err != nil {
fmt.Println(err)
return
}
newTiPyr := SpaTiPyr.Copy()
var WG sync.WaitGroup
numworkers := 5
ch := make(chan RoomInPyr, (2)*newTiPyr.RootRows*newTiPyr.RootCols)
fmt.Printf("made channel with len %v \n", 2*newTiPyr.RootRows*newTiPyr.RootCols)
newTiPyr.RGB2Gray()
newTiPyr.PrintShape()
for z := 0; z < numworkers; z++ {
WG.Add(1)
fmt.Printf("Create worker number: %v \n", z)
go func(WG *sync.WaitGroup) {
for Room := range ch {
newTiPyr.FilterGrayAt(Room.row, Room.col, Room.level, Room.fil, Room.chanum)
}
WG.Done()
}(&WG)
}
WG.Add(1)
go func(WG *sync.WaitGroup) {
i := 0
for Room := range ch {
fmt.Printf("\rworker %v did his %v task", numworkers+1, i)
newTiPyr.FilterGrayAt(Room.row, Room.col, Room.level, Room.fil, Room.chanum)
i += 1
}
fmt.Printf("\n")
WG.Done()
}(&WG)
for level, levels := range newTiPyr.Level {
for row := 0; row < levels.SpacialPictures[0].Rows(); row++ {
for col := 0; col < levels.SpacialPictures[0].Cols(); col++ {
ch <- RoomInPyr{row, col, level, fil, 3}
}
}
}
close(ch)
WG.Wait()
newTiPyr.Gray2RGB()
fmt.Println("STP created printing to movie")
newTiPyr.PrintShape()
FFTOutPut, err := gocv.VideoWriterFile(("FFT_processed_" + file), vid.CodecString(), vid.Get(gocv.VideoCaptureFPS), CroppingRect.Dx(), CroppingRect.Dy(), true)
if err != nil {
fmt.Println(err)
return
}
defer FFTOutPut.Close()
for PiT := 0; PiT < newTiPyr.Frames; PiT++ {
Pyr := newTiPyr.GetPyramid(PiT)
RecImg := ReconstructImageFromPyramid(Pyr)
IntImg := ImageTo8Int(*RecImg)
//gocv.CvtColor(IntImg, &IntImg, gocv.ColorGrayToBGR)
FFTOutPut.Write((IntImg))
BGR := gocv.Split(IntImg)
window.IMShow(IntImg)
window2.IMShow(BGR[0])
window3.IMShow(BGR[1])
window4.IMShow(BGR[2])
window.WaitKey(32)
//FFTOutPut.Write(ImageTo8Int(*ReconstructImageFromPyramid(newTiPyr.GetPyramid(PiT))))
}
//window.WaitKey(-1)
fmt.Println(len(Egypt))
fmt.Println("lel")
}