Page 1 of 2
compare 2 bitmaps?
Posted: Fri Sep 19, 2008 9:54 am
by Jimboi
What's the fastest way to compare 2 bitmaps?
Re: compare 2 bitmaps?
Posted: Fri Sep 19, 2008 9:56 am
by IceSoft
Jimboi wrote:What's the fastest way to compare 2 bitmaps?
Use only very different bitmaps...So you can see it with your own eyes (Ok joke, sorry

)
Posted: Fri Sep 19, 2008 10:36 am
by AND51
Run through the two images, comparing pixel by pixel in a For-loop by reading the image buffer with DrawingBuffer().
Posted: Fri Sep 19, 2008 10:41 am
by pdwyer
It depends what answer you are looking for.
Do you just want "isIdentical" True/False or "how different" answer is a distance function (number of identical pixels or distance of the colour etc).
When you compare pixel by pixel you could just jump out of the loop at the first point that doesn't match.
You could compare to CRC's of the image too perhaps.
Posted: Fri Sep 19, 2008 10:47 am
by Jimboi
thanks guy!..very fast reply
but my grandmother say..compare pixel by pixel can be slow..

Posted: Fri Sep 19, 2008 10:50 am
by AND51
No, that's wrong.
Comparing pixel by pixel with Point() is very slow...
Comparing pixel by pixel with the method I've described above is very fast!
If you only find 100% identical double images, you can also use MD5FileFingerprint(), but then the whole file must be abso-fuckin-lutely identical!!
Posted: Fri Sep 19, 2008 11:05 am
by y3an
Also, .bmp are very simple to read with ReadFile()
http://en.wikipedia.org/wiki/BMP_file_format
So you have not to "ask" necessarily the video buffer
Posted: Fri Sep 19, 2008 11:14 am
by Trond
Something like this (I didn't test it):
Code: Select all
ReadFile(0, "c:\file1.bmp")
ReadFile(1, "c:\file2.bmp")
Len = Lof(0)
If Len = Lof(1)
Mem1 = AllocateMemory(Len)
Mem2 = AllocateMemory(Len)
ReadData(0, Mem1, Len)
ReadData(1, Mem2, Len)
Result = CompareMemory(Mem1, Mem2, Len)
EndIf
CloseFile(0)
CloseFile(1)
Posted: Fri Sep 19, 2008 11:23 am
by Jimboi
Thanks guy.. i never espect that nice people like u all
still exists in this world.

Posted: Fri Sep 19, 2008 11:26 am
by AND51
This might be faster than the MD5-method, but the file must be present on your HDD. For example, you cannot compare 2 images that you received via network.
And you code fails, when comparing a PNG to a GIF for example.
I think it would be the best, if the thread creator tells us more details about his needs.
//Edit
Do you only want to compare BMPs or all image formats?
Posted: Fri Sep 19, 2008 12:12 pm
by Jimboi
That enough for today..i will try yours guide when get home..
anyway..this is just an idea... i try to compare internet captcha image with my collections captcha image stored in my harddisk.. since coding someting like OCR is very tough for me.. this might be usefull for auto login to website that i visit everyday like bux site..
Posted: Fri Sep 19, 2008 9:03 pm
by Kaeru Gaman
If you copy both images over each other with XOr, each difference will leave a set bit in a desert of zeros.
... but I doubt it would be faster, because you could do the compare in the first loop, instead of first copy it and then find a zero...
but it's the most effektive method if you want to compare the pictures visually.
Posted: Sat Sep 20, 2008 11:04 am
by thefool
i try to compare internet captcha image with my collections captcha image stored in my harddisk
Okay, first up i want to tell that captcha's are made so bots/other software will be restricted from doing things. They are there for a purpose, not to annoy users, rather to protect them. They are MADE to be very very hard for software to read/understand, so the chance that you or practically anybody can read the newer generation captchas is VERY little.
Secondly, neither of the above solutions will work here as these captchas are probably generated on the fly. You need some kind of estimate to see if they are likely to be equal. So you need some analysis tools, byte to byte will have no effect with captchas. Neural networks might be used to create some sort of heuristic analysis, but this is not an easy thing to code and it will be tricket by artifacts and traps in the images.
And with the more and more advanced captchas on today, you will need code to eliminate vertical lines and bogus characters/graphic. This is not an easy job, trust me on that one. Simply comparing bytes will get you no where in this situation.
edit:
i know you are also looking for an OCR dll to help you with this, but i can tell you that i really doubt you'll find anything that works with just the slightly more advanced captchas. Again, captchas are MADE not to be machine-readable.
Could you eventually post an example captcha, eg take a screenshot of one from there so we can see what exactly it is we are dealing with?
Posted: Sat Sep 20, 2008 4:00 pm
by Kaeru Gaman
oh, I just overlooked the sentence with the captchas...
I agree to thefool
it would be absolutely useless I think, because one captcha just have to be altered in one pixel to be two different images but still the same captcha.
you won't be able to store enough comparison images and compare them in time before the universe ends to identify ANY captcha.
... better pay someone to read the captchas for you, that would be far far more effektive.
Posted: Mon Sep 22, 2008 7:56 am
by Jimboi
i agree too.. just learn how captcha made
so..how about OCR (Optical Character Recognition) is it any possibality to handle captcha thing?