def save_mvmtx_tf(self): if self.isnotExist: os.system("mkdir -p result/") self.folder_name += self.args[1] + str(int(time.time())%10000) os.system("mkdir -p result/%s"%(self.folder_name)) print "Created folder name:", os.getcwd(), self.folder_name self.isnotExist = False a = Image.fromarray(self.widget.data) save_file_name = "./result/%s/snapshot%s"%(self.folder_name,str(self.viewer_image_cnt)) a.save(save_file_name+".png") self.viewer_image_cnt += 1
def Make_cinema_source(self): rot_size = 180 for elem in range(rot_size): viewer_trans(-transX, -transY, -self.z_-transZ) viewer_rotate(360.0/rot_size, 0, 10, 0) viewer_trans(transX, transY, self.z_+transZ) #global mmtx #data_pkg = self.func_name(*self.args) #viewer_data, viewer_dtype = collect_result(data_pkg) self.update_widget() a = Image.fromarray(self.widget.data[:,:,0:3]) a.save("./resultsss/result-"+str('%03d'%(self.ret_image_cnt))+".tif") self.ret_image_cnt = self.ret_image_cnt + 1 print str(elem) + " DONE"
# print(new_folder_path) # os.makedirs(new_folder_path) list_im = glob.glob(new_folder_path + "/%s*.jpeg" % uuid_set) print('B') list_im.sort() #sort the file before joining it print('C') imgs = [Img.open(i) for i in list_im] print('D') #now lets Combine several images vertically with Python min_shape = sorted([(np.sum(i.size), i.size) for i in imgs])[0][1] print('E') imgs_comb = np.vstack( (np.asarray(i.resize(min_shape)) for i in imgs)) print('F') # for horizontally change the vstack to hstack imgs_comb = Img.fromarray(imgs_comb) print('G') pathsave = new_folder_path + "MyPdf%s.jpeg" % uuid_set print('H') #now save the image imgs_comb.save(pathsave) print('I') #and then remove all temp image for i in list_im: os.remove(i) print('J') except Exception, err: print err return False return pathsave
def keyPressEvent(self, event): global func_dict_ dummy = None if type(event) == QtGui.QKeyEvent: if event.key() == QtCore.Qt.Key_Escape: self.app.exit() #exit(1) #elif event.key() == QtCore.Qt.Key_A:func_dict['A'](dummy) elif event.key() == QtCore.Qt.Key_A: viewer_trans(0, 0, 50) self.z_ = self.z_ + 50 elif event.key() == QtCore.Qt.Key_B:func_dict['B'](dummy) #elif event.key() == QtCore.Qt.Key_C:func_dict['C'](dummy) elif event.key() == QtCore.Qt.Key_C: self.CRG=0 elif event.key() == QtCore.Qt.Key_D:func_dict['D'](dummy) elif event.key() == QtCore.Qt.Key_E:func_dict['E'](dummy) elif event.key() == QtCore.Qt.Key_F:func_dict['F'](dummy) #elif event.key() == QtCore.Qt.Key_G:func_dict['G'](dummy) elif event.key() == QtCore.Qt.Key_G: self.CRG = 2 elif event.key() == QtCore.Qt.Key_H:func_dict['H'](dummy) #elif event.key() == QtCore.Qt.Key_I:func_dict['I'](dummy) elif event.key() == QtCore.Qt.Key_I: filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') self.loadmmtx(filename) #elif event.key() == QtCore.Qt.Key_J:func_dict['J'](dummy) elif event.key() == QtCore.Qt.Key_J: filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') self.loadinvmmtx(filename) #elif event.key() == QtCore.Qt.Key_K:func_dict['K'](dummy) elif event.key() == QtCore.Qt.Key_K: filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') self.loadtff(filename) elif event.key() == QtCore.Qt.Key_L: #filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') #self.load_mvmtx_tf(filename) filename = QtGui.QFileDialog.getOpenFileName(self, 'Open File', '.') self.loadalpha(filename) #for video #elif event.key() == QtCore.Qt.Key_M:func_dict['M'](dummy) elif event.key() == QtCore.Qt.Key_M: self.Make_cinema_source() elif event.key() == QtCore.Qt.Key_N:func_dict['N'](dummy) #elif event.key() == QtCore.Qt.Key_O:func_dict['O'](dummy) elif event.key() == QtCore.Qt.Key_O: print "KEY OOOOO" self.save_tf_mv() #elif event.key() == QtCore.Qt.Key_P:func_dict['P'](dummy) elif event.key() == QtCore.Qt.Key_P: print "KEY PPPPP" self.load_tf_mv() elif event.key() == QtCore.Qt.Key_Q:func_dict['Q'](dummy) #elif event.key() == QtCore.Qt.Key_R:func_dict['R'](dummy) elif event.key() == QtCore.Qt.Key_R: self.CRG=1 elif event.key() == QtCore.Qt.Key_S: #self.save_mvmtx_tf() a = Image.fromarray(self.widget.data) a.save("./result/result-"+str(self.viewer_image_cnt)+".tif") self.viewer_image_cnt+=1 #elif event.key() == QtCore.Qt.Key_T:func_dict['T'](dummy) elif event.key() == QtCore.Qt.Key_T: global slider_on if slider_on == True: ret_str = '[' for elem in range(8): ret_str += str(self.slider.slider_dict[elem].value()) + ', ' ret_str += ']' print "==============================" print " SLIDER INFORMATION " print "------------------------------" print ret_str print "==============================" #elif event.key() == QtCore.Qt.Key_U:func_dict['U'](dummy) elif event.key() == QtCore.Qt.Key_U: self.update_widget() elif event.key() == QtCore.Qt.Key_V:func_dict['V'](dummy) elif event.key() == QtCore.Qt.Key_W:func_dict['W'](dummy) elif event.key() == QtCore.Qt.Key_X:func_dict['X'](dummy) elif event.key() == QtCore.Qt.Key_Y:func_dict['Y'](dummy) elif event.key() == QtCore.Qt.Key_Z:func_dict['Z'](dummy) else: event.ignore() self.update_widget()
def multiple_avi(args): """ Generate avi from multiple cinefiles INPUT ----- args : Namespace object contain each of the arguments used to generate an avi. See the top of this file for details, or from a terminal cine2avi --help OUTPUT ----- None """ if args.timestamp: print(os.path.join(script_dir, 'Helvetica.ttf')) #font = ImageFont.truetype(args.font, args.ts) files = args.cines #for i, fn in enumerate(files): fn = files[0].strip() frame_slice = slice(None) if '[' in fn: if fn[-1] == ']': fn, s = fn.split('[') try: frame_slice = slice(*map(noneint, s[:-1].split(':'))) except: raise ValueError("Couldn't convert '[%s' to slice notation" % s) else: print "Warning, found '[' in input, but it didn't end with ']', so I'll assume you didn't mean to give a frame range." base, ext = os.path.splitext(fn) ext = ext.lower() if not os.path.exists(fn): print "File %s not found, ignoring." % fn # continue output = args.output if '%s' in args.output: output = output % base elif '%' in args.output: output = output % i base, extout = os.path.splitext(output) output = output[:-6] + '_multiple' + extout print(output) bpp = None inp = [None for fn in files] if ext in ('.cin', '.cine'): inp_ref = cine.Cine(fn) for i, fn in enumerate(files): print(fn) fn = fn.strip() inp[i] = cine.Cine(fn) bpp = inp_ref.real_bpp if bpp < 8 or bpp > 16: bpp = None #Just in case td = args.td if args.td else int(ceil(log10(inp_ref.frame_rate))) t0 = 0. frame_text = lambda i: 't: %%.%df s, ' % td % (inp_ref.get_time( i) - t0) + 'Dt: %f ms' % (round( ((inp_ref.get_time(i) - inp_ref.get_time(i - 1)) * 1000) * 10) / 10) # 't: %f s \n Dt : ms' % elif ext in ('.tif', '.tiff'): inp = tiff.Tiff(fn) frame_text = lambda i: str(i) bpps = inp_ref[0].dtype.itemsize * 8 if bpp is None: bpp = bpps lengths = [len(i) for i in inp] print('Movie lengths :' + str(lengths)) Nmax = min(lengths) frames = range(*frame_slice.indices(Nmax)) if args.clip == 0: mappa = linspace(0., 2.**(bpps - bpp), 2**bpps) else: counts = 0 bins = arange(2**bpps + 1) for i in frames[::args.hist_skip]: c, b = histogram(inp_ref[i], bins) counts += c counts = counts.astype('d') / counts.sum() counts = counts.cumsum() bottom_clip = where(counts > args.clip)[0] if not len(bottom_clip): bottom_clip = 0 else: bottom_clip = bottom_clip[0] top_clip = where(counts < (1 - args.clip))[0] if not len(top_clip): top_clip = 2**bpps else: top_clip = top_clip[-1] #print bottom_clip, top_clip #import pylab #pylab.plot(counts) #pylab.show() #sys.exit() m = 1. / (top_clip - bottom_clip) mappa = clip(-m * bottom_clip + m * arange(2**bpps, dtype='f'), 0, 1) mappa = mappa**(1. / args.gamma) mappa = clip(mappa * 255, 0, 255).astype('u1') #print '%s -> %s' % (fn, output) ofn = output output = mjpeg.Avi(output, framerate=args.framerate, quality=args.quality) if args.rect is not None: rect = [int(i) for i in args.rect[1:-1].split(':')] print(rect) #print frames for i in StatusPrinter(frames, os.path.basename(ofn)): frame = [None for p in inp] for p, inpp in enumerate(inp): framep = inpp[i] if args.rotate: framep = rot90(framep, (args.rotate % 360) // 90) framep = mappa[framep] # print(type(frame)) if args.rect == None: frame[p] = asarray(framep) else: frame[p] = asarray(framep[rect[0]:rect[1], rect[2]:rect[3]]) fra = concatenate(tuple(frame), axis=0) if args.timestamp: fra = image.fromarray(fra) #draw = ImageDraw.Draw(fra) #draw.text((args.tx, args.ty), frame_text(i), font=font, fill=args.tb) fra = asarray(fra) # print(type(frame)) # plt.imshow(fra) # plt.show() # input() output.add_frame(fra) output.close()
def single_avi(args): if args.timestamp: print(os.path.join(script_dir, 'Helvetica.ttf')) #font = ImageFont.truetype(args.font, args.ts) for i, fn in enumerate(args.cines): fn = fn.strip() frame_slice = slice(None) if '[' in fn: if fn[-1] == ']': fn, s = fn.split('[') liste = [int(i) for i in s[:-1].split(':')] print(liste) #try: frame_slice = slice(liste[0], liste[1], liste[2]) # frame_slice = slice(*map(noneint, liste)) #frame_slice = slice(liste) #except: # raise ValueError("Couldn't convert '[%s' to slice notation" % s) else: print "Warning, found '[' in input, but it didn't end with ']', so I'll assume you didn't mean to give a frame range." base, ext = os.path.splitext(fn) ext = ext.lower() if not os.path.exists(fn): print "File %s not found, ignoring." % fn continue output = args.output if '%s' in args.output: output = output % base elif '%' in args.output: output = output % i bpp = None if ext in ('.cin', '.cine'): inp = cine.Cine(fn) bpp = inp.real_bpp if bpp < 8 or bpp > 16: bpp = None #Just in case td = args.td if args.td else int(ceil(log10(inp.frame_rate))) # frame_text = lambda i: 't: %%.%df s' % td % (i/float(input.frame_rate)) # frame_text = lambda i: 't: %%.%d s' % (inp.get_time(i)) t0 = 0. frame_text = lambda i: 't: %%.%df s, ' % td % (inp.get_time( i) - t0) + 'Dt: %f ms' % (round( ((inp.get_time(i) - inp.get_time(i - 1)) * 1000) * 10) / 10 ) # 't: %f s \n Dt : ms' % elif ext in ('.tif', '.tiff'): inp = tiff.Tiff(fn) frame_text = lambda i: str(i) bpps = inp[0].dtype.itemsize * 8 if bpp is None: bpp = bpps frames = range(*frame_slice.indices(len(inp))) if args.clip == 0: mappa = linspace(0., 2.**(bpps - bpp), 2**bpps) else: counts = 0 bins = arange(2**bpps + 1) for i in frames[::args.hist_skip]: c, b = histogram(inp[i], bins) counts += c counts = counts.astype('d') / counts.sum() counts = counts.cumsum() bottom_clip = where(counts > args.clip)[0] if not len(bottom_clip): bottom_clip = 0 else: bottom_clip = bottom_clip[0] top_clip = where(counts < (1 - args.clip))[0] if not len(top_clip): top_clip = 2**bpps else: top_clip = top_clip[-1] #print bottom_clip, top_clip #import pylab #pylab.plot(counts) #pylab.show() #sys.exit() m = 1. / (top_clip - bottom_clip) mappa = clip(-m * bottom_clip + m * arange(2**bpps, dtype='f'), 0, 1) mappa = mappa**(1. / args.gamma) mappa = clip(mappa * 255, 0, 255).astype('u1') #print '%s -> %s' % (fn, output) ofn = output output = mjpeg.Avi(output, framerate=args.framerate, quality=args.quality) if args.rect is not None: rect = [int(i) for i in args.rect[1:-1].split(':')] print(rect) #print frames for i in StatusPrinter(frames, os.path.basename(ofn)): frame = inp[i] if args.rotate: frame = rot90(frame, (args.rotate % 360) // 90) frame = mappa[frame] # if args.rect == None: frame = asarray(frame) else: frame = asarray(frame[rect[0]:rect[1], rect[2]:rect[3]]) if args.timestamp: frame = image.fromarray(frame) #draw = ImageDraw.Draw(frame) #draw.text((args.tx, args.ty), frame_text(i), font=font, fill=args.tb) frame = asarray(frame) # print(type(frame)) output.add_frame(frame) output.close()
from skimage import io import matplotlib.pyplot as plt import numpy as np def detect_faces(image): # Create a face detector face_detector = dlib.get_frontal_face_detector() # Run detector and get bounding boxes of the faces on image. detected_faces = face_detector(image, 1) face_frames = [(x.left(), x.top(), x.right(), x.bottom()) for x in detected_faces] return face_frames # Load image img_path = '/Users/tejus/Downloads/group-booking.jpg' image = io.imread(img_path) # Detect faces detected_faces = detect_faces(image) # Crop faces and plot for n, face_rect in enumerate(detected_faces): face = image.fromarray(image).crop(face_rect) plt.subplot(1, len(detected_faces), n + 1) plt.axis('off') plt.imshow(face)