Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/285.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.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# 从大图像中快速检测图像的方法_C#_Image Processing - Fatal编程技术网

C# 从大图像中快速检测图像的方法

C# 从大图像中快速检测图像的方法,c#,image-processing,C#,Image Processing,目前,我使用它来查找屏幕上另一个图像(即窗口)中出现的位图,但它的工具速度很慢,我希望它需要1秒或更短的时间,我正在考虑将图像裁剪成一个部分,即图像0,0点处的80,60部分,并在那里搜索,当它这样做时,它会进行相同的裁剪,但y+60并继续,直到它覆盖了整个图像(假设它是800×600像素) 我目前使用的代码是: public bool findImage(Bitmap small, Bitmap large, out Point location) {

目前,我使用它来查找屏幕上另一个图像(即窗口)中出现的位图,但它的工具速度很慢,我希望它需要1秒或更短的时间,我正在考虑将图像裁剪成一个部分,即图像0,0点处的80,60部分,并在那里搜索,当它这样做时,它会进行相同的裁剪,但y+60并继续,直到它覆盖了整个图像(假设它是800×600像素)

我目前使用的代码是:

        public bool findImage(Bitmap small, Bitmap large, out Point location)
    {
        //Loop through large images width
        for (int largeX = 0; largeX < large.Width; largeX++)
        {
            //And height
            for (int largeY = 0; largeY < large.Height; largeY++)
            {
                //Loop through the small width
                for (int smallX = 0; smallX < small.Width; smallX++)
                {
                    //And height
                    for (int smallY = 0; smallY < small.Height; smallY++)
                    {
                        //Get current pixels for both image
                        Color currentSmall = small.GetPixel(smallX, smallY);
                        Color currentLarge = large.GetPixel(largeX + smallX, largeY + smallY);
                        //If they dont match (i.e. the image is not there)

                        if (!colorsMatch(currentSmall, currentLarge))
                            //Goto the next pixel in the large image

                            goto nextLoop;
                    }
                }
                //If all the pixels match up, then return true and change Point location to the top left co-ordinates where it was found
                location = new Point(largeX, largeY);
                return true;
            //Go to next pixel on large image
            nextLoop:
                continue;
            }
        }
        //Return false if image is not found, and set an empty point
        location = Point.Empty;
        return false;
    }
public bool findImage(小位图、大位图、出点位置)
{
//循环浏览大宽度图像
for(int-largeX=0;largeX
由于您正在寻找精确匹配,您可以对大图片进行下采样,也可以对小图片进行下采样(但要在不同的偏移量下进行多次)。然后搜索下采样图片的精确匹配(可能是递归的)

您的大图片听起来不太大,您可以通过Boyer-Moore搜索其中一行来逃脱处罚。

这可能会引起您的兴趣: