-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpipeline.go
133 lines (104 loc) · 2.92 KB
/
pipeline.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
package main
import (
"image"
"image/color"
"image/draw"
"sync"
"time"
"path/filepath"
"github.com/schollz/progressbar/v3"
"github.com/AlexEidt/Vidio"
)
var (
inputFrame *image.RGBA
inputFrameRW sync.Mutex
procFrameQueue1 chan *image.RGBA
grayFrame *image.RGBA
grayFrameRW sync.Mutex
procFrameQueue2 chan *ImageGrayMask
binaryFrame *image.RGBA
binaryFrameRW sync.Mutex
procFrameQueue3 chan *ImageGrayBoundMask
calcFrame *image.RGBA
calcFrameRW sync.Mutex
procFrameQueue4 chan *ImageCropMask
croppedFrame *image.RGBA
croppedFrameRW sync.Mutex
tempDirTinyVid string
tempDirFrames string
)
type ImageGrayMask struct {
Mask *image.Gray
Image *image.RGBA
}
type ImageGrayBoundMask struct {
Mask *image.Gray
Image *image.RGBA
Bbox image.Rectangle
Subj int
}
type ImageCropMask struct {
CBox image.Rectangle
Image *image.RGBA
zoom bool
}
func establishPipesAndImgs() {
inputFrame = image.NewRGBA(image.Rect(0, 0, screenWidth, squareSize))
draw.Draw(inputFrame, inputFrame.Bounds(), &image.Uniform{color.RGBA{255,0,255,255}}, image.ZP, draw.Src)
procFrameQueue1 = make(chan *image.RGBA)
grayFrame = image.NewRGBA(image.Rect(0, 0, screenWidth, squareSize))
draw.Draw(grayFrame, grayFrame.Bounds(), &image.Uniform{color.RGBA{255,0,0,255}}, image.ZP, draw.Src)
procFrameQueue2 = make(chan *ImageGrayMask)
binaryFrame = image.NewRGBA(image.Rect(0, 0, screenWidth, squareSize))
draw.Draw(binaryFrame, binaryFrame.Bounds(), &image.Uniform{color.RGBA{0,255,0,255}}, image.ZP, draw.Src)
procFrameQueue3 = make(chan *ImageGrayBoundMask)
calcFrame = image.NewRGBA(image.Rect(0, 0, screenWidth, squareSize))
draw.Draw(calcFrame, calcFrame.Bounds(), &image.Uniform{color.RGBA{0,0,255,255}}, image.ZP, draw.Src)
procFrameQueue4 = make(chan *ImageCropMask)
croppedFrame = image.NewRGBA(image.Rect(0, 0, squareSize, squareSize))
draw.Draw(croppedFrame, croppedFrame.Bounds(), &image.Uniform{color.RGBA{0,255,255,255}}, image.ZP, draw.Src)
}
func startPipeline() {
video, _ := vidio.NewVideo(filepath.Join(tempDirTinyVid,getBasenameWithoutExt(inputVideo)+".mp4"))
tframes = video.Frames()
cframes = 0
if !playOnlyMode {
bar = progressbar.Default(int64(tframes))
}
video.Close()
go readVideo()
go grayscaleVideo()
go binaryVideo()
go calcVideo()
go cropVideo()
}
func checkPipelineDone() bool {
if cframes == tframes {
if !playOnlyMode {
bar.Clear()
bar.Close()
}
close(procFrameQueue1)
close(procFrameQueue2)
close(procFrameQueue3)
close(procFrameQueue4)
if !playOnlyMode {
// Last step to make video file from image sequence
joinOutputImgs()
}
return true
}
return false
}
func tickPipeline() {
ticker := time.NewTicker(time.Millisecond * 16)
defer ticker.Stop()
for {
select {
case <-ticker.C:
if checkPipelineDone() {
return
}
}
}
}