-
Notifications
You must be signed in to change notification settings - Fork 2
/
read_plates.go
38 lines (35 loc) · 922 Bytes
/
read_plates.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
package license_plate_recognition
import (
"image"
"time"
"github.com/disintegration/imaging"
)
// ReadLicensePlates Returns found license plates with information about each one
func (net *YOLONetwork) ReadLicensePlates(imgSrc image.Image, saveCrop bool) (*YOLOResponse, error) {
resp := YOLOResponse{}
st := time.Now()
plates, err := net.detectPlates(imgSrc)
if err != nil {
return nil, err
}
for i := range plates {
rectcropimg := imaging.Crop(imgSrc, plates[i])
rects, classesIDs, text, prob, err := net.detectSymbols(rectcropimg)
if err != nil {
return nil, err
}
plResp := PlateResponse{
Rect: plates[i],
Text: text,
Probability: float64(prob),
OCRClassesIDs: classesIDs,
OCRRects: rects,
}
if saveCrop {
plResp.CroppedNumber = rectcropimg
}
resp.Plates = append(resp.Plates, plResp)
}
resp.Elapsed = time.Since(st)
return &resp, nil
}