Forum

Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - ap_grass

Pages: [1]
1
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.

2
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.

3
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!

Pages: [1]