Forum

Author Topic: add Folder  (Read 3332 times)

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
add Folder
« on: April 30, 2022, 05:22:57 PM »
Hello,

I would like to find in Python API the equivalent to  add folder in GUI menu WorkFlow. I see there is chunk.addPhotos() but this requires a list of photos. Is there a command for adding a folder?

Any help will be appreciated....
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: add Folder
« Reply #1 on: May 02, 2022, 05:36:34 PM »
Hello Paul,

One of the examples for Add Folder workaround is given in the workflow scripts in our GitHub repository:

Code: [Select]
import os
def find_files(folder, types):
    return [entry.path for entry in os.scandir(folder) if (entry.is_file() and os.path.splitext(entry.name)[1].lower() in types)]
photos = find_files(image_folder, [".jpg", ".jpeg", ".tif", ".tiff"])
chunk.addPhotos(photos)
Best regards,
Alexey Pasumansky,
Agisoft LLC

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: add Folder
« Reply #2 on: May 02, 2022, 06:07:08 PM »
Thanks Alexey,

but for my needs it does not  work!
I am trying to use addFolder with Multicamera layout where I have 277 RGB images and 277 corresponding thermal tif images
so I used following:
Code: [Select]
photos = find_files(path, [".jpg", ".jpeg", ".tif", ".tiff"])

photos[0:4]
Out[10]: 2022-05-02 09:47:33
2022-05-02 09:47:33 ['C:/Users/paul.pelletier/Downloads/Duet_T/img/rgb\\IX-x1-00057_0278_0001.JPG',
2022-05-02 09:47:33  'C:/Users/paul.pelletier/Downloads/Duet_T/img/rgb/thm\\IX-x1-00057_0278_0001_THM.tif',
2022-05-02 09:47:33  'C:/Users/paul.pelletier/Downloads/Duet_T/img/rgb\\IX-x1-00057_0278_0002.JPG',
2022-05-02 09:47:33  'C:/Users/paul.pelletier/Downloads/Duet_T/img/rgb/thm\\IX-x1-00057_0278_0002_THM.tif']

chunk.addPhotos(photos,layout=ps.MultiplaneLayout)
2022-05-02 09:48:22 AddPhotos: layout = MultiplaneLayout
2022-05-02 09:48:22 Loading photos...
2022-05-02 09:48:47 Finished processing in 23.221 sec (exit code 1)
2022-05-02 09:50:15 Loading photos...
2022-05-02 09:50:15 Finished processing in 0.454 sec (exit code 1)
However, I get one camera with 544 planes instead of 277 cameras with 2 planes ..see following where Chunk1 is result of using the code and Chunk2 is result of using Add Folder in GUI with Multicamera system. ...
Is there a way to addfolder with multicamera system in Python API?
« Last Edit: May 02, 2022, 08:00:08 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: add Folder
« Reply #3 on: May 06, 2022, 06:46:42 PM »
Hello Paul,

Creating of MultiPlaneLayout via Python has been described in the following thread (based on two sensor example):
https://www.agisoft.com/forum/index.php?topic=11583.msg51962#msg51962

Code: [Select]
images = [None]*(len(rgb) + len(nir))
images[::2] = rgb
images[1::2] = nir
filegroups = [2]*(len(images)//2)
#images is alternating list of rgb, nir paths
#filegroups defines the multi-camera system groups: [2, 2, 2, ....]

chunk.addPhotos(filenames = images, filegroups = filegroups, layout=Metashape.MultiplaneLayout)

some time ago I have also sent the following example for eight-camera system:


Code: [Select]
camera = [list_of paths_camera1, list_of_paths_camera2, list_of_paths_camera3, list_of_paths_camera4, list_of_paths_camera5, list_of_paths_camera6, list_of_paths_camera7, list_of_paths_camera8]
### list_of_paths_cameraN represent the list of paths for corresponding source folder
​C = len(camera)
images = [None]*(len(camera[0]) + len(camera[1]) + len(camera[2])  + len(camera[3])  + len(camera[4])  + len(camera[5]) + len(camera[6])   + len(camera[7]))
for i in range(C):
    images[i::C] = camera[i]
filegroups = [C]*(len(images)//C)
###images is alternating list of camera[0], camera[1] ... camera[7] paths
###filegroups defines the multi-camera system groups: [8, 8, 8, ....]
chunk.addPhotos(filenames = images, filegroups = filegroups, layout=Metashape.MultiplaneLayout)

Haven't optimized it, though, as we are not getting such requests frequently, but we'll consider publishing universal example in GitHub.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: add Folder
« Reply #4 on: May 06, 2022, 07:26:41 PM »
Thanks Alexey,
 the trick is the filegroups defining a series of 2s. So now I have 277 biplane images with rgb and thm. However although the first images in images list are the rgb alternating with the thm, I get plane 1 as thm and plane 2 as rgb. It should be the reverse rgb plane 1 or master and thm plane 2...also the reference info for rgb images is not read as seen in attachment....Iguess because thm is non referenced and is put into Plane 1...

But with Add folder from GUI I can get the correct relation between planes using Multicamera option and selecting the rgb folder (with thm as subfolder)...
« Last Edit: May 07, 2022, 09:24:04 PM by Paulo »
Best Regards,
Paul Pelletier,
Surveyor

Paulo

  • Hero Member
  • *****
  • Posts: 1303
    • View Profile
Re: add Folder
« Reply #5 on: May 10, 2022, 06:46:27 AM »
It seems that the code works when the 2 folders holding the rgb and thm images are at same level, i.e. thm folder is not sub folder of rgb which was originally the case...

Now with path to rgb = 'C:/Users/paul.pelletier/Downloads/Duet_T/img/rgb'
         and path to thm = 'C:/Users/paul.pelletier/Downloads/Duet_T/img/thm16bit'

the multiplane setup is correct as seesn in:
Best Regards,
Paul Pelletier,
Surveyor

ilia

  • Jr. Member
  • **
  • Posts: 55
    • View Profile
Re: add Folder
« Reply #6 on: July 07, 2022, 06:58:40 PM »
On the page 17th of the Python API reference 1.8.3 document there are an example where .addPhotos is used without filegroups with rig-like setup (two cameras by position). Is it a mistake there?