Fixed range issues with gocv

This commit is contained in:
Russell Stanley 2022-01-05 14:14:22 +10:30 committed by Saxon Nelson-Milton
parent b97cc3c8c7
commit 808f0f662e
3 changed files with 13 additions and 9 deletions

View File

@ -1,3 +1,4 @@
//go:build !nocv
// +build !nocv
// What it does:
@ -93,8 +94,8 @@ func main() {
// now find contours
contours := gocv.FindContours(imgThresh, gocv.RetrievalExternal, gocv.ChainApproxSimple)
for _, c := range contours {
area := gocv.ContourArea(c)
for i := 0; i < contours.Size(); i++ {
area := gocv.ContourArea(contours.At(i))
if area < float64(minArea) {
continue
}
@ -104,7 +105,7 @@ func main() {
//gocv.DrawContours(&img, contours, i, statusColor, 2)
rect := gocv.BoundingRect(c)
rect := gocv.BoundingRect(contours.At(i))
gocv.Rectangle(&img, rect, color.RGBA{0, 0, 255, 0}, 1)
}

View File

@ -1,3 +1,4 @@
//go:build !nocv
// +build !nocv
/*
@ -117,9 +118,9 @@ func (m *KNN) Detect(img *gocv.Mat) bool {
// Find contours and reject ones with a small area.
var contours [][]image.Point
allContours := gocv.FindContours(imgDelta, gocv.RetrievalExternal, gocv.ChainApproxSimple)
for _, c := range allContours {
if gocv.ContourArea(c) > m.area {
contours = append(contours, c)
for i := 0; i < allContours.Size(); i++ {
if gocv.ContourArea(allContours.At(i)) > m.area {
contours = append(contours, allContours.At(i).ToPoints())
}
}

View File

@ -1,3 +1,4 @@
//go:build !nocv
// +build !nocv
/*
@ -117,9 +118,10 @@ func (m *MOG) Detect(img *gocv.Mat) bool {
// Find contours and reject ones with a small area.
var contours [][]image.Point
allContours := gocv.FindContours(imgDelta, gocv.RetrievalExternal, gocv.ChainApproxSimple)
for _, c := range allContours {
if gocv.ContourArea(c) > m.area {
contours = append(contours, c)
for i := 0; i < allContours.Size(); i++ {
if gocv.ContourArea(allContours.At(i)) > m.area {
contours = append(contours, allContours.At(i).ToPoints())
}
}