Put the first line Pixel(x,0) of the SmallImg in a structure (Array, StringList, what you prefer),
then scan the big image line per line.
When you find the pixel sequence then compare the second line of SmallImg with the (maybe) corrisponding of the BigImg (Same x of the first occurence, y+1) and so on.
If all the lines are the same, you have find your SmallImg.
OK, that's clear.
I mean what ideas have you got concerning optimizing this process? Realization you suggested takes 80 seconds when searching for 16x14 image inside of 800x600 (worst case).
Hi,
to optimize it you can do follow:
1) put your BigImage in a structure (Color, x, y)
2) order it by color
3) do the same with your small Img
4) select the color with less pixels
5) search in this structure just for one color, for example:
The small picture have 4 red pixels. Store this information in the form x,y for the first, x+a,y+b for the second and so on. Then take the first pixel in the Big stucture in the "red section". If Abs(x[0]-x[1])=a => it may be the right pixel, else If x[0]-x[2]=a and so on. (check also the y only if it match) When the first two points match, do it again with the third and so on.
Working with in-memory structure (Array or TList or something else) should dramatically increase your speed, because you don't have to manage DeviceContext, Canvas, and other stuff that brakes your procedure, any you read the pixel only ones.
Of course this method won't be the best if you examin the image of a ChessBoard (with many x[0]-x[1]=a), but for many pictures it should be ok.
P.S.
I wrote a better answer, but this site crashes when uploading, and my WellWritingImpulse is gone with it.
Just ask me if something is not clear.
Yeap. But:
-there is no real need to sort colors in small image;
-usage of two figurative points (they are first to check)give excellent speed gain, while the third does not;
-using TBitmap.Scanline is the first a programmer should come to know (for 4 years working with Delphi I used Canvas.pixels[]).
Thank you for participation.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.