You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In this issue, it is reported that there is a severe memory leak during the conversion between image.Image and gocv.Mat types, specifically when these conversions are done within a goroutine pool. Despite the fact that all the images are reported as Empty, a significant amount
Steps to Reproduce
package main
import (
"fmt""image""time""github.com/panjf2000/ants""gocv.io/x/gocv"
)
// MatToMat converts a gocv.Mat to another gocv.Mat through an image representation funcMatToMat(mat gocv.Mat) gocv.Mat {
// Convert gocv.Mat to image.Image img, _:=mat.ToImage()
// Convert image.Image back to gocv.Mat (RGB format) reImg, _:=gocv.ImageToMatRGB(img)
// Ensure the new gocv.Mat is closed to prevent memory leaks deferreImg.Close()
returnreImg
}
// ImgToImg converts an image.Image to another image.Image through a gocv.Mat representation funcImgToImg(img image.Image) image.Image {
// Convert image.Image to gocv.Mat (RGB format) mat, _:=gocv.ImageToMatRGB(img)
// Convert gocv.Mat back to image.Image reImg, _:=mat.ToImage()
returnreImg
}
// imgInfo holds an image's gocv.Mat representation and its name typeimgInfostruct {
img gocv.Matnamestring
}
// sendGocv is a channel used to send imgInfo instances varsendGocv=make(chanimgInfo)
// imgdict is a map that stores imgInfo instances varimgdict=make(map[string]gocv.Mat)
// poolWait waits for all images to be processed and stored in imgdict funcpoolWait(countint) {
for {
select {
caseimginfo:=<-sendGocv:
imgdict[imginfo.name] =imginfo.imgcount--// fmt.Println("Remaining", count, "Processed", len(imgdict)) ifcount==0 {
return
}
}
}
}
// createAndRunPool creates a goroutine pool to run a specified task multiple times funccreateAndRunPool(count, poolSizeint, taskfunc(textstring)) {
p, err:=ants.NewPool(poolSize)
iferr!=nil {
panic(err)
}
deferp.Release()
gofunc() {
fori:=0; i<count; i++ {
err=p.Submit(func() {
msg:=fmt.Sprintf("%d", i)
task(msg)
})
iferr!=nil {
panic(err)
}
}
}()
poolWait(count)
}
funcmain() {
file:="./any_png.png"runCount:=100mat:=gocv.IMRead(file, gocv.IMReadUnchanged)
fmt.Println("first")
createAndRunPool(runCount, 20, func(textstring) {
newMat:=MatToMat(mat)
sendGocv<-imgInfo{newMat, text}
})
fmt.Println("end")
time.Sleep(5*time.Second)
fmt.Println("Second round")
createAndRunPool(runCount, 20, func(textstring) {
newMat:=MatToMat(mat)
sendGocv<-imgInfo{newMat, text}
})
fmt.Println("End")
time.Sleep(5*time.Second)
for_, ig:=rangeimgdict {
ifig.Empty() {
fmt.Println("Empty!")
}
}
}
Your Environment
Operating System and version: Linux 5.4.0-126-generic Feature/mat pointer #142-Ubuntu SMP Fri Aug 26 12:12:57 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux
OpenCV version used: 4.8.1
How did you install OpenCV? make build
GoCV version used: v0.35.0
Go version: 1.22.1
Did you run the env.sh or env.cmd script before trying to go run or go build?
If my usage method is incorrect, please tell me the correct usage. Thank you
The text was updated successfully, but these errors were encountered:
Description
In this issue, it is reported that there is a severe memory leak during the conversion between image.Image and gocv.Mat types, specifically when these conversions are done within a goroutine pool. Despite the fact that all the images are reported as Empty, a significant amount
Steps to Reproduce
Your Environment
env.sh
orenv.cmd
script before trying togo run
orgo build
?If my usage method is incorrect, please tell me the correct usage. Thank you
The text was updated successfully, but these errors were encountered: