用于创建marzipano场景的脚本

时间:2017-01-25 16:12:45

标签: python windows loops imagemagick

这是编写后的脚本,感谢帮助过的人。

代码是在python 2中创建的,需要安装python 2才能运行。

你还需要imagemagick,这样软件才能完成关卡。

你可以更改文件夹,但它基本上需要从C:\ 360 \ images_folder \ project_name \ cubefotos * .jpg< - 每个具有此格式的文件的360张照片中获取6个cubefotos。

如果您的电脑无法运行代码,因为使用了ram和cpu,请尝试替换每个" subprocess.Popen"使用" subprocess.call" < - 没有引号

# -*- coding: utf-8 -*-
#Importing libraries
import os, sys
import glob
import subprocess
import shutil
from datetime import datetime, date, time, timedelta
from time import gmtime, strftime

#store and print starting time.
hi =  datetime.now()
print " starting time: " + str(hi) + "\n"

project = 'name of your project'
print 'C:\\360\\testing\\'+project+'\\tiles'
try:
    shutil.rmtree('C:\\360\\testing\\'+project+'\\tiles')
except:
    os.makedirs('C:\\360\\testing\\'+project+'\\tiles')


#Creation of a list of every file in the directory 
data = glob.glob('C:\\360\\images_folder\\'+project+'\\cubefotos\\*.jpg')


#Set the numbers of folders to be created
le = len(data)
llen = le // 6

#list of faces
innf = ['b', 'd', 'f', 'l', 'r', 'u']

#Start creating folders and subfolders

#First loop: "Global loop" creates root folder for the total "scene" necessary
for i in range(0, llen):
    os.makedirs('C:\\360\\testing\\'+project+'\\tiles\\' + str(i))
    #Second loop: creates levels for the scenes
    for l in range(1, 4):

        os.makedirs(os.path.join('C:\\360\\testing\\'+project+'\\tiles', str(i), str(l)))

        #Thrid loop: creates faces subfolders
        for e in innf:
            os.makedirs(os.path.join('C:\\360\\testing\\'+project+'\\tiles', str(i), str(l), str(e)))

            #Conditionals: Creates necessary subfolders for each level
            #Level one condition
            if l == 1:
                os.makedirs(os.path.join('C:\\360\\testing\\'+project+'\\tiles', str(i), str(l), str(e), str(0)))
            #Level two condition
            elif l == 2:
                for f in range(0, 2):
                    os.makedirs(os.path.join('C:\\360\\testing\\'+project+'\\tiles', str(i), str(l) ,str(e), str(f)))

            #Level three condition
            elif l == 3:
                for d in range(0, 4):
                    os.makedirs(os.path.join('C:\\360\\testing\\'+project+'\\tiles', str(i), str(l), str(e), str(d)))

#Prints time it took to create folder structure
subprocess.Popen("echo Folders were created in:  " + str(datetime.now() - hi), shell=True)
archivo = 0
temp=0
for i in range(0, llen):
    print "······FOLDER······: " + str(i)
    temp=i*6
    #archivo=0
    #Second loop: creates levels for the scenes
    for l in range(1, 4):
        subprocess.Popen("echo level " + str(l), shell=True)
        #Create and organize images for level 1
        for it in range(0, 6):
            varin = data[i+it]
            v2 = varin[0: 42]
            archivo = it+temp
            #print file
            subprocess.Popen("echo file number: ", shell=True)



            subprocess.Popen("echo face " + str(it), shell=True)
            if int(it) == 0:
                face ='f'
            elif int(it) == 1:
                face ='r'
            elif int(it) == 2:
                face ='b'
            elif int(it) == 3:
                face ='l'
            elif int(it) == 4:
                face ='u'
            elif int(it) == 5:
                face ='d'


            #Normalized paths
                #level 1
            l1 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '1', face, '0', '0.jpg') )
                #level 2
            l20 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '2', face, '0', '0.jpg') )
            l21 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '2', face, '0', '1.jpg') )
            l22 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '2', face, '1', '0.jpg') )
            l23 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '2', face, '1', '1.jpg') )
                #level 3
            l300 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '0', '0.jpg') )
            l301 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '0', '1.jpg') )
            l302 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '0', '2.jpg') )
            l303 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '0', '3.jpg') )
            l310 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '1', '0.jpg') )
            l311 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '1', '1.jpg') )
            l312 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '1', '2.jpg') )
            l313 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '1', '3.jpg') )
            l320 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '2', '0.jpg') )
            l321 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '2', '1.jpg') )
            l322 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '2', '2.jpg') )
            l323 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '2', '3.jpg') )
            l330 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '3', '0.jpg') )
            l331 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '3', '1.jpg') )
            l332 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '3', '2.jpg') )
            l333 = os.path.normpath(os.path.join('C:\\360\\testing\\'+project+'\\tiles\\', str(i), '3', face, '3', '3.jpg') )


            #check faces for their individual processing requirements

            if it == 4:
                #level 1
                subprocess.Popen("convert " + data[archivo] + " -resize 25%% -rotate 180 " + str(l1) , shell=True)

                #level2
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+0+0 " + str(l20) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+512+0 " + str(l21) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+0+512 " + str(l22) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+512+512 " + str(l23) , shell=True)

                #level3
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+0 " + str(l300) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+0 " + str(l301) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+0 " + str(l302) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+0 " + str(l303) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+512 " + str(l310) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+512 " + str(l311) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+512 " + str(l312) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+512 " + str(l313) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+1024 " + str(l320) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+1024 " + str(l321) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+1024 " + str(l322) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+1024 " + str(l323) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+1536 " + str(l330) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+1536 " + str(l331) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+1536 " + str(l332) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+1536 " + str(l333) , shell=True)


            if it == 5:
                #level 1
                subprocess.Popen("convert " + data[archivo] + " -resize 25%% -rotate 180 " + str(l1) , shell=True)

                #level2
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+0+0 " + str(l20) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+512+0 " + str(l21) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+0+512 " + str(l22) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -rotate 180 -crop 512x512+512+512 " + str(l23) , shell=True)

                #level3
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+0 " + str(l300) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+0 " + str(l301) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+0 " + str(l302) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+0 " + str(l303) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+512 " + str(l310) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+512 " + str(l311) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+512 " + str(l312) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+512 " + str(l313) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+1024 " + str(l320) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+1024 " + str(l321) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+1024 " + str(l322) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+1024 " + str(l323) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+0+1536 " + str(l330) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+512+1536 " + str(l331) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -rotate 180 -crop 512x512+1024+1536 " + str(l332) , shell=True)
                subprocess.call("convert " + data[archivo] + " -rotate 180 -crop 512x512+1536+1536 " + str(l333) , shell=True)


                #print time it takes to process each scene
                subprocess.Popen("echo " + str(datetime.now() - hi), shell=True)

            if it != 4 and it != 5:
                #level 1
                subprocess.Popen("convert " + data[archivo] + " -resize 25%% " + str(l1) , shell=True)

                #level 2
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -crop 512x512+0+0 " + str(l20) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -crop 512x512+512+0 " + str(l21) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -crop 512x512+0+512 " + str(l22) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -resize 50%% -crop 512x512+512+512 " + str(l23) , shell=True)

                #leve 3
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+0+0 " + str(l300) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+512+0 " + str(l301) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1024+0 " + str(l302) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1536+0 " + str(l303) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+0+512 " + str(l310) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+512+512 " + str(l311) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1024+512 " + str(l312) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1536+512 " + str(l313) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+0+1024 " + str(l320) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+512+1024 " + str(l321) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1024+1024 " + str(l322) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1536+1024 " + str(l323) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+0+1536 " + str(l330) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+512+1536 " + str(l331) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1024+1536 " + str(l332) , shell=True)
                subprocess.Popen("convert " + data[archivo] + " -crop 512x512+1536+1536 " + str(l333) , shell=True)



#prints time it took the process to finish
print "\n"+ "process finished in: " +str(datetime.now() - hi)

1 个答案:

答案 0 :(得分:0)

专注于您的要求:

子流程帮助页面:Python 3.6

在python 2.7中,你想打电话:

subprocess.Popen([application_path, arg1, arg2, ...])

如果您使用的是python 3,那么您应该使用run而不是Popen

subprocess.run([application_path, arg1, arg2, ...])
相关问题