-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlibtools.go
More file actions
49 lines (39 loc) · 1.02 KB
/
libtools.go
File metadata and controls
49 lines (39 loc) · 1.02 KB
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
package goreco
import (
"bytes"
"fmt"
"gocv.io/x/gocv"
"image"
"image/color"
)
func MarkObjects(img *gocv.Mat, boxes []Box, putText bool) {
scaleX := float32(img.Cols())
scaleY := float32(img.Rows())
for i := 0; i < len(boxes); i += 1 {
box := boxes[i]
scaledRect := image.Rect(
int(box.rect.min[0]*scaleX), int(box.rect.min[1]*scaleY),
int(box.rect.max[0]*scaleX), int(box.rect.max[1]*scaleY),
)
gocv.Rectangle(img, scaledRect, color.RGBA{0, 255, 0, 0}, 2)
if putText {
gocv.PutText(img, fmt.Sprintf("%d(%f)", box.class, box.conf), scaledRect.Min, 1, 2, color.RGBA{100, 200, 0, 0}, 3)
}
}
}
type Jpeg []byte
var JpegHead = []byte{0xff, 0xd8}
var JpegTail = []byte{0xFF, 0xD9}
func CheckJpegHeader(data []byte) bool {
return bytes.Equal(data[:2], JpegHead)
//return bytes.Equal(data[:2], JpegHead) && bytes.Equal(data[len(data)-2:], JpegTail)
}
func FindMaxFloat32(floats []float32) (max float32, idx int) {
for i, v := range floats {
if v > max {
max = v
idx = i
}
}
return max, idx
}