内存使用优化

This commit is contained in:
nuknal
2024-09-23 17:04:31 +08:00
parent d3cf743b71
commit 97a375996a
5 changed files with 32 additions and 5 deletions

View File

@@ -6,6 +6,7 @@ import (
"image"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/airbusgeo/godal"
@@ -88,6 +89,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio)
mat.Close()
mat = matFiltered
runtime.GC()
}
if config.GCONFIG.Radiation.SceneMomentMatching {
@@ -132,6 +134,7 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio/4)
mat.Close()
mat = matFiltered
runtime.GC()
}
if config.GCONFIG.Radiation.SceneMomentMatching {
@@ -149,6 +152,10 @@ func (r *Registrator) SubScenes() (panScenes []*Scene, mssScenes []*Scene, err e
err = fmt.Errorf("pan and mss scenes count not match")
}
// var b bytes.Buffer
// gocv.MatProfile.WriteTo(&b, 1)
// fmt.Print(b.String())
return panScenes, mssScenes, err
}
@@ -201,7 +208,7 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
// 输出 GeoJSON 数据
log.Debug(string(data))
for i, scene := range mssScenes {
for _, scene := range mssScenes {
dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "MSS")
os.MkdirAll(dir, 0755)
@@ -211,6 +218,8 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
r.SetSceneBoundary(scene)
rgbirImage, _ := r.MergeMSSToBGRNIR(scene.Mat)
defer rgbirImage.Close()
err := utils.SaveBGRToGDALGTiff(rgbirImage,
4,
scene.Meta.Corners.UpperLeft.Longitude,
@@ -219,7 +228,6 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
[]godal.ColorInterp{godal.CIBlue, godal.CIGreen, godal.CIRed, godal.CIUndefined},
scene.Tiff)
if err != nil {
log.Errorf("save mss scene %d to tiff failed: %v", i+1, err)
return err
}