Forum

Author Topic: Python script on precalibrated camera calibration parameters  (Read 13794 times)

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Python script on precalibrated camera calibration parameters
« on: November 15, 2013, 05:56:23 PM »
Hi all,

We finally found a good set of camera calibration parameters for all of our cameras. Now I want to implement this process into my Python pipeline so we can make 3D models completely automatically.

Searching around, I didn't find a good example on how to write the script that the parameters can be input before aligning the images together.

And if I relate Python with PhotoScan Pro interface, the "Type" under "Initial" tap of Camera Calibration interface must be "Precalibrated", and the "Fix Calibration" needs to be selected as well.

Thank you all very much for any of your input.
Nan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #1 on: November 15, 2013, 06:03:08 PM »
Hello Nan,

Camera calibration data should be applied to the sensor instance (sensors = calibration groups you see in the Camera Calibration window).

Then you need to import the calibration parameters to sensor.user_calib and set up sensor.fixed = True (if you need to fix calibration).
Best regards,
Alexey Pasumansky,
Agisoft LLC

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #2 on: November 15, 2013, 06:12:20 PM »
Hi Alexey,

Thank you so much for your super fast reply. I had some code written down but I don't think it's right. So Can you give me some example codes like if I want to input fx, fy, cx, cy, k1, k2, and k3, and also like you mentioned I want to "Fix calibration"?

Thank you so much for your time!!

Nan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #3 on: November 15, 2013, 06:15:15 PM »
Hello Nan,

If you have camera calibration .xml data for certain calibration group (=sensor):

Code: [Select]
path = "calibration.xml"
sensor.user_calib.load(path)
sensor.fixed = True

I think it should work.
Best regards,
Alexey Pasumansky,
Agisoft LLC

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #4 on: November 15, 2013, 06:27:03 PM »
Alexey,

I was trying to put all of those parameters in the code, but I think loading a pre-saved xml calibration file should work just fine.

So this part should be before the photo alignment, right?

I have code like:
new_chunk.cameras.add(path)
new_chunk.enabled=true
doc.chunks.add(new_chunk)

And after those 3 lines, the camera calibration should be inserted in, and then the code will be matching photos, llike:

doc.activeChunk.matchPhotos(accuracy="high", preselection="generic")
doc.activeChunk.alighPhotos()

Is that right place to put in the camera calibration parameters?

Thanks a lot!
Nan
« Last Edit: November 15, 2013, 06:29:26 PM by an198317 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #5 on: November 15, 2013, 06:39:17 PM »
Hello Nan,

Yes, the place is right, but I recommend to create sensor instances manually in a loop across all cameras.

Code: [Select]


        camera = PhotoScan.Camera()
        camera.open(cam_path)
        camera.label = camera.path.rsplit("/",1)[1]

        sensor = PhotoScan.Sensor()
sensor.width = camera.width
sensor.height = camera.height
        sensor.user_calib.load(calib_path)
        sensor.fixed = True

camera.sensor = sensor 
chunk.sensors.add(sensor)
chunk.photos.add(camera)


If there is only one calibration group, the script should be modified accordingly.
Best regards,
Alexey Pasumansky,
Agisoft LLC

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #6 on: November 15, 2013, 06:47:38 PM »
Hi Alexey,

Yes, we only have one calibration group for now, so where I should change the code you showed?

And I assume the sensor.width and sensor.heigh are just the image dimension, right?

Thanks,
Nan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #7 on: November 15, 2013, 06:49:15 PM »
Hello Nan,

Yes, you can just create new sensor, add it to chunk (don't forget to assign proper sensor.width and sensor.height) and than load cameras and assign camera.sensor to the created instance.
Best regards,
Alexey Pasumansky,
Agisoft LLC

an198317

  • Newbie
  • *
  • Posts: 42
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #8 on: November 15, 2013, 06:51:37 PM »
I hope this is the last question, Alexey,

What does your code "camera.label = camera.path.rsplit("/",1)[1]" mean?

Nan

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Python script on precalibrated camera calibration parameters
« Reply #9 on: November 15, 2013, 06:54:52 PM »
Hello Nan,

It assigns new label to camera according to the image filename (whole path is split from right using "slash" as a delimeter and the right part is taken).
Best regards,
Alexey Pasumansky,
Agisoft LLC