1
Python and Java API / Re: for loop image loading
« on: February 18, 2015, 08:07:16 PM »
ah yes...
current working directory issue. added"os.chdir(ImageDirectory)" after it found the images. thanks!
in case you were curious...here is the updated script;
current working directory issue. added"os.chdir(ImageDirectory)" after it found the images. thanks!
in case you were curious...here is the updated script;
Code: [Select]
import PhotoScan
import os
import sys
from PySide.QtGui import QPixmap, QApplication
import time
import getpass
import subprocess
def Zazzle():
# Define: Home Directory
path = os.getcwd()
print ("Home Directory: ", path)
print ("Script Location: C:\Program Files\Agisoft\PhotoScan Pro\scripts")
print ("Output Path: ", path+"\\raw\\output")
# append all of the sku names to the sku list
skus = []
for directory in os.listdir(path+"\\raw\\tiff"):
skus.append(directory)
print("skus found: "+directory)
for sku in skus:
ImageDirectory = os.path.join(path,"raw","tiff",sku)
# Load Image Files into Chunk Camera
print('adding images from directory: '+ImageDirectory)
# Set Application Objects
doc = PhotoScan.app.document
# Define Chunk
chunk = PhotoScan.app.document.addChunk()
chunk.label = str(sku)
imageFiles = []
for photo in os.listdir (ImageDirectory):
if photo.endswith('.tif'):
imageFiles.append(photo)
else:
print('other file found: ',photo)
if len(imageFiles)>0:
print(imageFiles)
if len(imageFiles)==0:
print('no images found!')
os.chdir(ImageDirectory)
chunk.addPhotos(imageFiles)
chunk.importMasks(path='',method='alpha')
camera = chunk.cameras[0]
# match Photos
chunk.matchPhotos(accuracy=PhotoScan.HighAccuracy,preselection=PhotoScan.GenericPreselection, filter_mask=True)
# align Photos
chunk.alignCameras()
# Build Dense Cloud
chunk.buildDenseCloud(quality=PhotoScan.MediumQuality)
#Build Model
chunk.buildModel(surface=PhotoScan.Arbitrary,interpolation=PhotoScan.EnabledInterpolation)
# Build UVs
chunk.buildUV(mapping=PhotoScan.GenericMapping)
# Build Texture
chunk.buildTexture(blending=PhotoScan.MosaicBlending, size=4096)
# Decimate Model
chunk.decimateModel(100000)
modelname = path+"\\output\\"+sku+".obj"
#Export Model & Save Doc
chunk.exportModel(modelname,texture_format="tif", texture=True,format="obj")
time.sleep(5)
doc.save(sku+".psz")
time.sleep(5)
sys.exit()
quit()
return 1
label = "Zazzle/Run"
PhotoScan.app.addMenuItem(label, Zazzle, "r")
print("Zazzle Menu Added")
print ("press r to run")