Forum

Author Topic: AddPhotos Photoscan 1.1.0  (Read 2461 times)

Kalel

  • Newbie
  • *
  • Posts: 7
    • View Profile
AddPhotos Photoscan 1.1.0
« on: August 01, 2017, 09:19:06 PM »
Hi, I am new using the Photoscan/Python combination. I need to do batch processing of aerial photos. I need to to this in 2 scripts in order to be able to place my markers manually.
First script: 1.Import photos in the work flow from their folder.
 2. Align the photos.
3. Save the project.
Second script: 1.Import the marker file (.txt)
 2.Build the dense cloud.
3.Build mesh.
4.Build the texture.
5.Save the project. I have written a little script inspired by previous posts. Nevertheless, the photos won't show up in the Chunk.


import PhotoScan
import os



def main():



    print("Script is starting")
doc = PhotoScan.app.document #Permet d'avoir accès au projet qui est déjà ouvert
chunk= doc.addChunk()

path_photos = PhotoScan.app.getExistingDirectory(
    "Specify folder with input photos:")  # Spécifier le nom du dossier contenant les photos
path_photos += "/"

project_path = PhotoScan.app.getSaveFileName("Specify project filename for saving:")  # Spécifier le nom du projet pour enregistrement

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

image_list = os.listdir(path_photos)
for photo in image_list:
    if ("JPG" or "JPEG" or "TIF" or "PNG") in photo.lower():
        chunk.addPhotos(path_photos + photo)

PhotoScan.app.update()   #Met à jour l'interface après le téléchargement des photos

PhotoScan.app.update()
Thank in advance
Best regards
Samantha
« Last Edit: August 01, 2017, 09:30:43 PM by Kalel »

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: AddPhotos Photoscan 1.1.0
« Reply #1 on: August 02, 2017, 12:44:04 PM »
The photos do not load into the chunk because you made a mistake in your filter condition.
Code: [Select]
("JPG" or "JPEG" or "TIF" or "PNG") in photo does not check for the presence of the extension (I assume) in the given photo path but actually does
Code: [Select]
(True or True or True or True) in photo or
Code: [Select]
True in photoIn this type of situation (again, assuming you check the extension) it is easier to use the endswith() str method that can take a tuple:
Code: [Select]
# Be careful to check for lower extensions when you lower the path
path.lower().endswith(("jpg", "jpeg", "tif", "png"))

Then, as addPhotos() takes a list of file paths, you can simply filter the result of os.listdir():
Code: [Select]
# Only keep files with extension jpg, jpeg, tif and png
image_list = [
    os.path.join(path_photos, path)
    for path in os.listdir(path_photos)
    if path.lower().endswith(("jpg", "jpeg", "tif", "png"))
    ]
chunk.addPhotos(image_list)


I reformatted your script in the attached file (haven't tested it though). Don't forget that indentation is very important in Python.
« Last Edit: August 03, 2017, 10:46:24 AM by Gall »

Kalel

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AddPhotos Photoscan 1.1.0
« Reply #2 on: August 02, 2017, 09:08:41 PM »
Hi again and thank you for your previous answer. The code does not work. I've simplified it the best I could but it is still not working. Please help..

import PhotoScan
import os

doc = PhotoScan.app.document
chunk = doc.addChunk()

path_photos = r'C:\Users\Pellousa\Desktop\Data engage\Photogrammetry\Patch 1'
path_photos += "\\"
print(path_photos)

image_list = os.listdir(path_photos)
for photo in image_list:
    if ("jpg" or "jpeg" or "tif" or "png") in photo.lower():
         chunk.addPhotos(path_photos + photo)

PhotoScan.app.update()

Gall

  • Jr. Member
  • **
  • Posts: 85
    • View Profile
Re: AddPhotos Photoscan 1.1.0
« Reply #3 on: August 03, 2017, 10:45:30 AM »
Did you try the script I attached to my post? I admit I forgot to remove one line that messes up the save but it is working for me (although I don't have the version 1.1.0 to test it but I don't see incompatibilities).

Anyway, when you say that the code does not work, please specify what error/behavior you have, otherwise we cant help you...

Again, you can find the corrected script attached to this post...

Kalel

  • Newbie
  • *
  • Posts: 7
    • View Profile
Re: AddPhotos Photoscan 1.1.0
« Reply #4 on: August 03, 2017, 09:17:17 PM »
Hello again, I finally got everything to work on another version Photoscan 1.0.4
There's still 2 things I need to add in my script :
1. Import Markers
2. Import Camera positions

Can anyone help me?

Thanks
Kalel