Agisoft Metashape

Agisoft Metashape => Python and Java API => Topic started by: Helimax on April 02, 2015, 07:19:25 PM

Title: Load a calibration file - precalibrated project
Post by: Helimax on April 02, 2015, 07:19:25 PM
Hi !

I start with Python but I managed to do a lot of things thanks to this forum.
I'm stuck fort import calibration file (xml).

I saw this post but there have been changes since :
http://www.agisoft.com/forum/index.php?topic=1748.msg9189#msg9189

My script just below :

import PhotoScan
import os
import glob

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

AerialImageFiles = glob.glob("C:\\TRAVAUX EN COURS\\Agisoft Photoscan\\TEST SCRIPTS\\UHD Phototec\\431\\*.jpg")

cam = chunk.addCamera()
cam.open(AerialImageFiles[0])
# Load sensor calib
user_calib = PhotoScan.Calibration()
# build sensor object
sensor = chunk.addSensor()
sensor.label = "MyCamera"
sensor.width = 7360
sensor.height = 4912
sensor.fixed = True
sensor.user_calib = user_calib
user_calib.load("C:\\TRAVAUX EN COURS\\Agisoft Photoscan\\TEST SCRIPTS\\Calib.xml", "xml")

# LOAD AERIAL IMAGES
print("---Loading images...")
# load each image
for FileName in AerialImageFiles:
   #print("File: " + FileName)
   cam = chunk.addCamera()
   if not(cam.open(FileName)):
      app.messageBox("Loading of image failed: " + FileName)
   cam.label = FileName
   cam.sensor = sensor

os.chdir("C:\\TRAVAUX EN COURS\\Agisoft Photoscan\\TEST SCRIPTS\\UHD Phototec\\431")


There is no error message, but all calibration parameters are = "0"

My xml file (calibration) is ok when I load it "manually".

Can someone help me ?

Thanks.

Maxime
Title: Re: Load a calibration file - precalibrated project
Post by: Alexey Pasumansky on April 02, 2015, 07:38:58 PM
Hello Maxime,

It looks like you are at first assigning sensor.user_calib to the empty variable and then load calibration to the variable, but it is no longer connected.

You need to swap these lines.
Title: Re: Load a calibration file - precalibrated project
Post by: Helimax on April 03, 2015, 03:42:22 PM
Hello Alexey,

Thank you for your quick response.
It works much better that way.

Have a good day !

Maxime
Title: Re: Load a calibration file - precalibrated project
Post by: n@sk on May 06, 2015, 07:38:20 PM
Hi Alexey,

I tried to adapt the code above, but keep getting the error below:

                        chunk.addPhotos(img_list)
         
         u_calib = PhotoScan.Calibration()
         u_calib.load(os.path.join(cameraPath,"calib.xml"), "xml")

         print(chunk.sensors[0].fixed)
         chunk.sensors[0].fixed = True

>True   ### (The camera group appears to have fixed calibration, even though at the GUI "Fix Calibration" is not ticked)
>sensor.fixed = True
  AttributeError: 'PhotoScan.Sensor' object attribute 'fixed' is read-only


What am I doing wrong, could you please advise?

thanks
         
Title: Re: Load a calibration file - precalibrated project
Post by: Alexey Pasumansky on May 08, 2015, 12:43:53 PM
Hello n@sk,

Are you sure that the AttributeError is related to the given code?

Probably you need to assign sensor = chunk.sensors[0] at first.
Title: Re: Load a calibration file - precalibrated project
Post by: n@sk on May 14, 2015, 11:24:08 AM
Hello Alexey,

thank you for your response.

Yes, I tried the command line to make sure it is
and
Yes I need to assign!! I thought I could get access to the sensor without...

cheers