如何匹配存储在数据库中的图像并检索相关记录 [英] how to match image stored in database and retrieve related records

查看:75
本文介绍了如何匹配存储在数据库中的图像并检索相关记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

hi
i在我的数据库中有一个名为image的表格,我在那里存储指纹。

i在C#中有匹配和查找代码,并且它们都能很好地工作。 />
让我给你一个关于如何完成匹配的想法......有两个图像(图片框)查询和模板....当我用指纹加载它们时它完全匹配。



i创建了一个文件夹,其中有许多指纹图像,当我加载查询图像并点击匹配时,它给我完美匹配(通过扫描该文件夹)并返回图像名称。



NOW

问题是我想从数据库扫描图像,即我想在图片框中加载查询图像后我点击查找,它应该扫描我存储在我的数据库中的每个图像,找到完美匹配,它应该在匹配后检索与该图像相关的所有数据(例如:ID,名称,电子邮件,联系人......等)<下面是


是查找按钮的代码:

 private void btnFind_Click(object sender,EventArgs e)
{
{

双倍得分;
{

// timage = null;
string path = @D:\ db;
string dir = Path.GetFileNameWithoutExtension(path);
string [] filess = Directory.GetFiles(path,* .tif *,System.IO.SearchOption.AllDirectories);
MessageBox.Show(dir);




for(var i = 0; i< filess.Length; i ++)
{

var item = filess [i];
//在这里处理项目
// MessageBox.Show(filess [i]);
// pbxTemplateImg.Image = tImage;


tImage = ImageLoader.LoadImage(filess [i]);
pbxTemplateImg.Image = tImage;

{
string shortFileName = Path.GetFileNameWithoutExtension(filess [i]);
try
{
tFeatures = provider.GetResource(shortFileName,repository);
}
catch(例外)
{
MessageBox.Show(无法加载功能+ provider.GetSignature()+。尝试使用不同的参数。,功能加载错误,
MessageBoxButtons.OK,MessageBoxIcon.Error);
返回;
}
}






if(qImage == null)
{
MessageBox.Show(无法匹配指纹:未分配的查询指纹!,错误,MessageBoxButtons.OK,MessageBoxIcon.Error);
返回;
}

if(tImage == null)
{
MessageBox.Show(无法匹配指纹:未分配的模板指纹!,错误,MessageBoxButtons .OK,MessageBoxIcon.Error);
返回;
}

//匹配功能
列表< MinutiaPair> matchingMtiae = null;
//双倍得分;
IMinutiaMatcher minutiaMatcher = matcher as IMinutiaMatcher;
if(minutiaMatcher!= null)
{
score = minutiaMatcher.Match(qFeatures,tFeatures,out matchingMtiae);

if(qFeatures为List< Minutia>& tFeatures为List< Minutia>)
{
pbxQueryImg.Image = qImage.Clone()as Bitmap;
Graphics g1 = Graphics.FromImage(pbxQueryImg.Image);
ShowBlueMinutiae(qFeatures as List< Minutia>,g1);
//pbxQueryImg.Invalidate();

//pbxTemplateImg.Image = tImage.Clone()as Bitmap;
图形g2 = Graphics.FromImage(pbxTemplateImg.Image);
ShowBlueMinutiae(tFeatures as List< Minutia>,g2);
//pbxTemplateImg.Invalidate();

if(score == 0 || matchingMtiae == null)
MessageBox.Show(string.Format(Similarity:{0}。,score));
else
{
List< Minutia> qMtiae = new List< Minutia>();
List< Minutia> tMtiae = new List< Minutia>();
foreach(MinutiaPair mPair in matchingMtiae)
{
qMtiae.Add(mPair.QueryMtia);
tMtiae.Add(mPair.TemplateMtia);
}
IFeatureDisplay< List< Minutia>> display = new MinutiaeDisplay();

display.Show(qMtiae,g1);
pbxQueryImg.Invalidate();

display.Show(tMtiae,g2);
pbxTemplateImg.Invalidate();
if(得分> 70)
{
MessageBox.Show(string.Format(相似度:{0}。匹配细节:{1}。,得分,
matchingMtiae.Count));
}
}
}
else
ShowResults(score,matchingMtiae);

}
else
得分= matcher.Match(qFeatures,tFeatures);
if(得分<70)
{
//MessageBox.Show(\"match nt found);
//休息;


}
其他
{

MessageBox.Show(匹配找到);
休息;
}

}
}
}
}

解决方案

有几种比较图像的方法。请参阅: http://stackoverflow.com/questions/843972/image-comparison-fast-algorithm [ ^ ]。



这是一个很好的例子:简单.NET中的图像比较 [ ^ ]

hi i have a table named "image" in my database where i am storing fingerprints.
i have a matching and finding code in C# and both of them work perfectly well.
Let me give u an idea about how the matching is done...there are two images(picturebox) Query and Template....when i load both of these with fingerprint it matches perfectly.

i have created a folder in which there are many fingerprint images and when i load a query image and click match it gives me the perfect match (by scanning that folder) and returns the image name.

NOW
the problem is that i want to scan images from database i.e. i want that after loading the query image in the picturebox and when i click find , it should scan each image that i have stored in my database , find the perfect match and it should after matching retrieve all the data related to that image(Eg: ID,name,email,contact...etc)

below is the code for find button:

private void btnFind_Click(object sender, EventArgs e)
{
    {

        double score;
        {

            // timage = null;
            string path = @"D:\db";
            string dir = Path.GetFileNameWithoutExtension(path);
            string[] filess = Directory.GetFiles(path, "*.tif*" , System.IO.SearchOption.AllDirectories);
            MessageBox.Show(dir);




            for (var i = 0; i < filess.Length; i++)
            {

                var item = filess[i];
                //work with item here
                // MessageBox.Show(filess[i]);
                // pbxTemplateImg.Image = tImage;


                tImage = ImageLoader.LoadImage(filess[i]);
                pbxTemplateImg.Image = tImage;

                {
                    string shortFileName = Path.GetFileNameWithoutExtension(filess[i]);
                    try
                    {
                        tFeatures = provider.GetResource(shortFileName, repository);
                    }
                    catch (Exception)
                    {
                        MessageBox.Show("Unable to load features " + provider.GetSignature() + ". Try using different parameters.", "Feature Loading Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }






                if (qImage == null)
                {
                    MessageBox.Show("Unable to match fingerprints: Unassigned query fingerprint!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                if (tImage == null)
                {
                    MessageBox.Show("Unable to match fingerprints: Unassigned template fingerprint!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                // Matching features
                List<MinutiaPair> matchingMtiae = null;
                //double score;
                IMinutiaMatcher minutiaMatcher = matcher as IMinutiaMatcher;
                if (minutiaMatcher != null)
                {
                    score = minutiaMatcher.Match(qFeatures, tFeatures, out matchingMtiae);

                    if (qFeatures is List<Minutia> && tFeatures is List<Minutia>)
                    {
                        pbxQueryImg.Image = qImage.Clone() as Bitmap;
                        Graphics g1 = Graphics.FromImage(pbxQueryImg.Image);
                        ShowBlueMinutiae(qFeatures as List<Minutia>, g1);
                        //pbxQueryImg.Invalidate();

                        //pbxTemplateImg.Image = tImage.Clone() as Bitmap;
                        Graphics g2 = Graphics.FromImage(pbxTemplateImg.Image);
                        ShowBlueMinutiae(tFeatures as List<Minutia>, g2);
                        //pbxTemplateImg.Invalidate();

                        if (score == 0 || matchingMtiae == null)
                            MessageBox.Show(string.Format("Similarity: {0}.", score));
                        else
                        {
                            List<Minutia> qMtiae = new List<Minutia>();
                            List<Minutia> tMtiae = new List<Minutia>();
                            foreach (MinutiaPair mPair in matchingMtiae)
                            {
                                qMtiae.Add(mPair.QueryMtia);
                                tMtiae.Add(mPair.TemplateMtia);
                            }
                            IFeatureDisplay<List<Minutia>> display = new MinutiaeDisplay();

                            display.Show(qMtiae, g1);
                            pbxQueryImg.Invalidate();

                            display.Show(tMtiae, g2);
                            pbxTemplateImg.Invalidate();
                            if (score > 70)
                            {
                                MessageBox.Show(string.Format("Similarity: {0}. Matching minutiae: {1}.", score,
                                                              matchingMtiae.Count));
                            }
                        }
                    }
                    else
                        ShowResults(score, matchingMtiae);

                }
                else
                    score = matcher.Match(qFeatures, tFeatures);
                if (score < 70)
                {
                    //MessageBox.Show("match nt found");
                    //break;


                }
                else
                {

                    MessageBox.Show("match found");
                    break;
                }

            }
        }
    }
}

解决方案

There are several methods to compare images. See this: http://stackoverflow.com/questions/843972/image-comparison-fast-algorithm[^].

Here is pretty good example: Simple image comparison in .NET[^]


这篇关于如何匹配存储在数据库中的图像并检索相关记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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