Forum

Author Topic: Adding Multiple Chunks to Project in Python Script  (Read 5450 times)

ax0n

  • Newbie
  • *
  • Posts: 7
    • View Profile
Adding Multiple Chunks to Project in Python Script
« on: July 26, 2017, 02:38:49 PM »
Greetings,

I am working with images form and RGB and an NIR camera and I need to process them in individual chunks in the same project.

I cant seem to add multiple chunks in the script, the second added chunk overwrites the first.. Can anyone point me in the direction of a solution to this?

Here is an example framework of the script where I try to add a second chunk.

Code: [Select]

# start new project and save as specific unique project name
import os
import PhotoScan as ps

doc = ps.app.document
chunk = doc.addChunk()
project_path = ps.app.getSaveFileName("Specify project filename for saving: ")

if not project_path:
    print("Script aborted")

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

doc.save(project_path)
ps.app.update()

# get folder of RGB photos
path_photos_rgb = ps.app.getExistingDirectory("Specify folder with RGB photos: ")
path_photos_rgb += "/"

# get folder of NIR photos
path_photos_nir = ps.app.getExistingDirectory("Specify folder with NIR photos: ")
path_photos_nir += "/"

# create 'RGB' chunk and add photos

chunk.label = "RGB"

image_list = os.listdir(path_photos_rgb)

photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].upper() in ["JPG", "JPEG", "TIF", "PNG", "TIFF"]:
           photo_list.append(path_photos_rgb + photo)
           print(photo)
    else:
           print("No photo available.")
print(photo_list)
chunk.addPhotos(photo_list)
doc.save(project_path)
ps.app.update()

# create 'NIR' chunk and add photos
chunk.label = "NIR"

image_list = os.listdir(path_photos_nir)

photo_list = list()
for photo in image_list:
    if photo.rsplit(".",1)[1].upper() in ["JPG", "JPEG", "TIF", "PNG", "TIFF"]:
           photo_list.append(path_photos_nir + photo)
           print(photo)
    else:
           print("No photo available.")
print(photo_list)
chunk.addPhotos(photo_list)
doc.save(project_path)
ps.app.update()


print("step finished")



at this point I have a single chunk labeled "NIR" that contains all the RGB and NIR photos. Any suggestions?

Thank you for your time,

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15160
    • View Profile
Re: Adding Multiple Chunks to Project in Python Script
« Reply #1 on: July 26, 2017, 04:02:26 PM »
Hello indigo,

You need to create a new chunk, so before the line chunk.label = "RGB" please add: chunk = doc.addChunk()

Also I can suggest to use doc.save(project_path) only in the beginning, when doc variable is initialized, then just use doc.save() without any arguments.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ax0n

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: Adding Multiple Chunks to Project in Python Script
« Reply #2 on: July 26, 2017, 04:32:33 PM »
Thank you Alexey, that worked.

for future reference, how do I switch active chunks in the script?

I will post the whole script when it is running for anyone else that might need it.

thanks again,


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15160
    • View Profile
Re: Adding Multiple Chunks to Project in Python Script
« Reply #3 on: July 26, 2017, 05:09:35 PM »
Hello indigo,

You can access the chunks by their index (first one has index = 0), like chunk = doc.chunk[2], for example.

To make chunk active in the Workspace pane, please use the following:
Code: [Select]
doc.chunk = doc.chunks[1]
To access the active chunk, just use chunk = doc.chunk
Best regards,
Alexey Pasumansky,
Agisoft LLC