-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstep5_cropVideo.go
52 lines (42 loc) · 1.33 KB
/
step5_cropVideo.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
package main
import (
"image"
"image/draw"
"fmt"
)
// ---------------- Step Function ----------------
func cropVideo() {
for {
select {
case mask, ok := <-procFrameQueue4:
if !ok {
// Channel is closed
fmt.Println("Wrote Output Image Sequence")
return
}
// Process the received image
croppedImg := cropToBBox(mask.Image, mask.CBox)
//? Experimental zoom out and aspect ratio when bbox > cropRect
if mask.zoom {
// croppedImg = ResizeWithVerticalLetterbox(croppedImg, squareSize, squareSize)
croppedImg = ResizeRGBA(croppedImg, squareSize, squareSize)
}
if drawUI {
croppedFrameRW.Lock()
croppedFrame = croppedImg
croppedFrameRW.Unlock()
}
if !playOnlyMode {
copyAndWrite(croppedImg)
}
}
}
}
// ---------------- Helper Functions ----------------
func cropToBBox(src *image.RGBA, cropRect image.Rectangle) *image.RGBA {
// Create a new RGBA image for the cropped portion
dst := image.NewRGBA(cropRect)
// Copy the cropped portion from the source image to the destination image
draw.Draw(dst, cropRect, src, cropRect.Min, draw.Src)
return dst
}