Search similitary of a picture in folder of thousand others

Everything else that doesn't fall into one of the other PB categories.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

@Idle
Waoooouuuhhh !!! :shock:
Thanks a lot my friend IDLE, i test your code on my thousand records and say to you the result :D
Have a very good end of years 8)
IdeasVacuum wrote:For that particular image, I think OCR could do it.
Thanks IdeasVacuum, it's also an idea.. :D
But i'm not sure, an OCR is easy to use for searching a picture in thousands other :(
Or perhaps i not know all the functions of OCR :oops:
Last edited by Kwai chang caine on Fri Sep 03, 2021 2:53 pm, edited 1 time in total.
ImageThe happiness is a road...
Not a destination
Zach
Addict
Addict
Posts: 1675
Joined: Sun Dec 12, 2010 12:36 am
Location: Somewhere in the midwest
Contact:

Re: Search similitary of a picture in folder of thousand oth

Post by Zach »

OCR = optical character recognition.

Basically, it trains the computer to recognize certain shapes as letters and numbers. I use it all the time on Blu-Ray subtitle files, to generate text-based output.

You could use it like that, to look for album/artists names.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Aaaaah you want to say, try to recognize the title on the records, i'm not sure it's simple for the OCR :shock:
Because all the title have text drawing with much things around, too much color, style, etc... and not really writing...very difficult to recognize :?
A little bit like a captcha :lol:

I don't know what is the time for recognize one record in several thousand...
And not sure, it's not better in time, to try to do that with my eyes :lol:

But it's an idea.... some OCR are very powerfull....
Thanks for your answer :wink:
ImageThe happiness is a road...
Not a destination
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

I have also try with OpenCv, but for the moment, the result is not really "decisive" (It's the less i can say :oops:)
And after several day of research, try several methods, freewares, sharewares, shitware :? , etc ...

I have found 3 ways for the moment to found similar picture:
Image dupeles v1.6.3 works good but shareware
Visipics v1.31 Fr Free works very good, but impossible to take the name of the image found
ImageMagick Free and for the moment it's the only one, i can use with PB (Thanks to DANILO :wink: 8) DANILO/KCC = The dream team :mrgreen: :oops:)

So ATTENTION !!!
After the PQ-Code, the most quick code to compare in the world 8)
KCC make the CP-Code (CowPat-Code), the most slow code to compare in the universe :oops:
See the followed link
That's works, even if the picture is a little bit rotated, and more lightning :shock:
So in this case (The record saragoband, big bamboo), follow my instructions :

1/ Run the application
2/ Search a wife
3/ Married with her
4/ Make three childrens
5/ Return to your PC...normally the picture is found :mrgreen:

So if the picture is not rotate (the case of the other) the code is more quick :oops:
The unity of KCC is not the millisecond, the second,................ but more the minut, see perhaps...the hours :oops:
Image
If someone can make something more fast :lol: :lol: :lol: don't hésitate 8) i'm not offensed :mrgreen:
Last edited by Kwai chang caine on Mon Jan 13, 2014 9:57 pm, edited 3 times in total.
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

Kwaï chang caïne wrote:KCC make the CP-Code (CowPat-Code), the most slow code to compare in the universe :oops:
https://files.cloud.orange.fr/cloudUpDo ... Error=true
The link doesn't work for me.
Some message about a wassup cookie that is missing in the request.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Excuse me.....
This is the good link
http://erdsjb.free.fr/PureStorage/Provi ... cords2.zip
ImageThe happiness is a road...
Not a destination
User avatar
BasicallyPure
Enthusiast
Enthusiast
Posts: 539
Joined: Thu Mar 24, 2011 12:40 am
Location: Iowa, USA

Re: Search similitary of a picture in folder of thousand oth

Post by BasicallyPure »

KCC I think this will be of interest to you.
http://phash.org/

BP
BasicallyPure
Until you know everything you know nothing, all you have is what you believe.
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Hello BASICALLYPURE :D
Since all this time i search a solution, i have also found pHash. :wink:
But the problem is i have not your knowledge :oops:
I don't know the C, it's not an EXE, and nobody already have created a wrapper or an interface in PB like JHPJHP for opencv :cry:

You have right ,apparently it's exactely that i need, because i have tested the site research and the result is verygood.
So for the time, i continue with my interface of ImageMagick, that's works not bad, with again little error, but it's better than nothing.
Like i'm a waffer, i have learning to not be difficult :mrgreen:

The true problem of my code, is for the moment i have not found how create a number, a key,like md5 but with an analyse of the image, for each image, a little bit like your splendid works of histogram, in fact i have found nice, but not understand all :oops:
My goal is create a style of key for each records and put this key in database for have a quick search.
For the time, my code is forced to compare each 12000 images with each record searched.
Imagine yesterday, for found 50 records my code have take 10 hours, it's not again the level of google image... :lol: :lol:
For have a more quick result, i have reduce the 12000 record to 100x100 and imagemagick found more quickly.
Thanks again for your interest for my lost case :|
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Thanks WILBERT 8) but during my numerous research i have also see this blog. :wink:
But it's chinese for kcc :oops:
In fact, i believe to have read all the web, before disturb you, and have eyes like a chameleon :lol:
Much explanation. further in english, and no exe, and link on c :|
Also in python, i not know better :oops: , further broken

I have also, since this time, found this link
http://www.pureftpd.org/project/libpuzzle
First i believe found the solution, but same problem...not understand how use it :oops:

I have found a way for calculate the primary color of all a picture with imagemagick.
I hope with that, sort my records by color, like that not be forced to compare 12000 records each time.

It's for the moment, the only thing i have found... :|
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

The dHash from the first link I posted seems pretty easy to implement.
pHash seems a little more complicated since I'm not familiar with DCT.

Edit:
See also http://www.purebasic.fr/english/viewtop ... 35#p436035 for my npHash module.
Last edited by wilbert on Sat Feb 01, 2014 7:00 pm, edited 1 time in total.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

The dHash from the first link I posted seems pretty easy to implement.
Since 8 years i try to programming in PB, i have destroy in my head the word "EASY" :mrgreen:
The only thing is easy for me all day...it's run PB IDE (And again ... :oops:)
After for me it's a fight of all the days :(
Image

By "easy" you mean this link for use it with PHP ?
http://jax-work-archive.blogspot.com/20 ... dhash.html
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

This should be dHash (hope I didn't make any mistakes)

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()

Procedure.q dHash(filename.s)
  Protected.i img, x, y, c, l0, l1, b, hash.q
  
  img = LoadImage(#PB_Any, filename)
  If IsImage(img)
    ResizeImage(img, 9, 8)
    StartDrawing(ImageOutput(img))
    For y = 0 To 7
      c = Point(0, y)
      l0 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff) 
      For x = 1 To 8
        c = Point(x, y)
        l1 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff)
        If l0 < l1 : hash | 1 << b : EndIf
        l0 = l1
        b + 1
      Next
    Next
    StopDrawing()
    FreeImage(img)
  EndIf
  
  ProcedureReturn hash
EndProcedure

Procedure.i dHashCompare(hash1.q, hash2.q)
  Protected.i result, b
  hash1 ! hash2
  For b = 0 To 63
    If hash1 & (1 << b)
      result + 1
    EndIf
  Next
  ProcedureReturn result
EndProcedure
The dHash procedure returns a 64 bit hash value.
If you compare two hashes using dHashCompare the lower the value, the better the match.
A value of 0 most likely is the same image, a value > 10 is most likely a different image.
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: Search similitary of a picture in folder of thousand oth

Post by Kwai chang caine »

Waooooouuuh i don't believe my eyes !!!! :shock: :shock:

I have try your crazy code, and the result is enough good 8)
I have not testing in all the case (Rotate, size, lightning, etc...)
But for the moment, it's good !!!! see yourself 8)
Compare two differents picture of extremely different record
-2770167811735213228
2609421560056017481
34

Compare exactely the same picture of the same record
-2770167811735213228
-2770167811735213228
0

Compare two differents picture of the same record
-2770167811735213228
-2842226509793678442
13

Compare the same picture rotating
-2770167811735213228
9173101322984576773
21

Compare the same picture lightning
-2770167811735213228
-2770167811735213100
1
It's a miracle !!!!
http://erdsjb.free.fr/PureStorage/Provi ... ilbert.zip

Image
One thousand of thanks WILBERT !!!
ImageThe happiness is a road...
Not a destination
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3942
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: Search similitary of a picture in folder of thousand oth

Post by wilbert »

I'm glad it works for you :D

You could try a minor modification

Code: Select all

UseJPEGImageDecoder()
UsePNGImageDecoder()

Procedure.q dHash(filename.s)
  Protected.i img, x, y, c, l0, l1, b, hash.q
  
  img = LoadImage(#PB_Any, filename)
  If IsImage(img)
    ResizeImage(img, 9, 8)
    StartDrawing(ImageOutput(img))
    For y = 0 To 7
      c = Point(0, y)
      l0 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff) 
      For x = 1 To 8
        c = Point(x, y)
        l1 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff)
        If l0 < l1 : hash | 1 << b : EndIf
        l0 = l1
        b + 1
      Next
    Next
    StopDrawing()
    FreeImage(img)
  EndIf
  
  ProcedureReturn hash
EndProcedure

Procedure.q dHash2(filename.s)
  Protected.i img, x, y, c, l0, l1, b, hash.q
  
  img = LoadImage(#PB_Any, filename)
  If IsImage(img)
    ResizeImage(img, 11, 10)
    StartDrawing(ImageOutput(img))
    For y = 1 To 8
      c = Point(1, y)
      l0 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff) 
      For x = 2 To 9
        c = Point(x, y)
        l1 = (c >> 8 & $ff) << 2 + (c & $ff) << 1 + (c >> 16 & $ff)
        If l0 - l1 < 8 : hash | 1 << b : EndIf
        l0 = l1
        b + 1
      Next
    Next
    StopDrawing()
    FreeImage(img)
  EndIf
  
  ProcedureReturn hash
EndProcedure

Procedure.i dHashCompare(hash1.q, hash2.q)
  Protected.i result, b
  hash1 ! hash2
  For b = 0 To 63
    If hash1 & (1 << b)
      result + 1
    EndIf
  Next
  ProcedureReturn result
EndProcedure
Does dHash2 give you better results ?
It's a small modification that discards the outer parts.
Windows (x64)
Raspberry Pi OS (Arm64)
Post Reply