Forum

Author Topic: Messages stop from command prompt; python experiences from command prompt?  (Read 2511 times)

ap_grass

  • Newbie
  • *
  • Posts: 3
    • View Profile
I'm running a python script from command prompt that seems to be partially working.

The problem is that responses within command prompt window stop, there are no error messages and the cursor just blinks as if it is processing.

After waiting a while, I stop the process by using Control Z + enter, upon which a full set of messages appears - including PhotoScan default messages, and printed statements I added to the code. When debugging my code, error messages would appear as well.

My code mostly runs, but this is a weird issue that I don't understand. I suspect this is a photoscan bug when run from command prompt.

Does anyone else have this issue? More broadly, is anyone else successfully running python from command prompt? I wonder if continuing to try using python from command prompt is a waste of time, or it will eventually come through for me.

I can't run my code inside the GUI because my goal is to create and process a large number of new photoscan documents in different folders/photo sets.

Any comments would be helpful, thanks!

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Messages stop from command prompt; python experiences from command prompt?
« Reply #1 on: November 21, 2018, 11:39:03 AM »
Hello ap_grass,

Can you send an example of such script to support@agisoft.com or post it here (if it is not sensible), so that we could try to reproduce the described behavior?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ap_grass

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Messages stop from command prompt; python experiences from command prompt?
« Reply #2 on: November 21, 2018, 07:40:16 PM »
Hi, thanks for taking a look.The below is just a cut and paste from other posts on this message board. I run it in command prompt (windows 10) with:
Code: [Select]
C:\Program Files\Agisoft\PhotoScan Pro>photoscan.exe -r "D:\UAV_2018\photoscan_draft.py"
Code: [Select]
#import libraries[D:

import os
import PhotoScan


# Define: AlignPhotosAccuracy ["high", "medium", "low"]
AlignPhotosAccuracy = "medium"

# set the home directory
#/UAV_photos
home =r'D:\20180809\NIR'
scan =r'D:\20180809\NIR\1'

# set new working directory to be in folder
# Set home folder
os.chdir(scan)
print("Home directory: " + scan)

# Define: PhotoScan Project File
PhotoScanProjectFile = ".\\PhotoScan_Project.psz"
# get main app objects
doc = PhotoScan.app.document
doc.save(PhotoScanProjectFile)
# app = PhotoScan.Application()
app = PhotoScan.Application()

# create chunk
chunk = doc.addChunk()

# ##this is from another site, compare with previous to make sure photos can be added automoatically
# http://www.agisoft.com/forum/index.php?topic=7980.0
path_photos = PhotoScan.app.getExistingDirectory(scan)
image_list = os.listdir(scan)
print(image_list)
photo_list = list()
for photo in image_list:
    if photo.rsplit(".", 1)[1].lower() in ["jpg", "jpeg", "tif", "tiff"]:
        photo_list.append(([path_photos, photo]))
doc.chunk.addPhotos(photo_list)

# SAVE PROJECT
doc.save()
print("---Saving project...")

app.quit()
print("photoscan is quit")



Messages in command prompt stop at the first doc.sav. After I hit control + Z enter, messages appear until the last doc.save(). The final app.quit() and print commands are not executed.
« Last Edit: November 21, 2018, 07:47:53 PM by ap_grass »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14847
    • View Profile
Re: Messages stop from command prompt; python experiences from command prompt?
« Reply #3 on: November 22, 2018, 08:25:59 PM »
Hello ap_grass,

I'm trying to reproduce the problem that you are observing, but also have some comments related to the script:

You do not have to use app = PohtoScan.Application() and app.quit() assignments, as the program GUI is not opened when the script is run in headless mode. It will stop automatically when the script ends. In your case the last line will not be executed, as app.quit() would terminate the activity.
Also for the same reasons I recommend to use in the beginning the following:
Code: [Select]
doc = PhotoScan.Document() #instead of doc = PhotoScan.app.document
It seems that your problem is caused by PhotoScan.app.getExistingDirectory() call. It waits for you to input the path to be assigned to path_photos variable. Or was it the intention of the script to be that interactive? I would rather suggest to pass the paths to the files or folders as script arguments:

Code: [Select]
C:\Program Files\Agisoft\PhotoScan Pro>photoscan.exe -r "D:\UAV_2018\photoscan_draft.py" "D:/image_folder/"
Code: [Select]
import PhotoScan, sys
path_photos = sys.argv[1]
print("This is the import folder: ", path_photos)
Best regards,
Alexey Pasumansky,
Agisoft LLC

ap_grass

  • Newbie
  • *
  • Posts: 3
    • View Profile
Re: Messages stop from command prompt; python experiences from command prompt?
« Reply #4 on: November 27, 2018, 07:21:30 PM »
Hi Alexey,

Your comments were very helpful. Thanks! I now have my script running and based on your suggestion to use command line arguments, figured out how to batch process through my folder set.

For anyone else who comes along, I'll leave my code here

note this creates the photoscan file (.psx) in the directory folder with the full set of photos

I set up a .bat file with this basic outline
"C:\Progam Files\Agisoft\PhotoScan Pro\photoscan.exe" -r "D:\photoscan_batch.py" "D:\photo_set1" %*
ECHO Set 1 Run
"C:\Progam Files\Agisoft\PhotoScan Pro\photoscan.exe" -r "D:\photoscan_batch.py" "D:\photos_set2" %*
ECHO Set 2 Run

Then run it from command line using
Code: [Select]
C:\Program Files\Agisoft\PhotoScan Pro>photoscan.exe -r "D:\UAV_2018\photoscan_draft.py" "D:/image_folder/"


Code: [Select]
#! python3

import os
import PhotoScan, sys
path_photos = sys.argv[1]


# Define: AlignPhotosAccuracy ["high", "medium", "low"]
AlignPhotosAccuracy = "medium"

# set new working directory to be in working folder set in command line
os.chdir(path_photos)
print("Home directory: " + path_photos)

# Define: PhotoScan Project File
PhotoScanProjectFile = ".\\PhotoScan_Project.psz"
# get main app objects
doc = PhotoScan.Document() #instead of doc = PhotoScan.app.document
doc.save(PhotoScanProjectFile)

app = PhotoScan.Application()

# create chunk
chunk = doc.addChunk()

# loading images
image_list = os.listdir(path_photos)
photo_list = list()
for photo in image_list:
    if ("jpg" or "jpeg" or "JPG" or "JPEG") in photo.lower():
        photo_list.append(path_photos + "\\" + photo)
chunk.addPhotos(photo_list)


# SAVE PROJECT
doc.save()
print("---Saving project...")
############################################################################
print("File: " + PhotoScanProjectFile)
# if not (doc.save(PhotoScanProjectFile)):
#     app.messageBox("Saving project failed!")

# Set up all GPUs to work (not sure if this is necessary)
# from http://www.agisoft.com/forum/index.php?topic=9874.0
# Enable two GPUs
PhotoScan.app.gpu_mask = 3


# ALIGN PHOTOS
print("---Aligning photos ...")
chunk.matchPhotos(PhotoScan.LowAccuracy, PhotoScan.GenericPreselection, False, 40000, 1000)
chunk.alignCameras()
doc.save()
print("saved, now to dense cloud")

#Build dense cloud
chunk.buildDepthMaps(quality=PhotoScan.MediumQuality, filter=PhotoScan.AggressiveFiltering)
chunk.buildDenseCloud()

doc.save()
print("SAVED DENSE CLOUD")
############################################################################
#this is where I ended as I needed to manually add GCPs.
« Last Edit: November 27, 2018, 09:07:58 PM by ap_grass »