mirror of https://bitbucket.org/ausocean/av.git
added logging to turbidity sensor
This commit is contained in:
parent
6505223782
commit
07c2472bdd
|
@ -149,7 +149,7 @@ func NewTurbidityProbe(log logger.Logger, delay time.Duration) (*turbidityProbe,
|
||||||
// Create the turbidity sensor.
|
// Create the turbidity sensor.
|
||||||
standard := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
standard := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
||||||
template := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
template := gocv.IMRead("../../turbidity/images/template.jpg", gocv.IMReadGrayScale)
|
||||||
ts, err := turbidity.NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha)
|
ts, err := turbidity.NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha, log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error("failed create turbidity sensor", "error", err.Error())
|
log.Error("failed create turbidity sensor", "error", err.Error())
|
||||||
}
|
}
|
||||||
|
@ -195,8 +195,9 @@ func (tp *turbidityProbe) Write(p []byte) (int, error) {
|
||||||
tp.log.Log(logger.Debug, "found frames", "frames", len(imgs))
|
tp.log.Log(logger.Debug, "found frames", "frames", len(imgs))
|
||||||
|
|
||||||
// Process video data to get saturation and contrast scores.
|
// Process video data to get saturation and contrast scores.
|
||||||
|
startTime := time.Now()
|
||||||
res, err := tp.ts.Evaluate(imgs)
|
res, err := tp.ts.Evaluate(imgs)
|
||||||
tp.log.Log(logger.Debug, "finished evaluation")
|
tp.log.Log(logger.Debug, "finished evaluation", "total duration (sec)", time.Since(startTime).Seconds())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
tp.log.Error("evaluate failed", "error", err.Error())
|
tp.log.Error("evaluate failed", "error", err.Error())
|
||||||
return len(p), err
|
return len(p), err
|
||||||
|
@ -242,7 +243,7 @@ func main() {
|
||||||
rv *revid.Revid
|
rv *revid.Revid
|
||||||
p *turbidityProbe
|
p *turbidityProbe
|
||||||
)
|
)
|
||||||
p, err := NewTurbidityProbe(*log, 120*time.Second)
|
p, err := NewTurbidityProbe(*log, 60*time.Second)
|
||||||
|
|
||||||
log.Log(logger.Debug, "initialising netsender client")
|
log.Log(logger.Debug, "initialising netsender client")
|
||||||
ns, err := netsender.New(log, nil, readPin(p, rv, log), nil, createVarMap())
|
ns, err := netsender.New(log, nil, readPin(p, rv, log), nil, createVarMap())
|
||||||
|
|
|
@ -35,7 +35,9 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"image"
|
"image"
|
||||||
"math"
|
"math"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -46,10 +48,11 @@ type TurbiditySensor struct {
|
||||||
standard, standardCorners gocv.Mat
|
standard, standardCorners gocv.Mat
|
||||||
k1, k2, sobelFilterSize int
|
k1, k2, sobelFilterSize int
|
||||||
scale, alpha float64
|
scale, alpha float64
|
||||||
|
logger logger.Logger
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewTurbiditySensor returns a new TurbiditySensor.
|
// NewTurbiditySensor returns a new TurbiditySensor.
|
||||||
func NewTurbiditySensor(template, standard gocv.Mat, k1, k2, sobelFilterSize int, scale, alpha float64) (*TurbiditySensor, error) {
|
func NewTurbiditySensor(template, standard gocv.Mat, k1, k2, sobelFilterSize int, scale, alpha float64, logger logger.Logger) (*TurbiditySensor, error) {
|
||||||
ts := new(TurbiditySensor)
|
ts := new(TurbiditySensor)
|
||||||
templateCorners := gocv.NewMat()
|
templateCorners := gocv.NewMat()
|
||||||
standardCorners := gocv.NewMat()
|
standardCorners := gocv.NewMat()
|
||||||
|
@ -76,6 +79,7 @@ func NewTurbiditySensor(template, standard gocv.Mat, k1, k2, sobelFilterSize int
|
||||||
|
|
||||||
ts.k1, ts.k2, ts.sobelFilterSize = k1, k2, sobelFilterSize
|
ts.k1, ts.k2, ts.sobelFilterSize = k1, k2, sobelFilterSize
|
||||||
ts.alpha, ts.scale = alpha, scale
|
ts.alpha, ts.scale = alpha, scale
|
||||||
|
ts.logger = logger
|
||||||
return ts, nil
|
return ts, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,16 +91,24 @@ func (ts TurbiditySensor) Evaluate(imgs []gocv.Mat) (*Results, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
for i := range imgs {
|
for i := range imgs {
|
||||||
|
timer := time.Now()
|
||||||
marker, err := ts.transform(imgs[i])
|
marker, err := ts.transform(imgs[i])
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("could not transform image: %d: %w", i, err)
|
return nil, fmt.Errorf("could not transform image: %d: %w", i, err)
|
||||||
}
|
}
|
||||||
edge := ts.sobel(marker)
|
|
||||||
|
|
||||||
|
ts.logger.Log(logger.Debug, "transform successful", "transform duration (sec)", time.Since(timer).Seconds())
|
||||||
|
|
||||||
|
timer = time.Now()
|
||||||
|
edge := ts.sobel(marker)
|
||||||
|
ts.logger.Log(logger.Debug, "sobel filter successful", "sobel duration", time.Since(timer).Seconds())
|
||||||
|
|
||||||
|
timer = time.Now()
|
||||||
sharpScore, contScore, err := ts.EvaluateImage(marker, edge)
|
sharpScore, contScore, err := ts.EvaluateImage(marker, edge)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
ts.logger.Log(logger.Debug, "sharpness and contrast evaluation successful", "evaluation duration", time.Since(timer).Seconds())
|
||||||
result.Update(sharpScore, contScore, float64(i), i)
|
result.Update(sharpScore, contScore, float64(i), i)
|
||||||
}
|
}
|
||||||
return result, nil
|
return result, nil
|
||||||
|
|
|
@ -30,12 +30,15 @@ package turbidity
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"io"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"bitbucket.org/ausocean/utils/logger"
|
||||||
"gocv.io/x/gocv"
|
"gocv.io/x/gocv"
|
||||||
"gonum.org/v1/gonum/stat"
|
"gonum.org/v1/gonum/stat"
|
||||||
"gonum.org/v1/plot"
|
"gonum.org/v1/plot"
|
||||||
"gonum.org/v1/plot/plotutil"
|
"gonum.org/v1/plot/plotutil"
|
||||||
|
"gopkg.in/natefinch/lumberjack.v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -44,15 +47,35 @@ const (
|
||||||
increment = 2.5 // Increment of the turbidity level.
|
increment = 2.5 // Increment of the turbidity level.
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Logging configuration.
|
||||||
|
const (
|
||||||
|
logPath = "/var/log/netsender/netsender.log"
|
||||||
|
logMaxSize = 500 // MB
|
||||||
|
logMaxBackup = 10
|
||||||
|
logMaxAge = 28 // days
|
||||||
|
logVerbosity = logger.Info
|
||||||
|
logSuppress = true
|
||||||
|
)
|
||||||
|
|
||||||
// TestImages will read a library of test images and calculate the sharpness and contrast scores.
|
// TestImages will read a library of test images and calculate the sharpness and contrast scores.
|
||||||
// A plot of the results will be generated and stored in the plots directory.
|
// A plot of the results will be generated and stored in the plots directory.
|
||||||
func TestImages(t *testing.T) {
|
func TestImages(t *testing.T) {
|
||||||
|
|
||||||
const (
|
const (
|
||||||
k1, k2 = 8, 8
|
k1, k2 = 8, 8
|
||||||
filterSize = 3
|
filterSize = 3
|
||||||
scale, alpha = 1.0, 1.0
|
scale, alpha = 1.0, 1.0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Create lumberjack logger.
|
||||||
|
fileLog := &lumberjack.Logger{
|
||||||
|
Filename: logPath,
|
||||||
|
MaxSize: logMaxSize,
|
||||||
|
MaxBackups: logMaxBackup,
|
||||||
|
MaxAge: logMaxAge,
|
||||||
|
}
|
||||||
|
log := logger.New(logVerbosity, io.MultiWriter(fileLog), logSuppress)
|
||||||
|
|
||||||
template := gocv.IMRead("images/template.jpg", gocv.IMReadGrayScale)
|
template := gocv.IMRead("images/template.jpg", gocv.IMReadGrayScale)
|
||||||
standard := gocv.IMRead("images/default.jpg", gocv.IMReadGrayScale)
|
standard := gocv.IMRead("images/default.jpg", gocv.IMReadGrayScale)
|
||||||
|
|
||||||
|
@ -66,7 +89,7 @@ func TestImages(t *testing.T) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ts, err := NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha)
|
ts, err := NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha, *log)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("could not create turbidity sensor: %v", err)
|
t.Fatalf("could not create turbidity sensor: %v", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue