similar up to threshold
This commit is contained in:
@@ -381,7 +381,10 @@ def find_fingerprint_similar(opts):
|
|||||||
def find_fingerprint_nearest(opts):
|
def find_fingerprint_nearest(opts):
|
||||||
''' Find nearest match to given file '''
|
''' Find nearest match to given file '''
|
||||||
|
|
||||||
cmp=os.path.abspath(opts.similarity)
|
cmp=os.path.abspath(opts.similarity.rsplit(",")[0])
|
||||||
|
thr=sys.maxint
|
||||||
|
if len(opts.similarity.rsplit(","))>1:
|
||||||
|
thr=int(opts.similarity.rsplit(",",1)[1])
|
||||||
conn=sqlite3.connect(opts.sqlfile)
|
conn=sqlite3.connect(opts.sqlfile)
|
||||||
conn.text_factory=str
|
conn.text_factory=str
|
||||||
db1=conn.cursor()
|
db1=conn.cursor()
|
||||||
@@ -399,7 +402,8 @@ def find_fingerprint_nearest(opts):
|
|||||||
colors=get_colors(cmp)[0]
|
colors=get_colors(cmp)[0]
|
||||||
|
|
||||||
db1.execute("SELECT file,fingerprint,sharpness,width,height,R,G,B FROM list WHERE sharpness > 0 ORDER BY file")
|
db1.execute("SELECT file,fingerprint,sharpness,width,height,R,G,B FROM list WHERE sharpness > 0 ORDER BY file")
|
||||||
this=['',sys.maxint,0,0,0,0]
|
this=['',thr,0,0,0,0]
|
||||||
|
hit1=None
|
||||||
for i,hit1 in enumerate(db1):
|
for i,hit1 in enumerate(db1):
|
||||||
if hit1[0] == cmp:
|
if hit1[0] == cmp:
|
||||||
continue
|
continue
|
||||||
@@ -411,9 +415,12 @@ def find_fingerprint_nearest(opts):
|
|||||||
this[3]=int(hit1[3])
|
this[3]=int(hit1[3])
|
||||||
this[4]=int(hit1[4])
|
this[4]=int(hit1[4])
|
||||||
this[5]=abs( hit1[5] - colors[0] )+abs( hit1[6] - colors[1] )+abs( hit1[7] - colors[2] )
|
this[5]=abs( hit1[5] - colors[0] )+abs( hit1[6] - colors[1] )+abs( hit1[7] - colors[2] )
|
||||||
if this[0]=='':
|
if hit1==None:
|
||||||
print("No measurements found")
|
print("No measurements found")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
if this[1]==thr:
|
||||||
|
print("No similar images for "+cmp+", up to threshold "+str(thr))
|
||||||
|
return
|
||||||
file_len=str(max(len(cmp), len(this[0])))
|
file_len=str(max(len(cmp), len(this[0])))
|
||||||
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: ^5}x{: ^5}').format("File","Diff","CDel","Shrp","Wth","Hgt"))
|
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: ^5}x{: ^5}').format("File","Diff","CDel","Shrp","Wth","Hgt"))
|
||||||
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: >5}x{: >5}').format(cmp,"","","%.1f" % sp,dims[0],dims[1]))
|
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: >5}x{: >5}').format(cmp,"","","%.1f" % sp,dims[0],dims[1]))
|
||||||
@@ -595,7 +602,7 @@ def main():
|
|||||||
if options.nearestcolor:
|
if options.nearestcolor:
|
||||||
find_color_nearest(options)
|
find_color_nearest(options)
|
||||||
if options.similarity!=None:
|
if options.similarity!=None:
|
||||||
if os.path.exists(options.similarity):
|
if os.path.exists(options.similarity.rsplit(",")[0]):
|
||||||
find_fingerprint_nearest(options)
|
find_fingerprint_nearest(options)
|
||||||
else:
|
else:
|
||||||
find_fingerprint_similar(options)
|
find_fingerprint_similar(options)
|
||||||
|
|||||||
Reference in New Issue
Block a user