如何比较图像 [英] How to compare Images

查看:63
本文介绍了如何比较图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在开发一个比较两个图像的软件,这意味着首先将带有网络摄像头的图像保存到数据库中,然后再使用网络摄像头拍照,然后再进行扫描以进行比较.

I am developing a software that compare two images , means first to save image with webcam in database and then take a picture with web cam and then Scan to compare..

现在我的问题是,由于网络摄像头和照明设备的亮度会影响该问题,我该怎么办...

Now my Question is how can i do this as the brightness of web cam and lighting affect this...

我不希望得到100%的结果,因为如果我扫描图像并且它的某些部分与数据库中的4到5幅图像匹配,那么我应该得到它,那么它应该返回5幅图像,应该忽略颜色以及亮度.

i dont want 100% result, as I want it if I scan image and some part of it matched with 4 to 5 image from database then it should return 5 Image, color should be neglected as well as brightness.

如果我用网络摄像头拍照并以任何角度保存,它将与我最后捕获的图​​像进行比较.

If i take a pic with web cam and save this with any angle, it will compare with image that i capture last..

请帮助我...

谢谢..:)

推荐答案

无法设置Srystal报告的PaperSize.

Hi Can not set a PaperSize of srystal report.

谢谢您在这里发布.

根据您的描述,我对要比较的图像不太了解.

According to your description, I do not have a good understanding of what the images you want to compare.

如果要比较成像的图像,图像的大小将相同.

If you want to compare the imaged, image would be the same size.

您可以使用以下代码对其进行比较,它将以百分比形式输出相似度.

You could use the following code to compare them and it will output the similarity in percentage.

这是代码.

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace compare_images
{
    class Program
    {
        static void Main(string[] args)
        {
            Bitmap img1 = new Bitmap(@"C:\Users\v-wezan\Desktop\image.png");
            Bitmap img2 = new Bitmap(@"C:\Users\v-wezan\Desktop\image2.png");

            if (img1.Size != img2.Size)
            {
                Console.Error.WriteLine("Images are of different sizes");
                return;
            }

            float diff = 0;

            for (int y = 0; y < img1.Height; y++)
            {
                for (int x = 0; x < img1.Width; x++)
                {
                    diff += (float)Math.Abs(img1.GetPixel(x, y).R - img2.GetPixel(x, y).R) / 255;
                    diff += (float)Math.Abs(img1.GetPixel(x, y).G - img2.GetPixel(x, y).G) / 255;
                    diff += (float)Math.Abs(img1.GetPixel(x, y).B - img2.GetPixel(x, y).B) / 255;
                }
            }
            Console.WriteLine("diff: {0} %", 100 * diff / (img1.Width * img1.Height * 3));
            Console.ReadKey();
        }
    }
}

如果要比较图像之间的差异,可以参考

If you want to compare the images for their difference, you could refer to the thread I done before.

我希望这会对您有所帮助.

I hope this would be helpful to you.

最好的问候,

温迪


这篇关于如何比较图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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