747ab25325
CI / changes (push) Successful in 1m31s
CI / ad (push) Successful in 26s
CI / admin (push) Successful in 17s
CI / analysis (push) Successful in 24s
CI / bff (push) Successful in 16s
CI / chore (push) Successful in 14s
CI / equipment (push) Successful in 15s
CI / express (push) Successful in 13s
CI / factory (push) Successful in 13s
CI / message (push) Successful in 10s
CI / order (push) Successful in 10s
CI / payment (push) Successful in 11s
CI / percutaneous (push) Successful in 11s
CI / product (push) Successful in 12s
CI / record (push) Successful in 12s
CI / sale (push) Successful in 11s
CI / store (push) Successful in 11s
CI / support (push) Successful in 11s
CI / task (push) Successful in 10s
CI / user (push) Successful in 18s
CI / water (push) Successful in 13s
CI / wecom (push) Successful in 13s
CI / ws (push) Successful in 6s
50 lines
1.0 KiB
Go
50 lines
1.0 KiB
Go
package facepp
|
|
|
|
import (
|
|
"encoding/json"
|
|
)
|
|
|
|
type PixelBox struct {
|
|
Left float64 `json:"left"`
|
|
Top float64 `json:"top"`
|
|
Width float64 `json:"width"`
|
|
Height float64 `json:"height"`
|
|
}
|
|
|
|
var MapTypeKeys = map[string][]string{
|
|
"acne": {"acne", "acne_pustule", "acne_nodule", "acne_mark"},
|
|
"closed_comedones": {"closed_comedones"},
|
|
"brown_spot": {"brown_spot"},
|
|
"mole": {"mole"},
|
|
}
|
|
|
|
func ExtractPixelBoxes(result json.RawMessage, keys ...string) ([]PixelBox, error) {
|
|
if len(result) == 0 || string(result) == "null" {
|
|
return nil, nil
|
|
}
|
|
var root map[string]json.RawMessage
|
|
if err := json.Unmarshal(result, &root); err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
var out []PixelBox
|
|
for _, key := range keys {
|
|
raw, ok := root[key]
|
|
if !ok {
|
|
continue
|
|
}
|
|
for _, rect := range locatedRectangles(raw) {
|
|
if rect.Width <= 0 || rect.Height <= 0 {
|
|
continue
|
|
}
|
|
out = append(out, PixelBox{
|
|
Left: rect.Left,
|
|
Top: rect.Top,
|
|
Width: rect.Width,
|
|
Height: rect.Height,
|
|
})
|
|
}
|
|
}
|
|
return out, nil
|
|
}
|