Forum

Author Topic: Failed to generate a georeferenced orthophoto using python script!  (Read 8779 times)

ppodder1985

  • Newbie
  • *
  • Posts: 4
    • View Profile
Hi,
I am using a trial version of Photoscan Pro. I have written following python script to generate an orthophoto from a list of UAV frames.
Code: [Select]
import os
import PhotoScan
import sys

doc = PhotoScan.app.document
chunk = PhotoScan.Chunk()
chunk.label = "New Chunk"
doc.chunks.add(chunk)

print("Srcipt started")

path_photos= "G:/UAV_images/test_photoscan_script"

project_path= "G:/UAV_images/test_photoscan_script/project/test.psz"

mosaic_path=  "G:/UAV_images/test_photoscan_script/test.tif"

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

PhotoScan.app.update()

#align photos
chunk.matchPhotos(accuracy = "high", preselection = "ground control", filter_mask = False, point_limit = 40000)
#doc.activeChunk.matchPhotos(accuracy = "high", preselection = "generic", filter_mask = False, point_limit = 50000)
chunk.alignPhotos()

#chunk.buildDepth(quality="medium")
#build dense cloud
chunk.buildDenseCloud(quality = "high", filter = "aggressive")

#build mesh
chunk.buildModel(surface = "height field", source = "dense", interpolation = "enabled", faces="medium")

#build texture
chunk.buildTexture(mapping = "orthophoto", blending = "mosaic", color_correction = False, size = 4096, count = 1)

#decimate model
chunk.decimateModel(face_count = 200000)

#save
doc.save(project_path)

PhotoScan.app.update()
print("Script finished")

After executing the above python script when I try to export Orthophoto from GUI, the Geographic radio button is disabled only Planar is enabled. But I want a georeferenced Orthophoto. I might have missed something in the script, could you please help me to resolve this.

FYI, I have tried the batch Process under workflow menu and use the same set of arguments. Surprisingly it has enabled the Geographic option. But I badly need the python script to work.

Thanks.
PPodder
« Last Edit: August 26, 2014, 06:56:45 PM by ppodder1985 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #1 on: August 26, 2014, 06:54:03 PM »
Hello PPodder,

You need to input camera or marker coordinates for georeferencing purposes. In your script this step is missing.

Do you have a text file with camera coordinates or GPS tags are present in the image EXIF?
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppodder1985

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #2 on: August 26, 2014, 06:58:23 PM »
Hi Alexey,
GPS tags are present in the image EXIF.
Thanks.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #3 on: August 27, 2014, 10:51:41 AM »
Hello PPodder,

Then I think you should put the following lines prior to alignment stage:
Code: [Select]
chunk.ground_control.loadExif()
chunk.ground_control.apply()
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppodder1985

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #4 on: August 27, 2014, 12:09:38 PM »
Hi Alexey,
Thanks for your help. I have one more query. I know latest version of Photoscan Pro doesn't support command line interface yet. I found number of threads talking about this and different workarounds to make it run from command line using python script. My script is now working from the GUI and I am using one of the solution from this forum to make it run from command line. But I am getting the following error:
Code: [Select]
doc.chunks.add(chunk)
AttributeError: 'NoneType' object has no attribute 'chunks'

FYI, if I don't use doc object then my script generates the orthophoto without any problem. Batch script I am using is as follows:
Code: [Select]
@echo off

echo ---RUNNING A PYTHON SCRIPT IN PHOTOSCAN---
echo .
echo DO NOT CLOSE THIS WINDOW!
echo .
echo If you do so before the batch finishes, the temporary script file will not be deleted and it will run again always when you start PhotoScan normally! If you do it by accident, delete manually the file:
echo %LOCALAPPDATA%\Agisoft\PhotoScan Pro\scripts\TempScript.py
echo .

:: Copy the input script file to PhotoScan scripts folder
echo Copying script file to PhotoScan Script folder...
copy %1 "%LOCALAPPDATA%\Agisoft\PhotoScan Pro\scripts\TempScript.py" /Y

:: Run PhotoScan and wait until it is closed
echo PhotoScan is started.
echo Waiting for PhotoScan to close... (you might need to do it manually)
call "c:\Program Files\Agisoft\PhotoScan Pro\photoscan.exe"

:: Delete the script file so that it is not run again when user runs next time photoscan normally
echo Deleting the script file in PhotoScan script folder...
del "%LOCALAPPDATA%\Agisoft\PhotoScan Pro\scripts\TempScript.py"

:: closes the cmd window
exit

I know as you don't officially support command line interface, you are not bound to answer this query. But this is a very critical question from our point of view as our application needs to be automated.

Thanks.
« Last Edit: August 27, 2014, 12:13:00 PM by ppodder1985 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 15177
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #5 on: August 27, 2014, 12:15:34 PM »
Hello PPodder,

Access to doc is disabled if the scripts are run from autorun folder.
Best regards,
Alexey Pasumansky,
Agisoft LLC

ppodder1985

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: Failed to generate a georeferenced orthophoto using python script!
« Reply #6 on: August 27, 2014, 12:19:44 PM »
That implies saving project is not possible if the scripts are run from autorun folder!