Page 2 of 4

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

Posted: Sat Dec 28, 2013 6:29 pm
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:

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

Posted: Thu Jan 02, 2014 2:08 pm
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.

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

Posted: Thu Jan 02, 2014 2:40 pm
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:

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

Posted: Mon Jan 13, 2014 6:49 pm
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:

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

Posted: Mon Jan 13, 2014 7:26 pm
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.

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

Posted: Mon Jan 13, 2014 7:36 pm
by Kwai chang caine
Excuse me.....
This is the good link
http://erdsjb.free.fr/PureStorage/Provi ... cords2.zip

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

Posted: Thu Jan 16, 2014 9:52 pm
by BasicallyPure
KCC I think this will be of interest to you.
http://phash.org/

BP

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

Posted: Fri Jan 17, 2014 9:42 am
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 :|

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

Posted: Fri Jan 17, 2014 1:49 pm
by wilbert

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

Posted: Fri Jan 17, 2014 3:01 pm
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... :|

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

Posted: Fri Jan 17, 2014 3:23 pm
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.

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

Posted: Fri Jan 17, 2014 4:12 pm
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

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

Posted: Fri Jan 17, 2014 4:16 pm
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.

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

Posted: Fri Jan 17, 2014 4:43 pm
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 !!!

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

Posted: Fri Jan 17, 2014 5:12 pm
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.