From 19166db5b951bbd373fdcfb684f5c44e81b68b77 Mon Sep 17 00:00:00 2001 From: Emerald Date: Tue, 23 Jul 2024 09:57:20 -0400 Subject: [PATCH] linting failed --- go.mod | 5 +- go.sum | 12 --- oceanprefilter/histogram_compare.go | 155 ---------------------------- 3 files changed, 2 insertions(+), 170 deletions(-) delete mode 100644 oceanprefilter/histogram_compare.go diff --git a/go.mod b/go.mod index 36fdc78..5f54ea3 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ toolchain go1.21.12 require ( github.com/Elvenson/xgboost-go v0.1.4 - github.com/nfnt/resize v0.0.0-20180221191011-83c6a9932646 + github.com/disintegration/imaging v1.6.2 github.com/pkg/errors v0.9.1 go.viam.com/rdk v0.28.0 go.viam.com/test v1.1.1-0.20220913152726-5da9916c08a2 @@ -37,7 +37,6 @@ require ( github.com/davecgh/go-spew v1.1.1 // indirect github.com/decred/dcrd/dcrec/secp256k1/v4 v4.2.0 // indirect github.com/desertbit/timer v0.0.0-20180107155436-c41aec40b27f // indirect - github.com/disintegration/imaging v1.6.2 // indirect github.com/docker/go-units v0.5.0 // indirect github.com/edaniels/golog v0.0.0-20230215213219-28954395e8d0 // indirect github.com/edaniels/lidario v0.0.0-20220607182921-5879aa7b96dd // indirect @@ -62,7 +61,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/gonuts/binary v0.2.0 // indirect github.com/google/flatbuffers v2.0.8+incompatible // indirect - github.com/google/go-cmp v0.5.9 // indirect + github.com/google/go-cmp v0.6.0 // indirect github.com/google/s2a-go v0.1.4 // indirect github.com/google/uuid v1.6.0 // indirect github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect diff --git a/go.sum b/go.sum index bf1ac6d..c8c5a0f 100644 --- a/go.sum +++ b/go.sum @@ -434,8 +434,6 @@ github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.4/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= -github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= @@ -1180,8 +1178,6 @@ golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8/go.mod h1:FeLwcggjj3mMvU+o golang.org/x/image v0.0.0-20200927104501-e162460cd6b5/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0= golang.org/x/image v0.0.0-20210607152325-775e3b0c77b9/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= golang.org/x/image v0.0.0-20211028202545-6944b10bf410/go.mod h1:023OzeP/+EPmXeapQh35lcL3II3LrY8Ic+EFFKVhULM= -golang.org/x/image v0.15.0 h1:kOELfmgrmJlw4Cdb7g/QGuB3CvDrXbqEIww/pNtNBm8= -golang.org/x/image v0.15.0/go.mod h1:HUYqC05R2ZcZ3ejNQsIHQDQiwWM4JBqmm6MKANTp4LE= golang.org/x/image v0.18.0 h1:jGzIakQa/ZXI1I0Fxvaa9W7yP25TqT6cHIHn+6CqvSQ= golang.org/x/image v0.18.0/go.mod h1:4yyo5vMFQjVjUcVk4jEQcU9MGy/rulF5WvUILseCM2E= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= @@ -1207,8 +1203,6 @@ golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= -golang.org/x/mod v0.14.0 h1:dGoOF9QVLYng8IHTm7BAyWqCqSheQ5pYWGhzW00YJr0= -golang.org/x/mod v0.14.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/mod v0.17.0 h1:zY54UmvipHiNd+pm+m0x9KhZ9hl1/7QNMyxXbc6ICqA= golang.org/x/mod v0.17.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= @@ -1287,8 +1281,6 @@ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180823144017-11551d06cbcc/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -1398,8 +1390,6 @@ golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/text v0.15.0 h1:h1V/4gjBv8v9cjcR6+AR5+/cIYK5N/WAgiv4xlsEtAk= -golang.org/x/text v0.15.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/text v0.16.0 h1:a94ExnEXNtEwYLGJSIUxnWoxoRz/ZcCsV63ROupILh4= golang.org/x/text v0.16.0/go.mod h1:GhwF1Be+LQoKShO3cGOHzqOgRrGaYc9AvblQOmPVHnI= golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -1504,8 +1494,6 @@ golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0= golang.org/x/tools v0.1.5/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= -golang.org/x/tools v0.17.0 h1:FvmRgNOcs3kOa+T20R1uhfP9F6HgG2mfxDv1vrx1Htc= -golang.org/x/tools v0.17.0/go.mod h1:xsh6VxdV005rRVaS6SSAf9oiAqljS7UZUacMZ8Bnsps= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d h1:vU5i/LfpvrRCpgM/VPfJLg5KjxD3E+hfT1SH+d9zLwg= golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d/go.mod h1:aiJjzUbINMkxbQROHiO6hDPo2LHcIPhhQsa9DLh0yGk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= diff --git a/oceanprefilter/histogram_compare.go b/oceanprefilter/histogram_compare.go deleted file mode 100644 index 7aedb94..0000000 --- a/oceanprefilter/histogram_compare.go +++ /dev/null @@ -1,155 +0,0 @@ -package oceanprefilter - -import ( - "fmt" - "image" - "math" - - "github.com/pkg/errors" -) - -const NVSplit = 4 -const NHSplit = 4 - -type Bucket struct { - Count int -} - -type Histogram struct { - Count int - Buckets []Bucket - spacing float64 -} - -func Hist(buckets int, minVal, maxVal float64, input []float64) Histogram { - // make evenly spaced buckets between min and max - // values outside of min and max are discarded - space := (maxVal - minVal) / float64(buckets) - bkts := make([]Bucket, buckets) - hist := Histogram{ - Count: 0, - Buckets: bkts, - spacing: space, - } - for _, val := range input { - if val >= maxVal || val < minVal { // skip over out of range values - continue - } - bucketIndex := int((val - minVal) / space) - if bucketIndex < 0 || bucketIndex > len(hist.Buckets)-1 { - panic(fmt.Sprintf("value of %v out of range between (%v, %v)", val, maxVal, minVal)) - } - hist.Count++ - hist.Buckets[bucketIndex].Count++ - } - return hist -} - -func histogramChangeFilter( - oldHists []Histogram, newImg image.Image, rc runConfig, -) (bool, []Histogram, error) { - firstHist := false - thresh := rc.threshold - if len(oldHists) == 0 { - firstHist = true // get the data for the first histogram - } - // find the horizon, take the average y value - linePoints, err := findHorizonLine(newImg) - if err != nil { - return false, nil, err - } - if len(linePoints) < 2 { - return false, nil, errors.New("function to find the horizon line returned less than 2 points") - } - cropY := int(math.Max(float64(linePoints[0].Y), float64(linePoints[1].Y))) - if rc.debug { - rc.logger.Debugf("found horizon at y = %v", cropY) - } - if cropY >= (newImg.Bounds().Max.Y-1) || cropY <= 1 { - return false, nil, errors.Errorf("could not find horizon in image. Got a horizon value of y = %v", cropY) - } - imgs, err := splitUpImage(newImg, rc.excludedZone, cropY, NHSplit, NVSplit) - if err != nil { - return false, nil, err - } - newHists := []Histogram{} // a histogram for each RGB channel - trigger := false - if !firstHist && len(imgs) != len(oldHists) { - return false, nil, errors.New("image changed drastically, cannot evaluate histogram difference. Can be caused by large amounts of motion") - } - for i, img := range imgs { - resultHists := createGrayHistograms(img) - for j, h := range resultHists { - newHist := h - splitTrigger := false - if !firstHist { - oldHist := oldHists[i*len(resultHists)+j] - if len(oldHist.Buckets) != len(newHist.Buckets) { - return false, nil, errors.Errorf("hists should have same number of buckets, old hist: %v, new hist: %v", len(oldHist.Buckets), len(newHist.Buckets)) - } - splitTrigger = histogramTrigger(oldHist, newHist, thresh) - } - newHists = append(newHists, newHist) - if splitTrigger { - trigger = true - } - } - } - return trigger, newHists, nil -} - -// take in an old image histogram, a new image, and return a trigger bool and the new image histogram -// returns a bool based on the thresh value -func histogramTrigger(oldHist, newHist Histogram, thresh float64) bool { - //result := basicCompare(oldHist, newHist) - ecdf1 := histogramToECDF(oldHist) - ecdf2 := histogramToECDF(newHist) - result := kolmogorovSmirnovTest(ecdf1, ecdf2) - trigger := false - if result >= thresh { - trigger = true - } - return trigger -} - -func createGrayHistograms(pic image.Image) []Histogram { - hists := make([]Histogram, 0, 1) - img := toGray(pic) - pix := []float64{} - for x := 0; x < img.Bounds().Dx(); x++ { - for y := 0; y < img.Bounds().Dy(); y++ { - c := img.GrayAt(x, y) - pix = append(pix, float64(c.Y)) - } - } - hists = append(hists, Hist(32, 0, 256, pix)) // 32 bin, 8 values in each bin in 255 total - return hists -} - -// histogramToECDF converts a histogram to an empirical cumulative distribution function (ECDF) -// Assumes histogram bins are evenly distributed over the data range -func histogramToECDF(hist Histogram) []float64 { - total := float64(hist.Count) - ecdf := make([]float64, len(hist.Buckets)) - cumulativeCount := 0.0 - if total == 0 { - return ecdf - } - for i, bkt := range hist.Buckets { - cumulativeCount += float64(bkt.Count) - ecdf[i] = cumulativeCount / total - } - return ecdf -} - -// kolmogorovSmirnovTest computes the Kolmogorov-Smirnov statistic for two ECDFs -func kolmogorovSmirnovTest(ecdf1, ecdf2 []float64) float64 { - maxDiff := 0.0 - for i := range ecdf1 { - diff := math.Abs(ecdf1[i] - ecdf2[i]) - if diff > maxDiff { - maxDiff = diff - } - } - return maxDiff -}