Viewing for nearest color
This commit is contained in:
@@ -238,8 +238,10 @@ def append_colors(sqlfile):
|
|||||||
conn.commit()
|
conn.commit()
|
||||||
return
|
return
|
||||||
|
|
||||||
def find_color_nearest(sqlfile,src):
|
def find_color_nearest(opts):
|
||||||
conn=sqlite3.connect(sqlfile)
|
""" Find closest matching images to given RGB color """
|
||||||
|
src=opts.nearestcolor
|
||||||
|
conn=sqlite3.connect(opts.sqlfile)
|
||||||
conn.text_factory=str
|
conn.text_factory=str
|
||||||
db=conn.cursor()
|
db=conn.cursor()
|
||||||
src=[float(i) for i in src.strip().strip('"').split(',')]
|
src=[float(i) for i in src.strip().strip('"').split(',')]
|
||||||
@@ -247,9 +249,20 @@ def find_color_nearest(sqlfile,src):
|
|||||||
src.append(1)
|
src.append(1)
|
||||||
db.execute("SELECT file, ABS(BR-?)+ABS(BG-?)+ABS(BB-?) as K,BR,BG,BB FROM list ORDER BY K LIMIT ?",
|
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],src[3]))
|
(src[0],src[1],src[2],src[3]))
|
||||||
|
hits=[]
|
||||||
for hit in db:
|
for hit in db:
|
||||||
print "%(f)s : D %(d).2f (RGB %(r).2f,%(g).2f,%(b).2f)" % {'f':hit[0],'d':hit[1],
|
hits.append(hit)
|
||||||
'r':hit[2],'g':hit[3], 'b':hit[4]}
|
|
||||||
|
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]
|
||||||
|
subprocess.call(opts.viewer.replace('%f', " ".join(fnames)), shell=True)
|
||||||
return
|
return
|
||||||
|
|
||||||
def get_colors(filename):
|
def get_colors(filename):
|
||||||
@@ -580,7 +593,7 @@ def main():
|
|||||||
print('Random lists...')
|
print('Random lists...')
|
||||||
random_lists(options.sqlfile)
|
random_lists(options.sqlfile)
|
||||||
if options.nearestcolor:
|
if options.nearestcolor:
|
||||||
find_color_nearest(options.sqlfile,options.nearestcolor)
|
find_color_nearest(options)
|
||||||
if options.similarity!=None:
|
if options.similarity!=None:
|
||||||
if os.path.exists(options.similarity):
|
if os.path.exists(options.similarity):
|
||||||
find_fingerprint_nearest(options)
|
find_fingerprint_nearest(options)
|
||||||
|
|||||||
Reference in New Issue
Block a user