gocv
gocv copied to clipboard
memory leak on openwrt
memory leak on openwrt
Description
using the follow source to get thumb, but the process holds large memory and not release until killed by system.
source
`package imager
import ( "errors" "fmt" "image"
"gocv.io/x/gocv"
)
// Size return width height func size(img *gocv.Mat) (int, int) { return img.Cols(), img.Rows() }
// GoCvResizeRatio resize by Ratio using gocv func GoCvResizeRatio(srcpath, dstpath string, width, height int) error { src := gocv.IMRead(srcpath, gocv.IMReadColor) if src.Empty() { fmt.Println("Invalid read of Mat in Resize test") return errors.New("img IMRead empty") } defer src.Close()
fScale := 1.0
srcwidth, wrcheight := size(&src)
scaleWidth := (float64(width) / float64(srcwidth))
scaleHeight := (float64(height) / float64(wrcheight))
fmt.Println("scale width:", scaleWidth, " height:", scaleHeight)
if width > 0 && height > 0 {
if scaleWidth > scaleHeight {
fScale = scaleHeight
} else {
fScale = scaleWidth
}
} else if width > 0 {
fScale = scaleWidth
} else if height > 0 {
fScale = scaleHeight
}
dst := gocv.NewMat()
defer dst.Close()
gocv.Resize(src, &dst, image.Point{}, fScale, fScale, gocv.InterpolationDefault)
if dst.Empty() {
fmt.Println("img resize empty")
return errors.New("img Resize empty")
}
if !gocv.IMWrite(dstpath, dst) {
fmt.Println("img IMWrite error")
return errors.New("img IMWrite empty")
}
return nil
} `
Your Environment
- Operating System and version: OpenWrt 18.06-SNAPSHOT
- OpenCV version used: v4.2.0
- How did you install OpenCV? using
- GoCV version used: v0.22.0
- Go version: go version go1.13.5 linux/amd64
- build configure: export CGO_CPPFLAGS="-I/opt/toolchain-aarch64_cortex-a53_gcc-8.2.0_glibc/usr/include" export CGO_LDFLAGS="-L/opt/toolchain-aarch64_cortex-a53_gcc-8.2.0_glibc/usr/lib -lopencv_calib3d -lopencv_core -lopencv_face -lopencv_videoio -lopencv_imgproc -lopencv_highgui -lopencv_imgcodecs -lopencv_objdetect -lopencv_features2d -lopencv_video -lopencv_dnn -lopencv_xfeatures2d"