gocv
gocv copied to clipboard
Memory leak in ORB detector
Description
I have a plain and simple implementation of ORB I got using a tutorial. When I try running this function 1000 times I see huge memory usage and it doesn't go down. I'm confident I closed all the gocv resources, I'm not passing mats between goroutines, it's just a pure function.
Steps to Reproduce
import (
"image"
"image/draw"
"gocv.io/x/gocv"
)
func convertToGray(img image.Image) (*image.Gray, error) {
bounds := img.Bounds()
gray := image.NewGray(bounds)
draw.Draw(gray, bounds, img, bounds.Min, draw.Src)
return gray, nil
}
func Process(img image.Image) (result ProcessResults, err error) {
gray, err := convertToGray(img)
if err != nil {
panic(err)
}
mat, err := gocv.ImageGrayToMatGray(gray)
if err != nil {
panic(err)
}
defer mat.Close()
orb := gocv.NewORB()
defer orb.Close()
mask := gocv.NewMat()
defer mask.Close()
keypoints, description := orb.DetectAndCompute(mat, mask)
defer description.Close()
result.Description = description.ToBytes()
result.DescCols = description.Cols()
result.DescRows = description.Rows()
result.DescType = description.Type()
result.Keypoints = keypoints
return
}
Your Environment
- Operating System and version:
5.15.143-1-MANJARO
- OpenCV version used: the one installed here
- How did you install OpenCV?
go get gocv.io/x/gocv v0.35.0
- GoCV version used: 0.35.0
- Go version: 1.19
- Did you run the
env.sh
orenv.cmd
script before trying togo run
orgo build
? Hope the docker image did