Image comparison & recognition with VBA

Hi experts,

I have a set of 100 images named from 1 to 100. (250*50 pixels each) and a selected image among this 100 images. I want to identify the selected image. (Find the exact match of this image among this 100 images)
Can anyone help me on this ?

PS. I'm using VBA under Access 2007.

Thanks in advance...
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Could you clarify how your images are stored.  ie. in a Table (in what format) or as individual files?

Also the selected image, how is this stored (same as the 100 images, in a variable, in a byte array, whatever).

Finally is the selected image an exact replica of one of the 100 images or do you have issues with differing image compression or even want to do a soft match to the 'best fit'?
Crawler77Author Commented:
I'm sorry that I haven't given much detail.

Images are individual files. I may convert them to any format (jpg, bmp, gif, ect...). so you're not bound to formats.

The selected image is an exact replica of one of the 100 images. And I plan to take a screenshot to obtain it. (If you can also help me on this I would appreciate that too.)

In fact what I try to do is find what image is displayed in a webpage. It changes randomly between 100 images within a flash application.

Thanks for the reply. If you need more info I'll be here...
Sorry Crawler77, I think this is beyond me.

As I understand it you want to grab an image from within a browser and match it to 1 of 100 images stored as files which can be in any format.  The problem here is that some of these formats support lossy compression so an image once compressed is not identical to the original.  Furthermore coming via a web page/flash the image could have been scaled to a different size for display purposes.  So whilst the image may look the same to us humans it is actually very different making comparison difficult.

Best of luck

The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

Crawler77Author Commented:
Barry I think you misunderstood me.
Forget about the browser thing.
I'll ask my question again.

Guess that I have 100 let me say, bmp images, or 100 jpg images, or gif images. Whichever suits you. I wanted to say that all images are in the SAME format but you can assume all of them to be ANY FORMAT you want (as a set). I can convert my source set of images to the format you choose.

Now can I identify a random image among these 100 images which is EXACTLY the same as one of them ? (Also in the same format with them)

If you can just answer this it will be sufficent for me.

Thanks again...
Crawler77Author Commented:
You better assume all images to be BMP.
Crawler77Author Commented:

I'm using VBA under Access 2007 and I think because of that some codes are not working.
(For example the first one)
You would struggle to get this functionality in VBA so I suggest you to use a VB.NET DLL to do all the dirty work and then use COM to use it.
Crawler77Author Commented:
How will I do that ?
If you are trying to compare 2 files I have attached some code which will do that natively in VBA without any external calls.  The code doesn't care whether the files are images or otherwise.  
Function IdenticalFiles(strFilename1 As String, strFilename2 As String) As Boolean

Dim byt1() As Byte
Dim byt2() As Byte
Dim f1 As Integer
Dim f2 As Integer
Dim lngFileLen1 As Long
Dim lngFileLen2 As Long
Dim i As Long

'Test to see if we have actually been passed 2 filenames
If LenB(strFilename1) = 0 Or LenB(strFilename2) = 0 Then Exit Function
'Test to see if the first file exists
If LenB(Dir(strFilename1)) = 0 Then Exit Function
'Test to see if the second file exists
If LenB(Dir(strFilename2)) = 0 Then Exit Function

'OK now start looking at the file contents
f1 = FreeFile
Open strFilename1 For Binary Access Read As #f1
f2 = FreeFile
Open strFilename2 For Binary Access Read As #f2
lngFileLen1 = LOF(f1)
lngFileLen2 = LOF(f2)
If lngFileLen1 = lngFileLen2 Then
  'Continue - there is a possibility they are the same
  ReDim byt1(1 To lngFileLen1) As Byte
  ReDim byt2(1 To lngFileLen2) As Byte
  Get #f1, , byt1
  Get #f2, , byt2
  For i = 1 To lngFileLen1
    If byt1(i) <> byt2(i) Then GoTo IdenticalFiles_Exit 'The 2 files are not the same
  'We got this far so the 2 files must be the same
  IdenticalFiles = True
End If

Close #f1
Close #f2

End Function

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Crawler77Author Commented:
Bullseye :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.