Forum

Author Topic: Loading images from subdirectory to cameras groupes  (Read 3108 times)

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Loading images from subdirectory to cameras groupes
« on: December 19, 2017, 02:50:48 PM »
Hi All ,

I have a  main directory with a lot of sub-directories and I would like to load them all  to my PhotoScan chunk with a python script, each sub-directory to new camera group ,   
Iv got some script with create camera group but i have no Idea how to modify it to create new camera group for next sub-dir etc ...
Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()
new_group = chunk.addCameraGroup()

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append("/".join([path_photos, photo]))
chunk.addPhotos(photo_list)
print("- Photos ajoutées")

for camera in list(chunk.cameras):
camera.group = new_group
Did anybody can help pls ?
« Last Edit: December 19, 2017, 03:31:27 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Loading images from subdirectory to cameras groupes
« Reply #1 on: December 19, 2017, 04:00:23 PM »
Hello magic,

You need to look for the directories in the main dir first and then  loop through found folders and apply the previously used method.

I'll try to post the example of such solution shortly.
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Loading images from subdirectory to cameras groupes
« Reply #2 on: December 20, 2017, 12:28:03 PM »
Can You check it Alexey please still cant solve it
Code: [Select]
doc = PhotoScan.app.document
chunk = doc.addChunk()

# Ajout de photos -add photos 1st chunk
path_photos = PhotoScan.app.getExistingDirectory("main folder:")
image_list = os.listdir(path_photos)
photo_list = list()
for root, dirs, files in os.walk(path_photos):
    new_group = chunk.addCameraGroup()
    for photo in image_list:
        if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
            photo_list.append("/".join([path_photos, photo]))
        chunk.addPhotos(photo_list)
        print("- Photos ajoutées")
           
        for camera in list(chunk.cameras):
            camera.group = new_group

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14927
    • View Profile
Re: Loading images from subdirectory to cameras groupes
« Reply #3 on: December 20, 2017, 05:45:39 PM »
Hello magic,

Please try this code to load the images from the sub-directories of the user-defined master folder to separate camera groups in the same chunk:
Code: [Select]
import PhotoScan, os

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

path_master = PhotoScan.app.getExistingDirectory("Main folder:")
sub_folders = os.listdir(path_master)
for folder in sub_folders:
folder = os.path.join(path_master, folder)
if not os.path.isdir(folder):
continue

image_list = os.listdir(folder)
photo_list = list()
new_group = chunk.addCameraGroup()
new_group.label = os.path.basename(folder)
for photo in image_list:
if photo.rsplit(".",1)[1].lower() in  ["jpg", "jpeg", "tif", "tiff"]:
photo_list.append(os.path.join(folder, photo))
chunk.addPhotos(photo_list)
for camera in chunk.cameras:
if not camera.group:
camera.group = new_group
Best regards,
Alexey Pasumansky,
Agisoft LLC