2021-05-25 14:30:24 +02:00
|
|
|
package face
|
|
|
|
|
2021-08-11 13:21:05 +02:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
)
|
|
|
|
|
2021-05-25 14:30:24 +02:00
|
|
|
// Points is a list of face landmark coordinates.
|
|
|
|
type Points []Point
|
|
|
|
|
|
|
|
// Markers returns relative marker positions for all face landmark coordinates.
|
2021-06-01 17:39:03 +02:00
|
|
|
func (pts Points) Markers(r Point, rows, cols float32) (m Markers) {
|
2021-05-25 14:30:24 +02:00
|
|
|
for _, p := range pts {
|
2021-06-01 17:39:03 +02:00
|
|
|
m = append(m, p.Marker(r, rows, cols))
|
2021-05-25 14:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return m
|
|
|
|
}
|
|
|
|
|
2021-08-11 13:21:05 +02:00
|
|
|
// Point represents a face landmark position.
|
2021-05-25 14:30:24 +02:00
|
|
|
type Point struct {
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
Row int `json:"x,omitempty"`
|
|
|
|
Col int `json:"y,omitempty"`
|
|
|
|
Scale int `json:"size,omitempty"`
|
|
|
|
}
|
|
|
|
|
2021-08-11 13:21:05 +02:00
|
|
|
// String returns the face landmark position as string.
|
|
|
|
func (p Point) String() string {
|
|
|
|
return fmt.Sprintf("%d-%d-%d", p.Row, p.Col, p.Scale)
|
|
|
|
}
|
|
|
|
|
2021-05-25 14:30:24 +02:00
|
|
|
// NewPoint returns new face landmark coordinates.
|
|
|
|
func NewPoint(name string, row, col, scale int) Point {
|
|
|
|
return Point{
|
|
|
|
Name: name,
|
|
|
|
Row: row,
|
|
|
|
Col: col,
|
|
|
|
Scale: scale,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Marker returns a relative marker position for the face landmark coordinates.
|
2021-06-01 17:39:03 +02:00
|
|
|
func (p Point) Marker(r Point, rows, cols float32) Marker {
|
|
|
|
if rows < 1 {
|
|
|
|
rows = 1
|
|
|
|
}
|
|
|
|
|
|
|
|
if cols < 1 {
|
|
|
|
cols = 1
|
2021-05-25 14:30:24 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return NewMarker(
|
|
|
|
p.Name,
|
2021-06-01 17:39:03 +02:00
|
|
|
float32(p.Col-r.Col)/cols,
|
|
|
|
float32(p.Row-r.Row)/rows,
|
|
|
|
float32(p.Scale)/rows,
|
|
|
|
float32(p.Scale)/cols,
|
2021-05-25 14:30:24 +02:00
|
|
|
)
|
|
|
|
}
|
2021-07-16 14:34:05 +02:00
|
|
|
|
|
|
|
// TopLeft returns the top left position of the face.
|
|
|
|
func (p Point) TopLeft() (int, int) {
|
|
|
|
return p.Row - (p.Scale / 2), p.Col - (p.Scale / 2)
|
|
|
|
}
|