内存使用优化
This commit is contained in:
@@ -84,6 +84,7 @@ var procCmd = &cobra.Command{
|
|||||||
reg.SaveRegisteredMssToRaw(registerdMSSRAW)
|
reg.SaveRegisteredMssToRaw(registerdMSSRAW)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
runtime.GC()
|
||||||
panScenes, mssScenes, err := reg.SubScenes()
|
panScenes, mssScenes, err := reg.SubScenes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Error(err)
|
logrus.Error(err)
|
||||||
@@ -92,6 +93,13 @@ var procCmd = &cobra.Command{
|
|||||||
reg.SaveScenesToTiff(panScenes, mssScenes)
|
reg.SaveScenesToTiff(panScenes, mssScenes)
|
||||||
producer.CleanScenes(panScenes)
|
producer.CleanScenes(panScenes)
|
||||||
producer.CleanScenes(mssScenes)
|
producer.CleanScenes(mssScenes)
|
||||||
|
|
||||||
|
// err := reg.SubScenesLessMem()
|
||||||
|
// if err != nil {
|
||||||
|
// logrus.Error(err)
|
||||||
|
// return
|
||||||
|
// }
|
||||||
|
|
||||||
runtime.GC()
|
runtime.GC()
|
||||||
|
|
||||||
if saveStrip {
|
if saveStrip {
|
||||||
|
|||||||
@@ -245,8 +245,6 @@ func PansharpenIHS(pan, B, G, R, I gocv.Mat, w float32) gocv.Mat {
|
|||||||
|
|
||||||
// 将图像从 HLS 转换回 BGR
|
// 将图像从 HLS 转换回 BGR
|
||||||
fusedImage := gocv.NewMat()
|
fusedImage := gocv.NewMat()
|
||||||
|
|
||||||
log.Println("cvt color from HLS to BGR")
|
|
||||||
gocv.CvtColor(mssHLS, &fusedImage, gocv.ColorHLSToBGR)
|
gocv.CvtColor(mssHLS, &fusedImage, gocv.ColorHLSToBGR)
|
||||||
|
|
||||||
channels := gocv.Split(fusedImage)
|
channels := gocv.Split(fusedImage)
|
||||||
|
|||||||
@@ -161,6 +161,7 @@ func (r *Registrator) CalcDownPhaseCorrelation() error {
|
|||||||
|
|
||||||
// 将PAN将采样作为轮廓匹配基准图像
|
// 将PAN将采样作为轮廓匹配基准图像
|
||||||
downsampledPanImage := gocv.NewMat()
|
downsampledPanImage := gocv.NewMat()
|
||||||
|
defer downsampledPanImage.Close()
|
||||||
gocv.Resize(r.PanImage, &downsampledPanImage,
|
gocv.Resize(r.PanImage, &downsampledPanImage,
|
||||||
image.Point{X: r.MssWidth, Y: r.MssHeight}, 0, 0, gocv.InterpolationCubic)
|
image.Point{X: r.MssWidth, Y: r.MssHeight}, 0, 0, gocv.InterpolationCubic)
|
||||||
log.Println("down sampled PAN images size:", downsampledPanImage.Size())
|
log.Println("down sampled PAN images size:", downsampledPanImage.Size())
|
||||||
@@ -385,6 +386,9 @@ func (r *Registrator) DoCoRegistration() error {
|
|||||||
gocv.InterpolationCubic,
|
gocv.InterpolationCubic,
|
||||||
gocv.BorderConstant,
|
gocv.BorderConstant,
|
||||||
color.RGBA{0, 0, 0, 0})
|
color.RGBA{0, 0, 0, 0})
|
||||||
|
|
||||||
|
mapX.Close()
|
||||||
|
mapY.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
// 裁掉末尾的的 MSS 480 行 和 PAN 的 480*4 行
|
// 裁掉末尾的的 MSS 480 行 和 PAN 的 480*4 行
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"image"
|
"image"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/airbusgeo/godal"
|
"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)
|
matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio)
|
||||||
mat.Close()
|
mat.Close()
|
||||||
mat = matFiltered
|
mat = matFiltered
|
||||||
|
runtime.GC()
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.GCONFIG.Radiation.SceneMomentMatching {
|
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)
|
matFiltered := rrc.HFNoiseFilter(mat, float64(mat.Cols())*config.GCONFIG.Radiation.HfRadiusRatio/4)
|
||||||
mat.Close()
|
mat.Close()
|
||||||
mat = matFiltered
|
mat = matFiltered
|
||||||
|
runtime.GC()
|
||||||
}
|
}
|
||||||
|
|
||||||
if config.GCONFIG.Radiation.SceneMomentMatching {
|
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")
|
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
|
return panScenes, mssScenes, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +208,7 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
|
|||||||
// 输出 GeoJSON 数据
|
// 输出 GeoJSON 数据
|
||||||
log.Debug(string(data))
|
log.Debug(string(data))
|
||||||
|
|
||||||
for i, scene := range mssScenes {
|
for _, scene := range mssScenes {
|
||||||
dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "MSS")
|
dir := filepath.Join(r.Params.OutputDir, scene.SceneIndex, "MSS")
|
||||||
os.MkdirAll(dir, 0755)
|
os.MkdirAll(dir, 0755)
|
||||||
|
|
||||||
@@ -211,6 +218,8 @@ func (r *Registrator) SaveScenesToTiff(panScenes []*Scene, mssScenes []*Scene) e
|
|||||||
r.SetSceneBoundary(scene)
|
r.SetSceneBoundary(scene)
|
||||||
|
|
||||||
rgbirImage, _ := r.MergeMSSToBGRNIR(scene.Mat)
|
rgbirImage, _ := r.MergeMSSToBGRNIR(scene.Mat)
|
||||||
|
defer rgbirImage.Close()
|
||||||
|
|
||||||
err := utils.SaveBGRToGDALGTiff(rgbirImage,
|
err := utils.SaveBGRToGDALGTiff(rgbirImage,
|
||||||
4,
|
4,
|
||||||
scene.Meta.Corners.UpperLeft.Longitude,
|
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},
|
[]godal.ColorInterp{godal.CIBlue, godal.CIGreen, godal.CIRed, godal.CIUndefined},
|
||||||
scene.Tiff)
|
scene.Tiff)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Errorf("save mss scene %d to tiff failed: %v", i+1, err)
|
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -32,7 +32,9 @@ func HFNoiseFilter(img gocv.Mat, radius float64) gocv.Mat {
|
|||||||
// 执行 DFT
|
// 执行 DFT
|
||||||
DFT := gocv.NewMat()
|
DFT := gocv.NewMat()
|
||||||
defer DFT.Close()
|
defer DFT.Close()
|
||||||
gocv.Merge([]gocv.Mat{img32f, gocv.Zeros(rows, cols, gocv.MatTypeCV32F)}, &DFT)
|
zero := gocv.Zeros(rows, cols, gocv.MatTypeCV32F)
|
||||||
|
defer zero.Close()
|
||||||
|
gocv.Merge([]gocv.Mat{img32f, zero}, &DFT)
|
||||||
gocv.DFT(DFT, &DFT, gocv.DftComplexOutput)
|
gocv.DFT(DFT, &DFT, gocv.DftComplexOutput)
|
||||||
|
|
||||||
// 中心化频谱
|
// 中心化频谱
|
||||||
@@ -126,6 +128,8 @@ func fftshift(input *gocv.Mat) {
|
|||||||
q3 := input.Region(image.Rect(cx, cy, input.Cols(), input.Rows())) // Bottom-Right
|
q3 := input.Region(image.Rect(cx, cy, input.Cols(), input.Rows())) // Bottom-Right
|
||||||
|
|
||||||
tmp := gocv.NewMatWithSize(q0.Rows(), q0.Cols(), input.Type())
|
tmp := gocv.NewMatWithSize(q0.Rows(), q0.Cols(), input.Type())
|
||||||
|
defer tmp.Close()
|
||||||
|
|
||||||
q0.CopyTo(&tmp)
|
q0.CopyTo(&tmp)
|
||||||
q3.CopyTo(&q0)
|
q3.CopyTo(&q0)
|
||||||
tmp.CopyTo(&q3)
|
tmp.CopyTo(&q3)
|
||||||
@@ -133,6 +137,11 @@ func fftshift(input *gocv.Mat) {
|
|||||||
q1.CopyTo(&tmp)
|
q1.CopyTo(&tmp)
|
||||||
q2.CopyTo(&q1)
|
q2.CopyTo(&q1)
|
||||||
tmp.CopyTo(&q2)
|
tmp.CopyTo(&q2)
|
||||||
|
|
||||||
|
q0.Close()
|
||||||
|
q1.Close()
|
||||||
|
q2.Close()
|
||||||
|
q3.Close()
|
||||||
}
|
}
|
||||||
|
|
||||||
func visualizeDFT(DFT gocv.Mat, file string) {
|
func visualizeDFT(DFT gocv.Mat, file string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user