Forum

Author Topic: Create N-files with .psx extension  (Read 10600 times)

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Create N-files with .psx extension
« on: February 20, 2017, 06:20:02 PM »
Hello,

I created a script in python to do a process but my script works on files with .psx with photos already imported in the file.

So , the question is , is there a way to automatically create n-files in .psx and add each time some photos from each folder?

For example, we have folders 1 to 100, each folder contains photos. I would like to create 100 .psx files (named 1.psx then 2.psx .... etc) where each .psx file contains photos from folder 1 for 1.psx , 2 for 2.psx ...etc 

Best regards,
Laurent Bitard

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15363
    • View Profile
Re: Create N-files with .psx extension
« Reply #1 on: February 20, 2017, 06:22:54 PM »
Hello Laurent,

In the neighboring thread we are trying to solve that with another user:
http://www.agisoft.com/forum/index.php?topic=6547.msg31638#msg31638
Best regards,
Alexey Pasumansky,
Agisoft LLC

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #2 on: February 20, 2017, 06:37:02 PM »
Thank you for you quick answer !

It's not  exactly the same but I will try to inspire myself with this topic !

Best ,
Laurent

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15363
    • View Profile
Re: Create N-files with .psx extension
« Reply #3 on: February 20, 2017, 06:53:15 PM »
Hello Laurent,

Seems to be just a nested loop: going through all the folders in the "master folder" and load the images from each found folder to a separate document (project).
Best regards,
Alexey Pasumansky,
Agisoft LLC

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #4 on: February 21, 2017, 12:06:35 PM »
t
« Last Edit: February 22, 2017, 04:38:51 PM by Laurent Bitard »

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #5 on: February 22, 2017, 11:17:50 AM »
Hello Alexey,

Yes it is a nested loop ! But it's more difficult to apply. There is my "code" but I don't know how to do my loops for into theses instruction because I must rename each .psx .

Code: [Select]
import os
import sys
import PhotoScan

doc = PhotoScan.app.document
chunk = doc.addChunk()

# Choix des chemins
Path_Photos = PhotoScan.app.getExistingDirectory("""D:\\1 - PFE_BITARD_PSM\\Blocs_Photoscan\\Gros_blocs\\2 - PHOTOS""")
Path_Photos += "\\"
Path_Project = PhotoScan.app.getExistingDirectory("""D:\\1 - PFE_BITARD_PSM\\Blocs_Photoscan\\Gros_blocs\1 - PHOTOSCAN\\4 - Projets""")
Path_Project += "\\"


dossier_list = os.listdir(Path_Photos)
dossier_list = list()

for i in dossier_list:
# Checking save filename
Path_Project = PhotoScan.app.getSaveFileName("""Spécifiez le nom du projet à enregistrer : """)


if Path_Project[-4:].lower() != ".psz":
Path_Project += ".psz"

# Add Photos to Project

image_list = os.listdir(Path_Photos)
photo_list = list()
for photo in image_list:
if photo.rsplit(".",1)[1].upper() in ["JPG", "JPEG", "TIF", "PNG"]:
photo_list.append(path_photos + photo)
print(photo)
else:
print("""Pas de photo exploitable dans le dossier.""")
print(photo_list)
chunk.addPhotos(photo_list)
PhotoScan.app.update()

doc.save(Path_Project)

Thanks in advance,
Best,
Laurent

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15363
    • View Profile
Re: Create N-files with .psx extension
« Reply #6 on: February 22, 2017, 03:13:56 PM »
Hello Laurent,

I could suggest something like the following. The script should look for all folders in "../2 - PHOTOS/" directory, create the separate project for each of such folders, fill the project chunk with the photos from the folder and save the project to "/1 - PHOTOSCAN/4 - Projects/" directory.

Code: [Select]
import PhotoScan, os

doc = PhotoScan.app.document

# Choix des chemins
Path_Photos = "D://1 - PFE_BITARD_PSM/Blocs_Photoscan/Gros_blocs/2 - PHOTOS/"
Path_Project = "D://1 - PFE_BITARD_PSM/Blocs_Photoscan/Gros_blocs/1 - PHOTOSCAN/4 - Projects/"

folders_list = os.listdir(Path_Photos)
for folder in folders_list:

if os.path.isdir(folders_list + folder):

new_doc = PhotoScan.Document()
new_doc.save(Path_Project + folder + ".psz")

image_list = os.listdir(Path_Photos + folder)
photo_list = list()

for photo in image_list:
if photo.rsplit(".",1)[1].upper() in ["JPG", "JPEG", "TIF", "TIFF", "PNG"]:
photo_list.append(path_photos + folder + "/" + photo)
# print(photo)
else:
print("as de photo exploitable dans le dossier.")
print(photo_list)

chunk = new_doc.addChunk()
chunk.addPhotos(photo_list)
new_doc.save()
print("document saved to " + Path_Project + folder + ".psz")

print("finished")

Best regards,
Alexey Pasumansky,
Agisoft LLC

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #7 on: February 22, 2017, 04:18:51 PM »
Hi Alexey,

Thank you for your answer ! It seems to be nice but I have try to run it and it send me an error.

(I have change path because Photoscan hate space and "-" in directory")

Current Code
Code: [Select]
import PhotoScan, os

doc = PhotoScan.app.document

# Choix des chemins
Path_Photos = "D://1_PFE_BITARD_PSM/Blocs_Photoscan/Gros_blocs/2_PHOTOS/"
Path_Project = "D://1_PFE_BITARD_PSM/Blocs_Photoscan/Gros_blocs/1_PHOTOSCAN/4_Projets/"

folders_list = os.listdir(Path_Photos)

for folder in folders_list:

if os.path.isdir(folders_list + folder):

new_doc = PhotoScan.Document()
new_doc.save(Path_Project + folder + ".psz")

image_list = os.listdir(Path_Photos + folder)
photo_list = list()

for photo in image_list:
if photo.rsplit(".",1)[1].upper() in ["JPG", "JPEG", "TIF", "TIFF", "PNG"]:
photo_list.append(path_photos + folder + "/" + photo)
# print(photo)
else:
print("Pas de photo exploitable dans le dossier.")
print(photo_list)

chunk = new_doc.addChunk()
chunk.addPhotos(photo_list)
new_doc.save()
print("document saved to " + Path_Project + folder + ".psz")

print("finished")

Laurent

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #8 on: February 22, 2017, 05:13:17 PM »
Hi Alexey ,

I searched the way to fix it and it's ok the program run perfectly !!

Thank You a lot for your help !

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15363
    • View Profile
Re: Create N-files with .psx extension
« Reply #9 on: February 22, 2017, 05:39:47 PM »
Hello Laurent,

It should be "Path_Photos + folder" instead of "folders_list + folder", sorry.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Laurent Bitard

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Create N-files with .psx extension
« Reply #10 on: February 22, 2017, 05:42:25 PM »
Yes it was that ! Thank you a lot Alexey !