var cs merlin.CannySettings
err = viper.UnmarshalKey("et_cannysettings", &cs)
if err != nil {
log.Error().Msgf("failed to unmarshal et_cannysettings: %v", err)
} else {
log.Info().Msgf("et_cannysettings: %v", cs)
}`
structs:
type GaussianBlurSettings struct { Right eyetracking.GaussianBlurjson:"right" Left eyetracking.GaussianBlurjson:"left"`
}
type CannySettings struct {
Right eyetracking.CannyEdgeDetection json:"right"
Left eyetracking.CannyEdgeDetection json:"left"
}
type GaussianBlur struct {
Apply bool json:"apply" // apply determines, if the gaussian blur filter is truned on or off
Ksize image.Point json:"ksize" // Ksize is the Gaussian blur kernel size
SigmaX float64 json:"sigma_x" // SigmaX is the Gaussian blur kernel standard deviation in X direction
SigmaY float64 json:"sigma_y" // SigmaY is the Gaussian blur kernel standard deviation in Y direction
BorderType gocv.BorderType json:"border_type" // BorderType is the border type used in the Gaussian blur filter
}
type CannyEdgeDetection struct {
Apply bool json:"apply" // apply determines, if the canny edge detection is truned on or off
KernelSize uint json:"kernel_size" // KerlenSize is the Gaussian blur kernel size
LowThreshold float64 json:"low_threshold" // LowThreshold is the low threshold for the Canny edge detection algorithm
HighThreshold float64 json:"high_threshold" // HighThreshold is the high threshold for the Canny edge detection algorithm
}
`
I'm using UnmarshalKey to read some structs from a json config file (relevant snippet below).
I use UnmarshalKey to read these into structs as shown below.
UnmarshalKey works for all structs in my project except
CannySettings
.{"level":"info","time":"2024-02-06T11:14:55+01:00","message":"et_gaussianblursettings: {{true (5,5) 0 0 border-constant} {true (5,5) 0 0 border-constant}}"} {"level":"info","time":"2024-02-06T11:14:55+01:00","message":"et_cannysettings: {{true 0 0 0} {true 0 0 0}}"}
However, viper.GetStringMap() returns the correct data for CannySettings.
`var gbs merlin.GaussianBlurSettings err = viper.UnmarshalKey("et_gaussianblursettings", &gbs) if err != nil { log.Error().Msgf("failed to unmarshal et_gaussianblursettings: %v", err) } else { log.Info().Msgf("et_gaussianblursettings: %v", gbs) }
structs:
type GaussianBlurSettings struct { Right eyetracking.GaussianBlur
json:"right"Left eyetracking.GaussianBlur
json:"left"` }type CannySettings struct { Right eyetracking.CannyEdgeDetection
json:"right"
Left eyetracking.CannyEdgeDetectionjson:"left"
}type GaussianBlur struct { Apply bool
json:"apply"
// apply determines, if the gaussian blur filter is truned on or off Ksize image.Pointjson:"ksize"
// Ksize is the Gaussian blur kernel size SigmaX float64json:"sigma_x"
// SigmaX is the Gaussian blur kernel standard deviation in X direction SigmaY float64json:"sigma_y"
// SigmaY is the Gaussian blur kernel standard deviation in Y direction BorderType gocv.BorderTypejson:"border_type"
// BorderType is the border type used in the Gaussian blur filter }type CannyEdgeDetection struct { Apply bool
json:"apply"
// apply determines, if the canny edge detection is truned on or off KernelSize uintjson:"kernel_size"
// KerlenSize is the Gaussian blur kernel size LowThreshold float64json:"low_threshold"
// LowThreshold is the low threshold for the Canny edge detection algorithm HighThreshold float64json:"high_threshold"
// HighThreshold is the high threshold for the Canny edge detection algorithm } `... "et_cannysettings": { "right": { "apply": true, "kernel_size": 20, "low_threshold": 40, "high_threshold": 100 }, "left": { "apply": true, "kernel_size": 20, "low_threshold": 40, "high_threshold": 100 } }, "et_findellipsesettings": { "right": { "apply": true }, "left": { "apply": true } }, "et_gaussianblursettings": { "right": { "apply": true, "ksize": { "X": 5, "Y": 5 }, "sigma_x": 0, "sigma_y": 0, "border_type": 0 }, "left": { "apply": true, "ksize": { "X": 5, "Y": 5 }, "sigma_x": 0, "sigma_y": 0, "border_type": 0 } }, ...