Commit a9c0950a authored by Jonathan Barés's avatar Jonathan Barés
Browse files

O1 for single frame is modified to take random camera motion into account.

parent d8cad196
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Load libraries:
import numpy as np
import os
import glob
import time
import datetime
from PIL import Image
from scipy import misc
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from multiprocessing import Pool
from matplotlib.widgets import RectangleSelector
#Input parameter:
##Number of processor for post-processing parallelization:
NbProc=4
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Rename file and create time vectors:
print('... is sorting pictures')
##Get picutre names:
nam_pict=glob.glob('picture/*.jpg')
##Count the number of pictures in the folder to get the number of kept steps:
NbStp=len(nam_pict)
##Initialise time vector:
timePic=np.zeros(NbStp)
##Create picture vector:
null=os.system('mkdir pictureWh')
##Loop over picture to get their times:
for it in range(len(nam_pict)):
tmp=Image.open(nam_pict[it])._getexif()[36867]
dt_tmp=datetime.datetime.strptime(tmp, '%Y:%m:%d %H:%M:%S')
timePic[it]=time.mktime(dt_tmp.timetuple())
##Sort time vector convert in min and save it:
timePic-=np.min(timePic)
Is=np.argsort(timePic)
timePic=timePic[Is]
timePic/=60.
np.savetxt('time.txt',timePic,delimiter='\n')
##Loop over picture to sort and rename them:
for it in range(len(nam_pict)):
os.system('cp '+nam_pict[Is[it]]+' pictureWh/'+str(it).zfill(4)+'.jpg')
##Remove picture folder:
os.system('rm -rf picture')
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Rotate pictures:
print('... is rotating pictures')
##Function to rotate pictures:
def RotatePicture(iPct):
print iPct
null=os.system('convert pictureWh/'+'%04d'%iPct+'.jpg -rotate 270 pictureWh/'+'%04d'%iPct+'.jpg')
return 0
##Parallelization of the rotation:
p=Pool(NbProc)
null=p.map(RotatePicture,xrange(NbStp))
p.close()
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Reframe pictures:
##Select the area of interest:
###Waiting:
print raw_input('Is waiting. Press ENTER to move...')
###Open the last picture:
pict1=mpimg.imread('pictureWh/'+'%04d'%(NbStp-1)+'.jpg')
###Define selection functions:
def line_select_callback(eclick,erelease):
global x1, y1, x2, y2
x1,y1=eclick.xdata,eclick.ydata
x2,y2=erelease.xdata,erelease.ydata
def toggle_selector(event):
print(' Key pressed.')
if event.key in ['Q', 'q'] and toggle_selector.RS.active:
print(' RectangleSelector deactivated.')
toggle_selector.RS.set_active(False)
if event.key in ['A', 'a'] and not toggle_selector.RS.active:
print(' RectangleSelector activated.')
toggle_selector.RS.set_active(True)
###Select:
fig,current_ax=plt.subplots()
plt.imshow(pict1,cmap=plt.cm.Greys)
plt.title('select area to consider, close to validate')
toggle_selector.RS=RectangleSelector(current_ax,line_select_callback,drawtype='box',useblit=True,button=[1,3],minspanx=5,minspany=5,spancoords='pixels',interactive=True)
plt.connect('key_press_event',toggle_selector)
plt.show()
plt.close()
##Function to crop the pictures:
def CropPicture(iPct):
global x1, y1, x2, y2
print iPct
###Load pictures:
pict1=misc.imread('pictureWh/'+'%04d'%iPct+'.jpg')
###Crop pictures:
pictF1=pict1[int(y1):int(y2),int(x1):int(x2),:]
###Save picture:
misc.imsave('pictureWh/'+'%04d'%iPct+'.jpg',pictF1)
##Parallelization of the cropping:
print('... is cropping pictures')
p=Pool(NbProc)
null=p.map(CropPicture,xrange(NbStp))
p.close()
#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#~/"\~#
#Create movies:
##Create picture vector:
null=os.system('mkdir tmpWh')
##function to plot the pictures with the time:
def PlotPicture(iPct):
global timePic
print iPct
###Load the time:
t0=timePic[iPct]
h0,m0=divmod(t0,60)
j0,h0=divmod(h0,24)
###Load pictures:
pict1=mpimg.imread('pictureWh/'+'%04d'%iPct+'.jpg')
###Plot picture:
plt.imshow(pict1)
plt.axis('off')
plt.title('%02d'%j0+'days '+'%02d'%h0+'hours - '+str(iPct))
plt.savefig('tmpWh/'+'%04d'%iPct+'.png',dpi=200)
plt.close()
##Parallelization of the cropping:
print('... is plotting pictures')
p=Pool(1)
null=p.map(PlotPicture,xrange(NbStp))
p.close()
##Make movies:
print('... is making the movie')
null=os.system('ffmpeg -r 15 -y -f image2 -i tmpWh/%04d.png -qscale 1 Wh.avi')
##Remove folders:
null=os.system('rm -f -R tmpWh')
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment