Forum

Author Topic: Importing images by looping through multiple folders  (Read 6835 times)

akasch

  • Newbie
  • *
  • Posts: 4
    • View Profile
Importing images by looping through multiple folders
« on: September 17, 2015, 08:31:05 PM »
Hi,

Has anyone written a Python script that accesses images stored in different folders? I want the images in each folder to be placed into its own chunk.

So:

Folder A (with images 1, 2, 3) translates to Chunk A containing images 1, 2, 3
Folder B (with images 4, 5, 6) translates to Chunk B containing images 4, 5, 6

Does anyone have script that accomplishes this? Any help would be amazing.

Thanks!

johnsietsma

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • John Sietsma
Re: Importing images by looping through multiple folders
« Reply #1 on: September 30, 2015, 07:43:18 AM »
I have a script which creates multiple documents using photos in multiple folders. You may be able to adapt it to create chunks instead.

https://gist.github.com/notoes/774f4b66a10acfe516e7

John

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: Importing images by looping through multiple folders
« Reply #2 on: October 07, 2015, 06:58:37 PM »
Hi John,
would you be so nice to reupload the script?
It would be greatly appreciated!
Cheers!

johnsietsma

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • John Sietsma
Re: Importing images by looping through multiple folders
« Reply #3 on: October 07, 2015, 11:07:18 PM »
Oh sorry, I'm moved it to a github repository. Here it is: https://github.com/notoes/PhotoscanWorkflow/blob/master/workflow.py

You'll be most interested in the section called "Project functions". The functions there iterate through folders and create new projects for each folder. You could do something like pass in a document to make_project() and comment out the lines where it creates a new document. The function creates a new chunk and adds photos to it.

All the best,
John

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: Importing images by looping through multiple folders
« Reply #4 on: October 08, 2015, 09:46:25 AM »
Hey John,
thank you very much! If you should be in my region of the map, I'll buy you a beer or two.
Cheers!
Arie

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: Importing images by looping through multiple folders
« Reply #5 on: October 10, 2015, 11:43:38 AM »
Hi again,
sorry to bother you but I've been trying to adapt your script to loop through already existing projects for decimating, retexturierung and exporting the models.
This works so far great but when applying this to a referenced chunk, I get "ERROR: Chunk is None".

I've been dabbling around for hours but am kind of stuck.
Any hints on what to change?

Here the output from console:
Code: [Select]
--- Starting workflow ---
Photoscan version 1.1.6
Home directory: C:\Users\User\Desktop\Agisoft_Skript_Test
2015-10-10 10:51:31.233192
Found 1 project directories
Making projects
Building document: C:\Users\User\Desktop\Agisoft_Skript_Test\Alc14_N_24
2015-10-10 10:51:31.233192
Opening project C:\Users\User\Desktop\Agisoft_Skript_Test\Alc14_N_24
Loading project...
can't load project
Finished processing in 0 sec (exit code 0)
ERROR: Cold not open document: C:\Users\User\Desktop\Agisoft_Skript_Test\Alc14_N_24\Alc14_N_24.psz
ERROR: Chunk is None
2015-10-10 10:51:31.302196
--- Finished workflow ---
« Last Edit: October 10, 2015, 11:52:55 AM by Arie »

johnsietsma

  • Newbie
  • *
  • Posts: 3
    • View Profile
    • John Sietsma
Re: Importing images by looping through multiple folders
« Reply #6 on: October 12, 2015, 01:25:07 AM »
Hi Arie,

That was a lot of code to throw at you :) I've created a simpler script which will create a new PhotoScan document and add chunks containing photos from subdirectories.

https://raw.githubusercontent.com/notoes/PhotoscanWorkflow/master/example_multichunk.py

I've added comments to (hopefully!) make it easier to understand.

Have a look at the bottom of the file to see how the chunks are processed. I've added some example steps that you could uncomment. Or you could add your own steps here, like decimation. Check the PhotoScan.Chunk section Python API doc for examples of what you can do.

Best of luck!

John Sietsma

Arie

  • Full Member
  • ***
  • Posts: 134
    • View Profile
Re: Importing images by looping through multiple folders
« Reply #7 on: October 12, 2015, 02:47:57 AM »
John,
thank you so much. That's greatly appreciated.  :)
Can't wait to try that script tomorrow!
Cheers!