Accord.NET比较两个图像以确定相似性 [英] Accord.NET Comparing two images to determine similarity

查看:630
本文介绍了Accord.NET比较两个图像以确定相似性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于您的代码为什么变得无法响应以及如何解决它,我希望您能提出建议。

I would like your advice as to why the code might be becoming unresponsive and how to fix it.

我正在使用Accord.NET来比较图像。我的项目的第一步是比较两个图像,即观察到的图像和模型图像,并确定它们的相似程度。第二,是将观察到的图像与我的整个数据库进行比较,以根据模型的分类方式确定观察到的图像最有可能的原因。现在,我专注于第一个。我最初尝试使用ExhaustiveTemplateMatching.ProcessImage(),但它不符合我的需求。现在,我正在使用SURF。这是我的代码,是这样的:

I am using Accord.NET to compare images. The first stage of my project is to compare two images, an observed image and a model image, and determine how similar they are; the second, is to compare an observed image against my whole database to determine what the observed image most likely is based on how the models have been categorized. Right now I am focusing on the first. I initially tried using ExhaustiveTemplateMatching.ProcessImage() but it didn't fit my need. Now, I am using SURF. Here is my code as is:

public class ProcessImage
{
    public static void Similarity(System.IO.Stream model, System.IO.Stream observed,
        out float similPercent)
    {
        Bitmap bitModel = new Bitmap(model);
        Bitmap bitObserved = new Bitmap(observed);

        // For method Difference, see http://www.aforgenet.com/framework/docs/html/673023f7-799a-2ef6-7933-31ef09974dde.htm

        // Inspiration for this process: https://www.youtube.com/watch?v=YHT46f2244E
        // Greyscale class http://www.aforgenet.com/framework/docs/html/d7196dc6-8176-4344-a505-e7ade35c1741.htm
        // Convert model and observed to greyscale
        Grayscale filter = new Grayscale(0.2125, 0.7154, 0.0721);
        // apply the filter to the model
        Bitmap greyModel = filter.Apply(bitModel);
        // Apply the filter to the observed image
        Bitmap greyObserved = filter.Apply(bitObserved);
        int modelPoints = 0, matchingPoints = 0;

        /*
         * This doesn't work. Images can have different sizes
        // For an example, https://thecsharper.com/?p=94
        // Match
        var tm = new ExhaustiveTemplateMatching(similarityThreshold); 
        // Process the images
        var results = tm.ProcessImage(greyModel, greyObserved);
        */

        using (SpeededUpRobustFeaturesDetector detector = new SpeededUpRobustFeaturesDetector())
        {
            List<SpeededUpRobustFeaturePoint> surfModel = detector.ProcessImage(greyModel);
            modelPoints = surfModel.Count();
          List<SpeededUpRobustFeaturePoint> surfObserved = detector.ProcessImage(greyObserved);

            KNearestNeighborMatching matcher = new KNearestNeighborMatching(5);
            var results = matcher.Match(surfModel, surfObserved);
            matchingPoints = results.Length;
        }
        // Determine if they represent the same points
        // Obtain the pairs of associated points, we determine the homography matching all these pairs


        // Compare the results, 0 indicates no match so return false
        if (matchingPoints <= 0)
        {
            similPercent = 0.0f;
        }

        similPercent = (matchingPoints * 100) / modelPoints;
    }
}

到目前为止,我可以获得点列表,但是

So far I get to obtain the list of points but then when matching the code seems to become unresponsive.

我在用户发布位图后从ASP.NET网页调用上述代码。以下是可能的代码:

I am calling the above code from an ASP.NET web page after the user posts a bitmap. Here is the code if it may help:

public ActionResult Compare(int id)
    {
        ViewData["SampleID"] = id;

        return View();
    }

    [HttpPost]
    public ActionResult Compare(int id, HttpPostedFileBase uploadFile)
    {
        Sample model = _db.Sample_Read(id);
        System.IO.Stream modelStream = null;
        float result = 0;

        _db.Sample_Stream(model.FileId, out modelStream);

        ImgProc.ProcessImage.Similarity(modelStream, uploadFile.InputStream,
                out result);

        ViewData["SampleID"] = id;
        ViewData["match"] = result;

        return View();
    }

页面本身非常简单,隐藏字段,文件类型输入和

The page itself is rather simple, a hidden field, an file type input and a submit.

推荐答案

问题是我的电脑。经过一段时间的处理后,计算完成。

Problem was my PC. After some time processing the calculation finishes.

谢谢,

这篇关于Accord.NET比较两个图像以确定相似性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆