Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak in ORB detector #1139

Open
danhab99 opened this issue Jan 3, 2024 · 0 comments
Open

Memory leak in ORB detector #1139

danhab99 opened this issue Jan 3, 2024 · 0 comments

Comments

@danhab99
Copy link

danhab99 commented Jan 3, 2024

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 or env.cmd script before trying to go run or go build? Hope the docker image did
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant