-
Notifications
You must be signed in to change notification settings - Fork 0
/
objDetection.go
61 lines (53 loc) · 1.4 KB
/
objDetection.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
package GoDeepStack
import (
"fmt"
"github.com/aavgoust02/GoDeepStack/util"
"strings"
)
type ObjectDetector struct {
*AbstractDetector
client *DeepStack
confidence float64
ImagePath string
}
type Object struct {
XMax float64 `json:"x_max"`
XMin float64 `json:"x_min"`
YMin float64 `json:"y_min"`
Confidence float64 `json:"confidence"`
Label string `json:"label"`
YMax float64 `json:"y_max"`
}
type Objects struct {
Predictions []Object `json:"predictions"`
Success bool `json:"success"`
}
func (od *ObjectDetector) Endpoint() string {
c := od.AbstractDetector.Client
protocol := "http"
if c.SSL {
protocol = "https"
}
return fmt.Sprintf("%s://%s:%d/v1/vision/detection", protocol, c.Addr, c.Port)
}
func (od *ObjectDetector) SetMinConfidence(confidence float64) *ObjectDetector {
od.confidence = confidence
return od
}
func (od *ObjectDetector) Detect(imagePath string) *Objects {
files := util.NewEmptyFiles()
files.Files["image"] = imagePath
params := util.NewEmptyParameters()
params.Parameters["min_confidence"] = fmt.Sprintf("%f", od.confidence)
var result *Objects
od.SendRequest(files, params, &result)
return result
}
func (o *Objects) String() string {
sb := strings.Builder{}
for _, v := range o.Predictions {
pred := fmt.Sprintf("Detected %-10s [%.2f%%]\n", v.Label, v.Confidence*100)
sb.WriteString(pred)
}
return sb.String()
}