viewer defaults

This commit is contained in:
ville rantanen
2014-05-23 11:02:18 +03:00
parent 1ecbc9edba
commit dab46ee12b

View File

@@ -42,11 +42,15 @@ def setup_options():
help="Return a list of small files, smaller than -m INT. This option will flip the 'Add new files' option. [%(default)s]")
parser.add_argument("--similar",type=str,dest="similarity",default=None,
help="Search list for similar images. Value 0-255 for similarity threshold. 0=high similarity. "+
"If value is a filename, search similar to that image. Append with ,value to prevent printing of too ddeiffering images")
"If value is a filename, search similar to that image. "+
"Append with ',value' to limit similarity. "+
"The output columns: SD SimilarityDiff., CD ColorDiff., "+
"RD AspectRatioDiff.,Shp SharpnessIndex.")
parser.add_argument("--viewer",type=str,dest="viewer",default=None,
help="Program to view images, %%f refers to filename(s)")
help="Program to view images, %%f refers to filename(s)."+
"If '1', defaults to: 'geeqie -l %f'")
parser.add_argument("-x",action="append",dest="exclude",default=[],
help="Exclude folder name from the lists. This option may be issued several times")
help="Exclude folder name from the lists. This option may be issued several times.")
parser.add_argument('startpath', action="store",default='.', nargs='?')
options=parser.parse_args()
@@ -212,6 +216,14 @@ def get_dims(filename):
out, err = p.communicate()
return (out.strip().split('x'))
def call_viewer(opts, files):
""" Runs the viewer program, contains defaults """
if opts.viewer=="1":
opts.viewer="geeqie -l %f"
devnull = open('/dev/null', 'w')
subprocess.call(opts.viewer.replace('%f', " ".join(files)), stderr=devnull, shell=True)
def append_colors(sqlfile):
conn=sqlite3.connect(sqlfile)
conn.text_factory=str
@@ -285,6 +297,16 @@ def get_colors(filename):
border=[float(i) for i in border.strip().strip('"').split(',')]
return (mean,border)
def get_color_diff(c1,c2):
""" Return color difference from two RGB triplets """
return abs( c1[0] - c2[0] )+abs( c1[1] - c2[1] )+abs( c1[2] - c2[2] )
def get_ratio_diff(d1,d2):
""" Return ratio difference from two w,h dimension tuplets """
return abs( float(d1[0])/float(d1[1]) - float(d2[0])/float(d2[1]) )
def append_fingerprints(sqlfile):
conn=sqlite3.connect(sqlfile)
conn.text_factory=str
@@ -345,7 +367,7 @@ def find_fingerprint_similar(opts):
pixels=dims[0]*dims[1]
colors=hit1[5:8]
db2.execute("SELECT file,fingerprint,sharpness,width,height,R,G,B FROM list WHERE sharpness > 0 ORDER BY file")
this1=[ [cmp, 0,sp,int(hit1[3]),int(hit1[4]),0,pixels] ]
this1=[ [cmp, 0,sp,int(hit1[3]),int(hit1[4]),0,pixels,0] ]
for hit2 in db2:
if hit2[0]==cmp:
continue
@@ -353,8 +375,9 @@ def find_fingerprint_similar(opts):
if similarity<thr:
this2=[hit2[0], similarity, hit2[2],
int(hit2[3]),int(hit2[4]),
abs( hit2[5] - colors[0] )+abs( hit2[6] - colors[1] )+abs( hit2[7] - colors[2] ),
int(hit2[3])*int(hit2[4])]
get_color_diff(hit2[5:8],colors),
int(hit2[3])*int(hit2[4]),
get_ratio_diff(hit2[3:5],dims)]
this1.append(this2)
hit_list.append(hit2[0])
this1.sort(key=lambda x: x[1])
@@ -368,13 +391,14 @@ def find_fingerprint_similar(opts):
for src in hits:
file_len=str(max([len(x[0]) for x in src]))
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: ^5}x{: ^5}').format("File","Diff","CDel","Shrp","Wth","Hgt"))
print( ('{: <'+file_len+'} {: ^4} {: ^4} {: ^4} {: ^4} {: ^5}x{: ^5}').format("File","SD","CD","RD","Shp","W","H"))
for c in range(len(src)):
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: >5}x{: >5}').format(src[c][0],src[c][1],"%.2f"%src[c][5],
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: >4} {: >5}x{: >5}').format(src[c][0],src[c][1],
"%.2f"%src[c][5],"%.2f"%src[c][7],
"%.1f" % src[c][2],src[c][3],src[c][4]))
if opts.viewer:
fnames=[x[0] for x in src]
subprocess.call(opts.viewer.replace('%f', " ".join(fnames)), shell=True)
call_viewer(opts, fnames)
return
@@ -414,8 +438,8 @@ def find_fingerprint_nearest(opts):
this[2]=hit1[2]
this[3]=int(hit1[3])
this[4]=int(hit1[4])
this[5]=abs( hit1[5] - colors[0] )+abs( hit1[6] - colors[1] )+abs( hit1[7] - colors[2] )
this[6]= (this[3]/float(this[4])) / (float(dims[0])/float(dims[1]))
this[5]=get_color_diff(colors, hit1[5:8]) #abs( hit1[5] - colors[0] )+abs( hit1[6] - colors[1] )+abs( hit1[7] - colors[2] )
this[6]=get_ratio_diff(this[3:5], dims)# (this[3]/float(this[4])) / (float(dims[0])/float(dims[1]))
if hit1==None:
print("No measurements found")
sys.exit(1)
@@ -423,12 +447,14 @@ def find_fingerprint_nearest(opts):
print("No similar images for "+cmp+", up to threshold "+str(thr))
return
file_len=str(max(len(cmp), len(this[0])))
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: ^5}x{: ^5}').format("File","Diff","CD","RoR","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} {: >4} {: >5}x{: >5}').format(this[0], this[1],"%.2f"%this[5],"%.3f"%this[6], "%.1f" % this[2],this[3], this[4]))
print( ('{: <'+file_len+'} {: ^4} {: ^4} {: ^4} {: ^4} {: ^5}x{: ^5}').format("File","SD","CD","RD","Shp","W","H"))
print( ('{: <'+file_len+'} {: >4} {: ^4} {: ^4} {: ^4} {: >5}x{: >5}').format(cmp,"","","","%.1f" % sp,dims[0],dims[1]))
print( ('{: <'+file_len+'} {: >4} {: >4} {: >4} {: >4} {: >5}x{: >5}').format(this[0], this[1],"%.2f"%this[5],
"%.2f"%this[6], "%.1f" % this[2],this[3], this[4]))
if opts.viewer:
subprocess.call(opts.viewer.replace('%f', " ".join((cmp,this[0]))), stderr=subprocess.STDOUT, shell=True)
call_viewer(opts, (cmp,this[0]))
def append_sharpness(sqlfile):