Forum

Author Topic: Select every 5th picture and activate or deactivate it by python script ?  (Read 9460 times)

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Hello,

i want to write a python script which can select every 5th or 10th picture.

Are there some people which has written something like this ?

Thanks

Andreas

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15465
    • View Profile
Hello Andreas,

Code: [Select]
chunk = PhotoScan.app.document.chunk
step = PhotoScan.app.getInt("Specify the selection step:" ,5)
index = 1
for camera in chunk.cameras:
      if not (index % step):
            camera.selected = True
      else:
            camera.selected = False
      index += 1
Best regards,
Alexey Pasumansky,
Agisoft LLC

AS_mining

  • Newbie
  • *
  • Posts: 19
    • View Profile
Thanks Alexey it works very fine !

Andreas

Mohammed

  • Full Member
  • ***
  • Posts: 192
    • View Profile
Hi Alexey,

Great script!
I need the same script but to select the images which have more than 4 ot 5 overlap images.

Thank you

Robert Dzur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Hi Alexey,

I'm wondering how I might modify the script above to select photos that are contained in a text list.  I've seen some other reference examples on the forum to opening a text file but I'm not quite getting the code correct.  Would like to do something like reading the text file containing a list of the photo labels that should not be selected (inverse selection from the list) to get anything not in the list (run_list1.txt) selected.

chunk = PhotoScan.app.document.chunk
sourcepath = "/Volumes/G-Tech/run_list1.txt"
file = open(sourcepath)
photoslist = file.readlines()
file.close()
photoslist = [photo.split()[0] for photo in photoslist]
for camera in chunk.cameras:
      if not (photoslist):
            camera.selected = True
      else:
            camera.selected = False

Thanks for any suggestions.

Robert

     

Robert Dzur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Ok.  Solved this code issue with the following...debugging print lines are commented out.

Code: [Select]
chunk = PhotoScan.app.document.chunk
sourcepath = "/Volumes/G-Tech/run_list1.txt"
file = open(sourcepath, "rt")
photoslist = " ".join(file.readlines()).split()
file.close()
#print (photoslist[0])
#print ("\n")
#print (chunk.cameras[0].label.split("'")[0])
for camera in chunk.cameras:
      if not (camera.label.split("'")[0] in photoslist):
            camera.selected = True
      else:
            camera.selected = False

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15465
    • View Profile
Hello Robert,

I think that for the condition inside the loop you need to use something like:
Code: [Select]
if camera.label in photoslist:
For the debugging purposes you can also print the photoslist contents to the Console to be sure, that it is read properly.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Robert Dzur

  • Newbie
  • *
  • Posts: 47
    • View Profile
Hi Alexey,

Just tried that out and the code worked great...much more streamlined.  Appreciate the suggestion.

Thank you.

Robert
--