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.
|
||||
standard := 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 {
|
||||
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))
|
||||
|
||||
// Process video data to get saturation and contrast scores.
|
||||
startTime := time.Now()
|
||||
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 {
|
||||
tp.log.Error("evaluate failed", "error", err.Error())
|
||||
return len(p), err
|
||||
|
@ -242,7 +243,7 @@ func main() {
|
|||
rv *revid.Revid
|
||||
p *turbidityProbe
|
||||
)
|
||||
p, err := NewTurbidityProbe(*log, 120*time.Second)
|
||||
p, err := NewTurbidityProbe(*log, 60*time.Second)
|
||||
|
||||
log.Log(logger.Debug, "initialising netsender client")
|
||||
ns, err := netsender.New(log, nil, readPin(p, rv, log), nil, createVarMap())
|
||||
|
|
|
@ -35,7 +35,9 @@ import (
|
|||
"fmt"
|
||||
"image"
|
||||
"math"
|
||||
"time"
|
||||
|
||||
"bitbucket.org/ausocean/utils/logger"
|
||||
"gocv.io/x/gocv"
|
||||
)
|
||||
|
||||
|
@ -46,10 +48,11 @@ type TurbiditySensor struct {
|
|||
standard, standardCorners gocv.Mat
|
||||
k1, k2, sobelFilterSize int
|
||||
scale, alpha float64
|
||||
logger logger.Logger
|
||||
}
|
||||
|
||||
// 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)
|
||||
templateCorners := 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.alpha, ts.scale = alpha, scale
|
||||
ts.logger = logger
|
||||
return ts, nil
|
||||
}
|
||||
|
||||
|
@ -87,16 +91,24 @@ func (ts TurbiditySensor) Evaluate(imgs []gocv.Mat) (*Results, error) {
|
|||
}
|
||||
|
||||
for i := range imgs {
|
||||
timer := time.Now()
|
||||
marker, err := ts.transform(imgs[i])
|
||||
if err != nil {
|
||||
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)
|
||||
if err != nil {
|
||||
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)
|
||||
}
|
||||
return result, nil
|
||||
|
|
|
@ -30,12 +30,15 @@ package turbidity
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"testing"
|
||||
|
||||
"bitbucket.org/ausocean/utils/logger"
|
||||
"gocv.io/x/gocv"
|
||||
"gonum.org/v1/gonum/stat"
|
||||
"gonum.org/v1/plot"
|
||||
"gonum.org/v1/plot/plotutil"
|
||||
"gopkg.in/natefinch/lumberjack.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -44,15 +47,35 @@ const (
|
|||
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.
|
||||
// A plot of the results will be generated and stored in the plots directory.
|
||||
func TestImages(t *testing.T) {
|
||||
|
||||
const (
|
||||
k1, k2 = 8, 8
|
||||
filterSize = 3
|
||||
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)
|
||||
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 {
|
||||
t.Fatalf("could not create turbidity sensor: %v", err)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue