Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# EmguCV.缝合类内存泄漏_C#_Memory Leaks_Emgucv_Image Stitching_Memory Consumption - Fatal编程技术网

C# EmguCV.缝合类内存泄漏

C# EmguCV.缝合类内存泄漏,c#,memory-leaks,emgucv,image-stitching,memory-consumption,C#,Memory Leaks,Emgucv,Image Stitching,Memory Consumption,我目前正在编写一个程序,用于使用EmguCV缝合图像。我使用Emgu.CV.Stiching类作为缝合算法,尽管我试图正确地配置资源,但根据我使用的图像的数量和大小,我会出现巨大的内存泄漏 下面是我的代码的一个最小的可复制示例 using System; using System.IO; using Emgu.CV; using Emgu.CV.Structure; using Emgu.CV.Stitching; using Emgu.CV.Util; using Emgu.CV.Featu

我目前正在编写一个程序,用于使用EmguCV缝合图像。我使用Emgu.CV.Stiching类作为缝合算法,尽管我试图正确地配置资源,但根据我使用的图像的数量和大小,我会出现巨大的内存泄漏

下面是我的代码的一个最小的可复制示例

using System;
using System.IO;

using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.CV.Stitching;
using Emgu.CV.Util;
using Emgu.CV.Features2D;
using Emgu.CV.CvEnum;

namespace Example
{
    class Program
    {
        static void Main(string[] args)
        {
            string folderPath = @"e:\Users\Dennis\Desktop\Stitching\ExampleImages2";       //Paste your the path of your folder, which contains the images, here       
            string format = ".jpg";
            string[] filePaths = Directory.GetFiles(folderPath, ("*" + format));
            string storagePath;

            Directory.CreateDirectory(folderPath + @"\Stitched");                                               //creates new Directionary if not exist
            int num = 1;                                                                                        //Sets file numbering
            while (true)                                                                                        //Checks if there is already an exisitng file with that name and change numbering "num" if "true"
            {
                storagePath = folderPath + @"\Stitched" + @"\result_" + num + format;

                if (!File.Exists(storagePath))
                    break;
                num++;
            }



            //Image Stitching

            Stitcher.Mode mode = Stitcher.Mode.Scans;
            float threshhold = 0.0001f;
            Mat result = new Mat();

            using (Stitcher stitcher = new Stitcher(mode))                                                  //Creates a Stitcher configured with one of the stitching modes
            using (AKAZE detector = new AKAZE(AKAZE.DescriptorType.Mldb, 0, 3, threshhold))                 //Creates a Feature Detector with a user-chosen threshhold
            using (VectorOfMat input = new VectorOfMat())
            {
                stitcher.SetFeaturesFinder(detector);

                Mat[] images = new Mat[filePaths.Length];

                for (int i = 0; i < filePaths.Length; i++)
                {
                    images[i] = CvInvoke.Imread(filePaths[i], ImreadModes.AnyColor);
                }

                input.Push(images);

                for (int i = 0; i < filePaths.Length; i++)
                {
                    images[i].Dispose();
                }

                stitcher.Stitch(input, result);

            }

            using (Image<Bgr, Byte> resImage = result.ToImage<Bgr, Byte>())
            {
                resImage.Save(storagePath);
            }

            result.Dispose();


            Console.ReadKey();              //I included this, so the program wont stop and you can see, how the memory consumption graph is not falling
        }

    }
}
使用系统;
使用System.IO;
使用Emgu.CV;
使用Emgu.CV.Structure;
使用Emgu.CV.缝合;
使用Emgu.CV.Util;
使用Emgu.CV.Features2D;
使用Emgu.CV.CvEnum;
名称空间示例
{
班级计划
{
静态void Main(字符串[]参数)
{
string folderPath=@“e:\Users\Dennis\Desktop\Stitching\ExampleMages2”;//在此处粘贴包含图像的文件夹路径
字符串格式=“.jpg”;
字符串[]filepath=Directory.GetFiles(folderPath,(“*”+格式));
字符串存储路径;
Directory.CreateDirectory(folderPath+@“\Stitched”);//如果不存在,则创建新的目录
int num=1;//设置文件编号
while(true)//检查是否已经存在具有该名称的现有文件,如果“true”,则更改编号“num”
{
storagePath=folderPath++“\Stitched++@”\result++num+格式;
如果(!File.Exists(storagePath))
打破
num++;
}
//图像拼接
缝合器模式=缝合器模式扫描;
浮动阈值=0.0001f;
Mat结果=新Mat();
使用(缝合器缝合器=新缝合器(模式))//创建使用其中一种缝合模式配置的缝合器
使用(AKAZE-detector=new-AKAZE(AKAZE.DescriptorType.Mldb,0,3,threshold))//使用用户选择的threshold创建特征检测器
使用(VectorOfMat输入=新VectorOfMat())
{
缝合器设置特征指示器(检测器);
Mat[]images=new Mat[filepath.Length];
for(int i=0;i
我正在使用VS 2015和EmguCV版本4.1.0.3420并运行调试版本

她是一个示例图像,因此您可以重现问题:


只需将图像放入文件夹并将folderPath粘贴到预期的代码行中。您可以使用NuGet安装我在代码中使用的EmguCV版本。

如果您使用
Release
而不是
Debug
build,内存状况是否有所改善?不,使用Release显示托管内存使用量小于1MB时,我会得到几乎相同的图形-几乎所有内存使用量都是非托管的。我想你需要直接在上提出一个问题。好的,我现在已经在github上发布了这个问题,希望这个问题能很快解决。然而,非常感谢你的努力:)祝你有一个愉快的一天!如果使用
Release
而不是
Debug
build,内存状况是否有所改善?不,我在使用Release时得到的图表几乎相同,显示托管内存使用量小于1MB—实际上所有内存使用量都是非托管的。我想你需要直接在上提出一个问题。好的,我现在已经在github上发布了这个问题,希望这个问题能很快解决。然而,非常感谢你的努力:)祝你有一个愉快的一天!