任何人都可以用代码帮我吗? [英] Can any one Help me with code ?

查看:99
本文介绍了任何人都可以用代码帮我吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。我正在使用Windows窗体中的项目,并且无法使此代码正常工作。



我想比较位图图像和文件中的图像C:\\Users \\Dave \\Documents \\ Visual Studio 2012 \\Projects \\Bura \\kartebi \\\\\\\\\\\\\\我做了两个班。首先是匹配类,它是比较twi位图图像。如果图像A包含图像B则返回true,否则返回false;第二类是imageCompare,我在其中创建字符串数组mis,在那里我有Kartebi文件夹中的所有图像路径。比我创建一个bitfor阵列,所有图像都在哪里。至少我正在与Matching.bp2(Bitmap largeImage,Bitmap模板)进行比较,如果是真的我在这个Image的add数组地址中添加。这个Compare方法返回Array。在这个数组中写入了所有的pathes,它们是Bitmap Image的一部分。但这段代码不起作用。它无法识别哪个图像包含哪个位图。但是在所有Arrays中,Infromation都是正确编写的,例如mis,bitfor。任何人都可以帮我这个吗?



这是一个代码:



Hello guys. I am working on my project in Windows Forms and cann't make this code work correctly.

I want to compare Bitmap image with Images in File "C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\Bura\\kartebi\\Kartebi" . I have made two Class. First is "Matching" class, which is comparing twi Bitmap Images. If image A contains Image B is return true, otherwise is return false; And the second Class is "imageCompare", in which i am creating string array "mis", there I have all image path which are in "Kartebi" Folder. Than I am creating one more array "bitfor ", where are all images. At least I am comparing with Matching.bp2(Bitmap largeImage, Bitmap template), if it is true I am adding in "add" array address of this Image. This "Compare" Method return Array. In this array is written all pathes which are part of Bitmap Image. But this code donn't works. It cann't identifi which Image which Bitmap contains. But in all Arrays Infromation is written correctly, for example in "mis","bitfor". Can anyone Help me with this ?

Here is a Code :

    public static class imageCompare
    {
        public static string[] Compare(Bitmap bitmap)
        {
            string[] mis = Directory.GetFiles("C:\\Users\\Dave\\Documents\\Visual Studio 2012\\Projects\\Bura\\kartebi\\Kartebi", "*.png");
            
            string[] add = new string[mis.Length];
            
            Bitmap[] bpp = new Bitmap[36];

            Bitmap[] bitfor = new Bitmap[36];
            //
            for (int i = 0; i < bitfor.Length; i++)
            {
                bpp[i] = (Bitmap)System.Drawing.Image.FromFile(mis[i]);
                bitfor[i] = Form1.ConvertToFormat(bpp[i], System.Drawing.Imaging.PixelFormat.Format24bppRgb);
            }

            for (int i = 0; i < bitfor.Length; i++)
            {
                if (Matching.bp2(bitmap, bitfor[i]))
                    add[i] = mis[i];
                else
                    add[i] = null;
            }
            return add;
            
        }
    }


public static class Matching
    {
        public static bool bp2(this Bitmap template, Bitmap bmp)
        {
            const int divisor = 4;
            const int epsilon = 10;

            ExhaustiveTemplateMatching etm = new ExhaustiveTemplateMatching(0.9f);
            TemplateMatch[] tm = etm.ProcessImage(new ResizeNearestNeighbor(template.Width / divisor, template.Height / divisor).Apply(template),
                                                  new ResizeNearestNeighbor(bmp.Width / divisor, bmp.Height / divisor).Apply(bmp));
            if (tm.Length == 1)
            {
                Rectangle tempRect = tm[0].Rectangle;

                if (Math.Abs(bmp.Width / divisor - tempRect.Width) < epsilon && Math.Abs(bmp.Height / divisor - tempRect.Height) < epsilon)
                {
                    return true;
                }
            }
            return false;
        }
    }

推荐答案

为什么不在AForge支持论坛上提出这个问题......因为那是'ExhaustiveTemplateMatching来自哪里?



像这样的AForge用户做了:[ ^ ]。
Why aren't you asking this question on the AForge support forum ... since that is where 'ExhaustiveTemplateMatching comes from ?

Like this AForge user did: [^].


简答:简单,此代码不要'做你认为应该做的事。



这是一个错误或误解。



第一,转到作者(如解决方案1中所建议的),看看你是否理解它应该做什么或有错误。



其次,试着去理解什么是错的。

准备一些应该匹配的图片和其他不应该的图片?

然后,用调试器一步一步地运行它们,看看它什么时候出错。



建议:用几段而不是ao来组织你的问题ne big。
Short answer: Simple, this code don't do what you think it should.

It is either a bug or a misunderstanding.

First, go to author (as suggested in solution 1) and see if you understood what it should do or have a bug.

Second, try to understand what is wrong.
Prepare some sets of pictures that should match and other sets that shouldn't?
Then, run them with the debugger step by step and see when it goes wrong.

Advice: organise your question in a few paragraphs rather a one big.


这篇关于任何人都可以用代码帮我吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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