Forum

Author Topic: API: access to selected images  (Read 10326 times)

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
API: access to selected images
« on: September 08, 2013, 01:09:52 AM »
would be interesting to know which images are selected, in the API.

e.g. to export some of them undistorted for later texture remapping in an external tool.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Re: API: access to selected images
« Reply #1 on: September 08, 2013, 11:40:18 AM »
Hello 7eicher,

There is a flag camera.selected, so you can run a loop through all the cameras in the chunk.
Best regards,
Alexey Pasumansky,
Agisoft LLC

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: API: access to selected images
« Reply #2 on: September 08, 2013, 03:57:28 PM »
Thanks Alexey, thats good news!

jdtakacs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: API: access to selected images
« Reply #3 on: September 18, 2013, 07:58:16 PM »
Hello,

I have a question along the same lines. I have a user that wants to be able to not only remove selected cameras from a chunk, but also delete the physical jpg/image file from the system as well. I am scripting this with the API but have run into an interesting issue. The problem is that when the script is run not all of the selected cameras are removed from the active chunk.

Code:

if cameraCount > 0:
   for camera in chunk.cameras:
      if camera.selected:
         print(camera.label)
         chunk.cameras.remove(camera)

This is simple code. If I rerun the script multiple times I am able to remove all the selected cameras, but I don't want the users to have to rerun multiple times. I am running Photoscan Professional 0.9.1 build 1714 64 bit.

Thanks!

Josh

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Re: API: access to selected images
« Reply #4 on: September 18, 2013, 08:40:51 PM »
Hello Josh,

I assume that the problem is in fact that you are removing elements from the list used in the loop.

I suggest to use the following loop definition:
Code: [Select]
for camera in list(chunk.cameras):
It should work correctly for the single run.
Best regards,
Alexey Pasumansky,
Agisoft LLC

jdtakacs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: API: access to selected images
« Reply #5 on: September 18, 2013, 10:35:33 PM »
Fantastic! That worked. Is this a Python specific thing? Can you tell me why I had to specify that it was an array?

Thanks!

Josh

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Re: API: access to selected images
« Reply #6 on: September 18, 2013, 10:42:31 PM »
Hello Josh,

It's a Python trick. However, there are other methods of element removal from list while iterating overt it, but it seems the most easy one.

When you use list(chunk.cameras) it means that new lit is created and you are moving through it and not the one you are removing elements from.

Another option is to add cameras to be removed to new list and then use chunk.cameras.remove(cam_list). I think it should also work.
« Last Edit: September 18, 2013, 10:45:24 PM by Alexey Pasumansky »
Best regards,
Alexey Pasumansky,
Agisoft LLC

7eicher

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: API: access to selected images
« Reply #7 on: September 18, 2013, 10:45:47 PM »
Dear friend, in python, list() will create you a copy of the camera collection. So you iterate over the temporarly copied list, while you remove the true/permanent list. If you don't do that, you will remove elements from a list, that you iterate over. Hope it gets clear? :)

jdtakacs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: API: access to selected images
« Reply #8 on: September 18, 2013, 10:56:52 PM »
All great information. Thank you for your help! Moving on. Next hurdle it to try to get a menu button for my script.

Thanks!

Josh

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14888
    • View Profile
Re: API: access to selected images
« Reply #9 on: September 18, 2013, 11:04:15 PM »
Hello Josh,

To add add button for your function you should use the following:
Code: [Select]
PhotoScan.app.addMenuItem("Custom menu/My script 1", new_func)
Best regards,
Alexey Pasumansky,
Agisoft LLC

jdtakacs

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: API: access to selected images
« Reply #10 on: September 19, 2013, 12:51:06 AM »
Hello Alexey,

Is there a way to load a script when PhotoScan opens? I would like to have this menu option available when a user opens PhotoScan.

Thanks!

Josh