Agisoft Metashape
Agisoft Metashape => Python and Java API => Topic started 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
-
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.
-
Hello Alexey,
Thank you for your quick response.
It works much better that way.
Have a good day !
Maxime
-
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
-
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.
-
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