close unused gocv.Mat
This commit is contained in:
parent
879172a507
commit
a0cd182de9
|
@ -149,6 +149,7 @@ func (sys *TextPredictSystem) getRotateCropImage(img gocv.Mat, box [][]int) gocv
|
|||
|
||||
func (sys *TextPredictSystem) Run(img gocv.Mat) []OCRText {
|
||||
srcimg := gocv.NewMat()
|
||||
defer srcimg.Close()
|
||||
img.CopyTo(&srcimg)
|
||||
boxes := sys.detector.Run(img)
|
||||
if len(boxes) == 0 {
|
||||
|
@ -224,6 +225,7 @@ func (ocr *OCRSystem) predictHandler(w http.ResponseWriter, r *http.Request) {
|
|||
|
||||
io.Copy(&buf, file)
|
||||
img, err2 := gocv.IMDecode(buf.Bytes(), gocv.IMReadColor)
|
||||
defer img.Close()
|
||||
if err2 != nil {
|
||||
w.Write([]byte(err2.Error()))
|
||||
return
|
||||
|
@ -252,6 +254,7 @@ func (ocr *OCRSystem) PredictDirImages(dirname string) map[string][]OCRText {
|
|||
for i := 0; i < len(imgs); i++ {
|
||||
imgname := imgs[i]
|
||||
img := ReadImage(imgname)
|
||||
defer img.Close()
|
||||
res := ocr.PredictOneImage(img)
|
||||
results[imgname] = res
|
||||
}
|
||||
|
|
|
@ -24,7 +24,8 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
|
|||
shapes[i] = s.(int)
|
||||
}
|
||||
}
|
||||
labelpath := getString(args, "rec_char_dict_path", "./config/ppocr_keys_v1.txt")
|
||||
home, _ := os.UserHomeDir()
|
||||
labelpath := getString(args, "rec_char_dict_path", home+"/.paddleocr/rec/ppocr_keys_v1.txt")
|
||||
labels := readLines2StringSlice(labelpath)
|
||||
if getBool(args, "use_space_char", true) {
|
||||
labels = append(labels, " ")
|
||||
|
@ -38,7 +39,6 @@ func NewTextRecognizer(modelDir string, args map[string]interface{}) *TextRecogn
|
|||
labels: labels,
|
||||
}
|
||||
if checkModelExists(modelDir) {
|
||||
home, _ := os.UserHomeDir()
|
||||
modelDir, _ = downloadModel(home+"/.paddleocr/rec/ch", modelDir)
|
||||
} else {
|
||||
log.Panicf("rec model path: %v not exist! Please check!", modelDir)
|
||||
|
@ -75,6 +75,7 @@ func (rec *TextRecognizer) Run(imgs []gocv.Mat, bboxes [][][]int) []OCRText {
|
|||
for k := i; k < j; k++ {
|
||||
data := crnnPreprocess(imgs[k], rec.shape, []float32{0.5, 0.5, 0.5},
|
||||
[]float32{0.5, 0.5, 0.5}, 255.0, maxwhratio, rec.charType)
|
||||
defer imgs[k].Close()
|
||||
copy(normimgs[(k-i)*c*h*w:], data)
|
||||
}
|
||||
|
||||
|
|
|
@ -92,6 +92,7 @@ func (d *DBPostProcess) boxScoreFast(array [][]float32, pred gocv.Mat) float64 {
|
|||
ymax := clip(int(math.Ceil(float64(maxf(boxY)))), 0, height-1)
|
||||
|
||||
mask := gocv.NewMatWithSize(ymax-ymin+1, xmax-xmin+1, gocv.MatTypeCV8UC1)
|
||||
defer mask.Close()
|
||||
ppt := make([][]image.Point, 1)
|
||||
ppt[0] = make([]image.Point, 4)
|
||||
ppt[0][0] = image.Point{int(array[0][0]) - xmin, int(array[0][1]) - ymin}
|
||||
|
|
|
@ -59,7 +59,6 @@ func resizeByMaxLen(img gocv.Mat, maxLen int) (gocv.Mat, int, int) {
|
|||
func normPermute(img gocv.Mat, mean []float32, std []float32, scaleFactor float32) []float32 {
|
||||
img.ConvertTo(&img, gocv.MatTypeCV32F)
|
||||
img.DivideFloat(scaleFactor)
|
||||
defer img.Close()
|
||||
|
||||
c := gocv.Split(img)
|
||||
data := make([]float32, img.Rows()*img.Cols()*img.Channels())
|
||||
|
@ -154,7 +153,6 @@ func crnnPreprocess(img gocv.Mat, resizeShape []int, mean []float32, std []float
|
|||
img.DivideFloat(scaleFactor)
|
||||
img.SubtractScalar(gocv.NewScalar(float64(mean[0]), float64(mean[1]), float64(mean[2]), 0))
|
||||
img.DivideScalar(gocv.NewScalar(float64(std[0]), float64(std[1]), float64(std[2]), 0))
|
||||
defer img.Close()
|
||||
|
||||
if resizeW < imgW {
|
||||
gocv.CopyMakeBorder(img, &img, 0, 0, 0, imgW-resizeW, gocv.BorderConstant, color.RGBA{0, 0, 0, 0})
|
||||
|
|
Loading…
Reference in New Issue