-
Notifications
You must be signed in to change notification settings - Fork 110
/
distorter.go
36 lines (30 loc) · 1.27 KB
/
distorter.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
package transform
import "github.com/pkg/errors"
// DistortionType is the name of the distortion model.
type DistortionType string
const (
// BrownConradyDistortionType is for simple lenses of narrow field easily modeled as a pinhole camera.
BrownConradyDistortionType = DistortionType("brown_conrady")
// KannalaBrandtDistortionType is for wide-angle and fisheye lense distortion.
KannalaBrandtDistortionType = DistortionType("kannala_brandt")
)
// Distorter defines a Transform that takes an undistorted image and distorts it according to the model.
type Distorter interface {
ModelType() DistortionType
CheckValid() error
Parameters() []float64
Transform(x, y float64) (float64, float64)
}
// InvalidDistortionError is used when the distortion_parameters are invalid.
func InvalidDistortionError(msg string) error {
return errors.Wrapf(errors.New("invalid distortion_parameters"), msg)
}
// NewDistorter returns a Distorter given a valid DistortionType and its parameters.
func NewDistorter(distortionType DistortionType, parameters []float64) (Distorter, error) {
switch distortionType { //nolint:exhaustive
case BrownConradyDistortionType:
return NewBrownConrady(parameters)
default:
return nil, errors.Errorf("do no know how to parse %q distortion model", distortionType)
}
}