Skip to content

Instantly share code, notes, and snippets.

@nv1t
Created January 9, 2018 07:01
Show Gist options
  • Save nv1t/939933a712ed6b5af4e1b1b46da5d57b to your computer and use it in GitHub Desktop.
Save nv1t/939933a712ed6b5af4e1b1b46da5d57b to your computer and use it in GitHub Desktop.
Sort Picture with OpenCV as Display (not automaticaly)
import numpy as np
import sys
import os
import cv2
import shutil
log = open('log.txt','a')
img = cv2.imread(sys.argv[1],1)
origimg = img
height, width, channels = img.shape
font = cv2.FONT_HERSHEY_SIMPLEX
cv2.putText(img,sys.argv[1],(10,200), font, 3,(255,255,255),7,cv2.LINE_AA)
cv2.putText(img,sys.argv[1],(0,200), font, 3,(0,0,0),7,cv2.LINE_AA)
maxHeight=700
maxWidth=700
if height > width:
h = maxHeight
w = int((maxHeight/height)*width)
else:
w = maxWidth
h = int((maxWidth/width)*height)
imS = cv2.resize(img, (w, h))
cv2.namedWindow("image", cv2.WND_PROP_FULLSCREEN)
cv2.setWindowProperty("image", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)
cv2.imshow('image',imS)
k = cv2.waitKey(0)
#13 keep
#120 delete
if k == 120:
log.write("L - %s\n" % (sys.argv[1]))
os.remove(sys.argv[1])
elif k == 13:
log.write("K - %s\n" % (sys.argv[1]))
filename = os.path.dirname(sys.argv[1])
i = 0
while os.path.isfile("../sorted/%s_%s.jpg" % (filename,i)):
i+=1
fname = "../sorted/%s_%s.jpg" % (filename,i)
shutil.copy(sys.argv[1],fname)
print(k)
log.close()
cv2.destroyAllWindows()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment