In [ ]:
import cv
import cv2
import numpy as np
import matplotlib.pyplot as plt
%matplotlib notebook
In [ ]:
# file path
path = '../Results/Exp8/'
width = 400
height = 400
nFrames = 500
writer = cv2.VideoWriter('%sFeatures.avi' % (path),cv.FOURCC('D','I','V','X'),30.0,(1000,800))
In [ ]:
for f in range(nFrames):
raw = cv2.imread('%scolor/color%03d.png' % (path,f+1),1)
cloud = cv2.imread('%scloud/cloud%03d.png' % (path,f+1),1)
mocap = cv2.imread('%smocap/mocap%03d.png' % (path,f+1),1)
latent = cv2.imread('%slatent/latent%03d.png' % (path,f+1),1)
rawOut = cv2.resize(raw,(width,height),interpolation=cv2.INTER_CUBIC)
cloudOut = cv2.resize(cloud,(width,height),interpolation=cv2.INTER_CUBIC)
mocapOut = cv2.resize(mocap,(width,height),interpolation=cv2.INTER_CUBIC)
latentOut = cv2.resize(latent,(width,height),interpolation=cv2.INTER_CUBIC)
out = np.zeros((2*width,2*height,3), np.uint8)
out[:height,:width,:] = rawOut
out[:height,width:,:] = cloudOut
out[height:,:width,:] = mocapOut
out[height:,width:,:] = latentOut
out = cv2.resize(out,(1000,800),interpolation=cv2.INTER_CUBIC)
writer.write(out)
if f == 50:
cv2.imwrite('Result/Features.png',out)
writer.release()
In [ ]:
# file path
width = 500
height = 400
nFrames = 200
path = '../Results/Exp8/Videos/'
In [ ]:
def createVideo(frames, captures, strings, writer, textPos=(70,55,70,385), window=(25,75,50,450,350,400)):
data = []
for frame,capture,string in zip(frames,captures,strings):
tr = 0
fr = 0
print string
dat = np.zeros((nFrames,height,width,3))
while(capture.isOpened()):
ret, img = capture.read()
if np.any(frame == tr):
output = cv2.resize(img,(width,height))
if string != '':
output[window[0]:window[1],window[2]:window[3],:] = 255
cv2.putText(output,string, (textPos[0],textPos[1]), cv2.FONT_HERSHEY_DUPLEX, 1, (0,0,0))
output[window[4]:window[5],window[2]:window[3],:] = 255
cv2.putText(output,string, (textPos[2],textPos[3]), cv2.FONT_HERSHEY_DUPLEX, 1, (0,0,0))
dat[fr,:,:,:] = output
fr += 1
tr += 1
if ret == False:
break
capture.release()
data.append(dat)
print 'Done!'
# save data to video file
for f in range(nFrames):
out = np.zeros((2*height,2*width,3), np.uint8)
out[:height,:width,:] = data[0][f,:,:,:]
out[height:,:width:,:] = data[1][f,:,:,:]
out[:height,width:,:] = data[2][f,:,:,:]
out[height:,width:,:] = data[3][f,:,:,:]
writer.write(out)
writer.release()
In [ ]:
tracks = []
frames = []
captures = []
shrNum = [2]
posTrs = [3,4]
strings = ['Posture 1: Head:30,Shoulder:100', '', 'Posture 2: Head:45,Shoulder:110', '']
for sNum in shrNum:
writer = cv2.VideoWriter('../Results/Exp8/Posture%d.avi'%(sNum),cv.FOURCC('D','I','V','X'),10.0,(2*width,2*height))
for pTr in posTrs:
tracks.append(np.loadtxt('%sK1S%dP%dT1'%(path,sNum,pTr), delimiter=',', skiprows=1))
nSamples = tracks[-1].shape[0]
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1.avi'%(path,sNum,pTr)))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1Cloud.mp4'%(path,sNum,pTr)))
createVideo(frames,captures,strings,writer,textPos=(65,25),window=(0,40,50,450))
In [ ]:
tracks = []
frames = []
captures = []
shrTrs = [1,2,3,4]
posTrs = [2,1,3,4]
strings = ['Polyster,V-neck', 'Polyster,O-neck', 'Cotton, V-neck', 'Cotton, O-neck']
writer = cv2.VideoWriter('../Results/Exp8/Shirt.avi',cv.FOURCC('D','I','V','X'),10.0,(2*width,2*height))
for sTr,pTr in zip(shrTrs, posTrs):
tracks.append(np.loadtxt('%sK1S%dP%dT1'%(path,sTr,pTr), delimiter=',', skiprows=1))
nSamples = tracks[-1].shape[0]
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1.avi'%(path,sTr,pTr)))
createVideo(frames,captures,strings,writer,textPos=(105,25),window=(0,40,90,410))
In [ ]:
tracks = []
frames = []
captures = []
shrTrs = [1,2,3,4]
posTrs = [2,1,3,4]
strings = ['Polyester, V-neck', 'Polyster, O-neck', 'Cotton, O-neck', 'Cotton, O-neck']
writer = cv2.VideoWriter('../Results/Exp8/ShirtCloud.avi',cv.FOURCC('D','I','V','X'),10.0,(2*width,2*height))
for sTr,pTr in zip(shrTrs, posTrs):
tracks.append(np.loadtxt('%sK1S%dP%dT1'%(path,sTr,pTr), delimiter=',', skiprows=1))
nSamples = tracks[-1].shape[0]
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1Cloud.mp4'%(path,sTr,pTr)))
createVideo(frames,captures,strings,writer,textPos=(105,25),window=(0,40,90,410))
In [ ]:
shrNum = 2
tracks = []
frames = []
captures = []
posTrs = [3,5]
strings = ['Head:30, Shoulder:100', 'Head:30, Shoulder:100',
'Head:45, Shoulder:110', 'Head:45, Shoulder:110']
writer = cv2.VideoWriter('../Results/Exp8/BaxterPos.avi',cv.FOURCC('D','I','V','X'),10.0,(2*width,2*height))
for pTr in posTrs:
tracks.append(np.loadtxt('%sK1S%dP%dT1Bax'%(path,shrNum,pTr), delimiter=',', skiprows=1))
nSamples = tracks[-1].shape[0]
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
frames.append(np.linspace(0, nSamples-1, num=nFrames, dtype=np.int32))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1Bax.avi'%(path,shrNum,pTr)))
captures.append(cv2.VideoCapture('%sK1S%dP%dT1BaxCloud.mp4'%(path,shrNum,pTr)))
createVideo(frames,captures,strings,writer,textPos=(105,25),window=(0,40,90,410))