Forum

Author Topic: add photo and save project  (Read 5982 times)

FreeArt

  • Newbie
  • *
  • Posts: 3
    • View Profile
add photo and save project
« on: August 25, 2015, 10:36:29 PM »
Hello

I'm using photoscan 1.1.6 and I wrote one little script which open and add all .tif photo from one directory and save this project to .psz but unfortunately the script is not work because can't open and add photos for chunk and I don't know why.

The error code:

    if proejct_path[-4:].lower() != ".psz":
NameError: name 'proejct_path' is not defined

The script:
Code: [Select]

import os
import PhotoScan

global doc
doc = PhotoScan.app.document

#path to photos
path_photos = PhotoScan.app.getExistingDirectory("Specify input photo folder:")

print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = "New Chunk"

project_path = PhotoScan.app.getSaveFileName("Specify project filename for saving:")
if not project_path:
print("Script aborted")

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

#loading images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
if ("TIFF" or "tif") in photo.lower():
photo_list.append(path_photos + "\\" + photo)
chunk.addPhotos(photo_list)
doc.save()
PhotoScan.app.update()
print("Script finished")


I would appreciate any help doing this. Thanks and sorry my poor English.

Regards
Peter
« Last Edit: August 25, 2015, 11:01:03 PM by FreeArt »

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: add photo and save project
« Reply #1 on: August 25, 2015, 11:02:58 PM »
You have a typo in there!

'proejct' should be 'project'

I don't know if the script will work after you fix that, but it should work better anyway!

FreeArt

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: add photo and save project
« Reply #2 on: August 26, 2015, 11:04:02 AM »
Thanks James for your reply.
 
I fixed my stupid mistake but unfortunately the program isn't work fine, because the program isn't save the project and can't add my tif photos BUT if I switch tif argument to "jpg" or "jpeg" the program can add jpg photos for chunk.
But It would be better if the program could add tiff photos for chunk. Can you give me some hint?

many Thanks

Peter

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: add photo and save project
« Reply #3 on: August 26, 2015, 11:16:24 AM »
Hello Peter,

in the line
Code: [Select]
if ("TIFF" or "tif") in photo.lower(): the first condition cannot be true, as caps letters can't appear in lower-case string.
I can suggest to change it to "tiff" and check if it helps.
Best regards,
Alexey Pasumansky,
Agisoft LLC

FreeArt

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: add photo and save project
« Reply #4 on: August 26, 2015, 03:21:21 PM »
Hello Alexey,

Thanks your hint, the problem was little strange for me:

if I use this:

Code: [Select]
if ("tiff" or "tif") in photo.lower():

The program don't add tif photos.

But if I use this line:

Code: [Select]
if ("tif" or "tiff") in photo.lower():

The program add tif files for chunk.

But Now the program works fine
and Really thanks your and James help  :).

here is the complet code:

Code: [Select]

import os
import PhotoScan

global doc
doc = PhotoScan.app.document

#path to photos
path_photos = PhotoScan.app.getExistingDirectory("Specify input photo folder:")

print("Script started")

#creating new chunk
doc.addChunk()
chunk = doc.chunks[-1]
chunk.label = "New Chunk"

project_path = PhotoScan.app.getSaveFileName("Specify project filename for saving:")
if not project_path:
print("Script aborted")

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

#loading images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
if ("tif" or "tiff") in photo.lower():
photo_list.append(path_photos + "\\" + photo)
chunk.addPhotos(photo_list)
doc.save(project_path)
PhotoScan.app.update()
print("Script finished")


Regards
Peter

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: add photo and save project
« Reply #5 on: August 26, 2015, 03:32:36 PM »
Code: [Select]
"tiff" or "tif"
evaluates to "tiff", whereas

Code: [Select]
"tif" or "tiff"
evaluates to "tif", so your code is effectively now just

Code: [Select]
if "tif" in photos.lower():
presumably your files all have .tif extension and your script wouldn't work if they had .tiff extension.

i think what you need is

Code: [Select]
if ("tif" in photos.lower()) or ("tiff" in photos.lower()):
but check that because i'm not fluent in python, and there's probably a more elegant solution!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: add photo and save project
« Reply #6 on: August 26, 2015, 03:34:11 PM »
Well, I think then you just can leave
Code: [Select]
if ".tif" in photo.lower()since this string is included in ".tiff" :)
Best regards,
Alexey Pasumansky,
Agisoft LLC

James

  • Hero Member
  • *****
  • Posts: 748
    • View Profile
Re: add photo and save project
« Reply #7 on: August 26, 2015, 03:39:37 PM »
I knew there was a more elegant answer!  :)

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14818
    • View Profile
Re: add photo and save project
« Reply #8 on: August 26, 2015, 03:44:44 PM »
Actually, I assume that originally the code was partially taken from one of my script samples posted on forum, so the problem was there even since then.
Best regards,
Alexey Pasumansky,
Agisoft LLC