decrease template size

This commit is contained in:
Russell Stanley 2022-02-07 16:14:07 +10:30
parent 140311fec9
commit 68d4bd5593
2 changed files with 10 additions and 8 deletions

View File

@ -120,7 +120,7 @@ const (
// Turbidity sensor constants. // Turbidity sensor constants.
const ( const (
k1, k2 = 8, 8 // Block size, must be divisible by the size template with no remainder. k1, k2 = 4, 4 // Block size, must be divisible by the size template with no remainder.
filterSize = 3 // Sobel filter size. filterSize = 3 // Sobel filter size.
scale = 1.0 // Amount of scale applied to sobel filter values. scale = 1.0 // Amount of scale applied to sobel filter values.
alpha = 1.0 // Paramater for contrast equation. alpha = 1.0 // Paramater for contrast equation.
@ -148,7 +148,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/icon.jpg", gocv.IMReadGrayScale)
ts, err := turbidity.NewTurbiditySensor(template, standard, k1, k2, filterSize, scale, alpha, log) 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())
@ -161,12 +161,14 @@ func NewTurbidityProbe(log logger.Logger, delay time.Duration) (*turbidityProbe,
// scores of a video to the the turbidity probe. // scores of a video to the the turbidity probe.
func (tp *turbidityProbe) Write(p []byte) (int, error) { func (tp *turbidityProbe) Write(p []byte) (int, error) {
tp.buffer.Write(p) tp.buffer.Write(p)
select { go func() {
case <-tp.ticker.C: select {
go tp.turbidityCalculation(p) case <-tp.ticker.C:
default: tp.turbidityCalculation(p)
return len(p), nil default:
} return
}
}()
return len(p), nil return len(p), nil
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 2.2 KiB