Forum

Author Topic: for loop image loading [solved]  (Read 6919 times)

nickc

  • Newbie
  • *
  • Posts: 25
    • View Profile
for loop image loading [solved]
« on: February 18, 2015, 07:28:34 PM »
Not sure why this works

Code: [Select]
import PhotoScan
import os
import sys

from PySide.QtGui import QPixmap, QApplication
import time

import getpass
import subprocess


# Get User
username = getpass.getuser()

def Zazzle():

# Define: Home Directory
path = os.getcwd()
print ("Home Directory: ", path)

ImageDirectory = path+"\\raw\\tiff\\"
os.chdir(ImageDirectory)
print ("Image Directory: ", ImageDirectory)

# Set Application Objects
doc = PhotoScan.app.document
print ("Processing Images...")

# Define Chunk
chunk = PhotoScan.app.document.addChunk()
chunk.label = "MainChunk"

# Find Images
ImageFiles = []
for photo in os.listdir (ImageDirectory):
if photo.endswith('.tif'):
ImageFiles.append(photo)

if len(ImageFiles)>0:
print(ImageFiles)
if len(ImageFiles)==0:
print('no images found!')

print("Zazzle Running")
print ("Script Location: C:\Program Files\Agisoft\PhotoScan Pro\scripts")

# Load Image Files into Chunk Camera
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\\model.obj"

#Export Model & Save Doc
chunk.exportModel(modelname,texture_format="tif", texture=True,format="obj")

time.sleep(5)
doc.save("AgisoftProject.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")


But then this does not

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 = 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!')

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")



essentially what im trying to do is to check a directory for subdirectories... each subdirectory would be equal to a new product or sku which would load as an seperate chunk.

here is the console;
Code: [Select]
Agisoft PhotoScan Version: 1.1.2 build 2014 (64 bit)
OpenGL Vendor: ATI Technologies Inc.
OpenGL Renderer: AMD FirePro W7000 (FireGL V)
OpenGL Version: 4.3.12823 Compatibility Profile Context FireGL 13.352.1019.0
Maximum Texture Size: 16384
Quad Buffered Stereo: not enabled
ARB_vertex_buffer_object: supported
ARB_texture_non_power_of_two: supported
Zazzle Menu Added
press r to run
Loading project...
loaded project in 0.016 sec
Finished processing in 0.016 sec (exit code 1)
Home Directory:  C:\Users\nicholas.culpin\Desktop\PhotoGramExample\assets
Script Location: C:\Program Files\Agisoft\PhotoScan Pro\scripts
Output Path:  C:\Users\nicholas.culpin\Desktop\PhotoGramExample\assets\raw\output
skus found: selve
skus found: selveTwo
skus found: Thumbs.db
adding images from directory: C:\Users\nicholas.culpin\Desktop\PhotoGramExample\assets\raw\tiff\selve
['snap_0001.tif', 'snap_0002.tif', 'snap_0003.tif', 'snap_0004.tif', 'snap_0005.tif', 'snap_0006.tif', 'snap_0007.tif', 'snap_0008.tif', 'snap_0009.tif', 'snap_0010.tif', 'snap_0011.tif', 'snap_0012.tif', 'snap_0013.tif', 'snap_0014.tif', 'snap_0015.tif', 'snap_0016.tif', 'snap_0017.tif', 'snap_0018.tif', 'snap_0019.tif', 'snap_0020.tif', 'snap_0021.tif', 'snap_0022.tif', 'snap_0023.tif', 'snap_0024.tif', 'snap_0025.tif', 'snap_0026.tif', 'snap_0027.tif', 'snap_0028.tif', 'snap_0029.tif', 'snap_0030.tif', 'snap_0031.tif', 'snap_0032.tif', 'snap_0033.tif', 'snap_0034.tif', 'snap_0035.tif', 'snap_0036.tif', 'snap_0037.tif', 'snap_0038.tif', 'snap_0039.tif', 'snap_0040.tif', 'snap_0041.tif', 'snap_0042.tif', 'snap_0043.tif', 'snap_0044.tif', 'snap_0045.tif', 'snap_0046.tif', 'snap_0047.tif', 'snap_0048.tif', 'snap_0049.tif', 'snap_0050.tif', 'snap_0051.tif', 'snap_0052.tif', 'snap_0053.tif', 'snap_0054.tif', 'snap_0055.tif', 'snap_0056.tif', 'snap_0057.tif', 'snap_0058.tif', 'snap_0059.tif', 'snap_0060.tif', 'snap_0061.tif', 'snap_0062.tif', 'snap_0063.tif', 'snap_0064.tif', 'snap_0065.tif', 'snap_0066.tif', 'snap_0067.tif', 'snap_0068.tif', 'snap_0069.tif', 'snap_0070.tif', 'snap_0071.tif', 'snap_0072.tif', 'snap_0073.tif', 'snap_0074.tif', 'snap_0075.tif', 'snap_0076.tif', 'snap_0077.tif', 'snap_0078.tif', 'snap_0079.tif', 'snap_0080.tif', 'snap_0081.tif', 'snap_0082.tif', 'snap_0083.tif', 'snap_0084.tif', 'snap_0085.tif', 'snap_0086.tif', 'snap_0087.tif', 'snap_0088.tif', 'snap_0089.tif', 'snap_0090.tif', 'snap_0091.tif', 'snap_0092.tif', 'snap_0093.tif', 'snap_0094.tif', 'snap_0095.tif', 'snap_0096.tif', 'snap_0097.tif', 'snap_0098.tif', 'snap_0099.tif', 'snap_0100.tif', 'snap_0101.tif', 'snap_0102.tif', 'snap_0103.tif', 'snap_0104.tif', 'snap_0105.tif', 'snap_0106.tif', 'snap_0107.tif', 'snap_0108.tif', 'snap_0109.tif', 'snap_0110.tif', 'snap_0111.tif', 'snap_0112.tif', 'snap_0113.tif', 'snap_0114.tif', 'snap_0115.tif', 'snap_0116.tif', 'snap_0117.tif', 'snap_0118.tif', 'snap_0119.tif', 'snap_0120.tif', 'snap_0121.tif', 'snap_0122.tif', 'snap_0123.tif', 'snap_0124.tif', 'snap_0125.tif', 'snap_0126.tif', 'snap_0127.tif', 'snap_0128.tif']
Loading photos...
Can't load photos
Finished processing in 0.015 sec (exit code 0)
Generating masks...
Finished processing in 0 sec (exit code 1)
>>>

thanks!
« Last Edit: February 18, 2015, 08:10:05 PM by nickc »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: for loop image loading
« Reply #1 on: February 18, 2015, 07:35:23 PM »
Hello Nick,

And at what line it stops working correctly?
Best regards,
Alexey Pasumansky,
Agisoft LLC

nickc

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: for loop image loading
« Reply #2 on: February 18, 2015, 07:37:43 PM »
seems like its failing at chunk.addPhotos(imageFiles)

I added the console output to my original post.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: for loop image loading
« Reply #3 on: February 18, 2015, 07:41:16 PM »
Hello Nick,

I think that you need to keep full paths to the images in imageFiles list.
Best regards,
Alexey Pasumansky,
Agisoft LLC

nickc

  • Newbie
  • *
  • Posts: 25
    • View Profile
Re: for loop image loading
« Reply #4 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;

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")
« Last Edit: February 18, 2015, 08:09:49 PM by nickc »