Forum

Author Topic: How to load calibration Camera parameter in batch file  (Read 10146 times)

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #15 on: November 08, 2016, 05:29:11 PM »
Hello Alexey,
It dosen't work
I putted the 8 file
camera1.xml, camera2.xml,camera3.xml,camera4.xml,camera5.xml,camera6.xml,camera7.xml,camera8.xml,
in the same directory of the photos and as you suggested I cange path with the two lines you gave me in the previuos message.
See below

import PhotoScan

chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    index  = camera.label[c.label.find("IMG") + 3]
    path = camera.photo.path.rsplit("/",1)[0] + "/camera" + index + ".xml"
    s = chunk.addSensor()
    s.label = camera.label
    s.user_calib = PhotoScan.Calibration()
    c = PhotoScan.Calibration()
    c.load(path)
    s.user_calib = c
    s.fixed  = True
    s.width = camera.photo.image().width
    s.height = camera.photo.image().height
    camera.sensor = s

The software give me an error see attachment,
what can I do?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #16 on: November 08, 2016, 05:39:27 PM »
Hello Davide,

should be
Code: [Select]
index  = camera.label[camera.label.find("IMG") + 3]
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #17 on: November 08, 2016, 07:55:46 PM »
Hello Alexey,
I made the change, no error comes out and Photoscan looks like in loop and in the top there is the write "Agisoft Photscan (dosen't respond) "

After few minutes the camera are all fix calibration, but the value of the f, cx, cy,.... are all equal to zero.

I know Alexey that it's long and difficult work to make me understand same Python but please make another effort to help me!!!

My script now is the following:

import PhotoScan

chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    index  = camera.label[camera.label.find("IMG") + 3]
    path = camera.photo.path.rsplit("/",1)[0] + "/camera" + index + ".xml"
    s = chunk.addSensor()
    s.label = camera.label
    s.user_calib = PhotoScan.Calibration()
    c = PhotoScan.Calibration()
    c.load(path)
    s.user_calib = c
    s.fixed  = True
    s.width = camera.photo.image().width
    s.height = camera.photo.image().height
    camera.sensor = s
 


Davide

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #18 on: November 08, 2016, 07:58:40 PM »
Hello Davide,

Can you send the project file in PSZ format to support@agisoft.com with added photos (any sample set with the common naming convention) and the set of the xml files? No need to have the cameras aligned, mesh or dense cloud in the project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #19 on: November 08, 2016, 09:07:18 PM »
Hello Davide,

In the provided project file the camera labels are like "IMG_5" and not "IMG5" as states before, so in the path line you need to use
Code: [Select]
index  = camera.label[camera.label.find("IMG") + 4]If both variants are possible, I can implement additional check, but it should work with the correction, I hope.
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #20 on: November 09, 2016, 06:55:26 PM »
Thank you very much Alexey!!!
It works!!!

Davide

totoromo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #21 on: January 31, 2017, 04:18:36 PM »
Following this conversation (among others), i'm facing an original problem : GUI manipulations and my Python script issu different results.

I use this code to create the structure (working fine) :
Code: [Select]
import PhotoScan
import os

calibFile = "CalibCam11.xml"
doc = PhotoScan.app.document
doc.open("PSZ.psz")

chunk2 = PhotoScan.app.document.addChunk()
chunk2.addPhotos(["Camera11_01380.534.tiff","Camera11_01381.522.tiff","Camera11_01382.528.tiff","Camera11_01383.524.tiff","Camera11_01384.528.tiff","Camera11_01385.525.tiff","Camera11_01386.530.tiff","Camera11_01387.525.tiff","Camera11_01388.531.tiff","Camera11_01389.529.tiff","Camera11_01390.525.tiff"])

Then, with the GUI i load a calibration file, fill in the focal length, fix it, and compute the orientation (Medium quality, no pair selection, 80k tie & 8k keypoints), which works fine.

If I try to execute the same via scripting, i get different (and bad) results.
Here's my python script :
Code: [Select]
sensorFile = chunk2.addSensor()
sensorFile.label = "Cam11"
sensorFile.user_calib = PhotoScan.Calibration()
c = PhotoScan.Calibration()
c.load(calibFile)
sensorFile.user_calib = c
sensorFile.fixed = True
sensorFile.width = 2560
sensorFile.height = 2048
sensorFile.focal_length = 8.0

for cam in chunk2.cameras:
cam.sensor = sensorFile

chunk2.matchPhotos(accuracy=PhotoScan.MediumAccuracy, preselection=PhotoScan.Preselection.NoPreselection, keypoint_limit=80000, tiepoint_limit=8000)
chunk2.alignCameras()
Currently working with 1.2.6 Pro

What am I doing wrong ?
What should I change in my script to get the exact same result as with the GUI ?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #22 on: January 31, 2017, 06:34:05 PM »
Hello totoromo,

What happens when you open Camera Calibration window from GUI after loading the calibration information from script?

I suggest to put sensorFile.user_calib = c assignment after defining sensor width and height.
Best regards,
Alexey Pasumansky,
Agisoft LLC

totoromo

  • Newbie
  • *
  • Posts: 4
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #23 on: January 31, 2017, 06:52:15 PM »
Hi Alexey,

Thanks for your quick answer.
When Iopen Camera Calibration window from GUI after loading the calibration information from script, i don't notice any difference from what is done when i load the calibration manually (values are apparently correctly loaded).

I tried to put sensorFile.user_calib = c assignment after defining sensor width and height, but it doesn't change anything.

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #24 on: January 31, 2017, 07:35:15 PM »
Hello totoromo,

Can you send two project saved in PSZ format (or one project with two chunks) that represent both approaches and also a calibration file that you are loading to support@agisoft.com?
Best regards,
Alexey Pasumansky,
Agisoft LLC