nearest color search for files
This commit is contained in:
@@ -33,7 +33,7 @@ def setup_options():
|
||||
parser.add_argument("--measure",action="store_true",dest="measure",default=False,
|
||||
help="Measure various statistics for similarity/color searches. This option will flip the 'Add new files' option. [%(default)s]")
|
||||
parser.add_argument("--nearest",type=str,dest="nearestcolor",default=False,
|
||||
help="Search list for nearest mean color. format: R,G,B in float 0-1. Add fourth value to limit search to number")
|
||||
help="Search list for nearest ambient color. format: R,G,B in float 0-1. Add fourth value to limit search to number of hits. Also accepts format file,hits to find nearest color to given file.")
|
||||
parser.add_argument("--dup",action="store_true",dest="duplicate",default=False,
|
||||
help="Return a list of duplicate files, based on hashes. This option will flip the 'Add new files' option. [%(default)s]")
|
||||
parser.add_argument("--del",action="store_true",dest="deleteFiles",default=False,
|
||||
@@ -274,9 +274,54 @@ def find_color_nearest(opts):
|
||||
hits[c][4]))
|
||||
if opts.viewer:
|
||||
fnames=[x[0] for x in hits]
|
||||
subprocess.call(opts.viewer.replace('%f', " ".join(fnames)), shell=True)
|
||||
call_viewer(opts, fnames)
|
||||
return
|
||||
|
||||
def find_color_nearest_file(opts):
|
||||
""" Find closest matching images to given files with RGB color """
|
||||
cmp=opts.nearestcolor.rsplit(",",1)
|
||||
if len(cmp)==1:
|
||||
thr=1
|
||||
else:
|
||||
thr=int(cmp[1])
|
||||
cmp=cmp[0]
|
||||
conn=sqlite3.connect(opts.sqlfile)
|
||||
conn.text_factory=str
|
||||
db=conn.cursor()
|
||||
if is_listed(db, cmp):
|
||||
db1.execute("SELECT file,fingerprint,sharpness,width,height,BR,BG,BB FROM list WHERE file=?",(cmp,))
|
||||
for hit1 in db:
|
||||
fp=int(hit1[1])
|
||||
sp=hit1[2]
|
||||
dims=hit1[3:5]
|
||||
src=hit1[5:8]
|
||||
else:
|
||||
fp=int(get_fingerprint(cmp))
|
||||
sp=get_sharpness(cmp)
|
||||
dims=get_dims(cmp)
|
||||
src=get_colors(cmp)[1]
|
||||
src=[float(i) for i in src]
|
||||
db.execute("SELECT file, ABS(BR-?)+ABS(BG-?)+ABS(BB-?) as K,BR,BG,BB FROM list ORDER BY K LIMIT ?",
|
||||
(src[0],src[1],src[2],thr))
|
||||
hits=[]
|
||||
for hit in db:
|
||||
if hit[0]==cmp:
|
||||
continue
|
||||
hits.append(hit)
|
||||
|
||||
file_len=str(max([len(x[0]) for x in hits]))
|
||||
for c in range(len(hits)):
|
||||
print( ('{: <'+file_len+'} D {:.2f} (RGB {:.2f},{:.2f},{:.2f})').format(hits[c][0],
|
||||
hits[c][1],
|
||||
hits[c][2],
|
||||
hits[c][3],
|
||||
hits[c][4]))
|
||||
if opts.viewer:
|
||||
fnames=[x[0] for x in hits]
|
||||
call_viewer(opts, fnames)
|
||||
return
|
||||
|
||||
|
||||
def get_colors(filename):
|
||||
small_args=['convert','-define','jpeg:size=64x64',filename+'[0]','-resize','10x10!','TEXT:-']
|
||||
p=subprocess.Popen(small_args,stdout=subprocess.PIPE)
|
||||
@@ -627,7 +672,11 @@ def main():
|
||||
print('Random lists...')
|
||||
random_lists(options.sqlfile)
|
||||
if options.nearestcolor:
|
||||
if os.path.exists(options.nearestcolor.rsplit(",")[0]):
|
||||
find_color_nearest_file(options)
|
||||
else:
|
||||
find_color_nearest(options)
|
||||
|
||||
if options.similarity!=None:
|
||||
if os.path.exists(options.similarity.rsplit(",")[0]):
|
||||
find_fingerprint_nearest(options)
|
||||
|
||||
Reference in New Issue
Block a user