-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathsettings_drawing.go
More file actions
99 lines (93 loc) · 2.79 KB
/
Copy pathsettings_drawing.go
File metadata and controls
99 lines (93 loc) · 2.79 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
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
package odam
import (
"image/color"
"strings"
blob "github.com/LdDl/gocv-blob/v2/blob"
"gocv.io/x/gocv"
)
// Wrap blob.DrawOptions
type DrawOptions struct {
*blob.DrawOptions
DisplayObjectID bool
}
func PrepareDrawingOptionsDefault() *DrawOptions {
return &DrawOptions{
blob.NewDrawOptionsDefault(),
true,
}
}
// PrepareDrawingOptions Prepares drawing options for blob library
func (classInfo *ClassesSettings) PrepareDrawingOptions() *DrawOptions {
drOpts := &blob.DrawOptions{}
if classInfo.DrawingSettings == nil {
// If drawing settings are not defined for certain class in JSON, then apply default settings for it
drOpts = blob.NewDrawOptionsDefault()
} else {
bboxOpts := blob.DrawBBoxOptions{
Color: color.RGBA{
classInfo.DrawingSettings.BBoxSettings.RGBA[0],
classInfo.DrawingSettings.BBoxSettings.RGBA[1],
classInfo.DrawingSettings.BBoxSettings.RGBA[2],
classInfo.DrawingSettings.BBoxSettings.RGBA[3],
},
Thickness: classInfo.DrawingSettings.BBoxSettings.Thickness,
}
cenOpts := blob.DrawCentroidOptions{
Color: color.RGBA{
classInfo.DrawingSettings.CentroidSettings.RGBA[0],
classInfo.DrawingSettings.CentroidSettings.RGBA[1],
classInfo.DrawingSettings.CentroidSettings.RGBA[2],
classInfo.DrawingSettings.CentroidSettings.RGBA[3],
},
Radius: classInfo.DrawingSettings.CentroidSettings.Radius,
Thickness: classInfo.DrawingSettings.CentroidSettings.Thickness,
}
textOpts := blob.DrawTextOptions{
Color: color.RGBA{
classInfo.DrawingSettings.TextSettings.RGBA[0],
classInfo.DrawingSettings.TextSettings.RGBA[1],
classInfo.DrawingSettings.TextSettings.RGBA[2],
classInfo.DrawingSettings.TextSettings.RGBA[3],
},
Scale: classInfo.DrawingSettings.TextSettings.Scale,
Thickness: classInfo.DrawingSettings.TextSettings.Thickness,
}
switch strings.ToLower(classInfo.DrawingSettings.TextSettings.Font) {
case "hershey_simplex":
textOpts.Font = gocv.FontHersheySimplex
break
case "hershey_plain":
textOpts.Font = gocv.FontHersheyPlain
break
case "hershey_duplex":
textOpts.Font = gocv.FontHersheyDuplex
break
case "hershey_complex":
textOpts.Font = gocv.FontHersheyComplex
break
case "hershey_triplex":
textOpts.Font = gocv.FontHersheyTriplex
break
case "hershey_complex_small":
textOpts.Font = gocv.FontHersheyComplexSmall
break
case "hershey_script_simplex":
textOpts.Font = gocv.FontHersheyScriptSimplex
break
case "hershey_script_complex":
textOpts.Font = gocv.FontHersheyScriptComplex
break
case "italic":
textOpts.Font = gocv.FontItalic
break
default:
textOpts.Font = gocv.FontHersheyPlain
break
}
drOpts = blob.NewDrawOptions(bboxOpts, cenOpts, textOpts)
}
return &DrawOptions{
drOpts,
classInfo.DrawingSettings.DisplayObjectID,
}
}