Forum

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

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
How to load calibration Camera parameter in batch file
« on: November 04, 2016, 06:01:26 PM »
Hi to all,
I'm new I've built my own scanner with 8 canon and a rotating platform.

I made the cameras calibration with Lens and exported them in xml files.
In my workflow I use a python batch file to start a multiple psx files list and it works well.

My problem is the time consuming operation to load each time in each psx file the camera calibration parameter before starting with my batch file.

Is it possible to keep that value in the memory of Photoscan? Or is there  something that I can add to my python file to automatic load the camera calibration parameter?

My photos name are i.e. name of customer IMG_1000020.jpg where the number 1 is my camera and 20 is the 20th shoot of that camera.

Please help me to understand,

bye

Davide
« Last Edit: November 04, 2016, 06:03:49 PM by davide1970 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14010
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #1 on: November 04, 2016, 06:14:26 PM »
Hello Davide,

So you have separate XML file for each camera, is that correct?
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #2 on: November 04, 2016, 06:22:51 PM »
Hello Alexey,
yes I've separated XML file for each camera
« Last Edit: November 05, 2016, 02:23:00 PM by davide1970 »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14010
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #3 on: November 05, 2016, 07:37:42 PM »
Hello Davide,

Then you need to create a separate camera calibration groups for each camera, via Python it can be done using sensor instances - each camera should have it's own sensor assigned and then load calibration to each sensor instance.

I'll try to post the example shortly.
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #4 on: November 07, 2016, 05:13:25 PM »
Hello Alexey,
It'll be great!!!
because I'm not strong on Python but if you give me an example I can use it and customize it myself.
thank you

bye

Davide
 

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #5 on: November 07, 2016, 07:13:39 PM »
Dear Alexey,
looking for a solution I found your suggestion to another user with similar problem. I tried to use the code you suggest but unfortunately I can not use it.
You suggested to use the following code:

        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)

I customized it in the following way but it dosen't work...

        camera = PhotoScan.Camera()
        camera.open(E:\OBJ\FracescaImg10000022.jpg)
        camera.label = camera.path.rsplit("/",1)[1]

        sensor = PhotoScan.Sensor()
   sensor.width = 3456
   sensor.height = 5184
        sensor.user_calib.load(E:\OBJ\camera1.xml)
        sensor.fixed = True

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


can you please help me to understand?

thank you

davide
 


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.
« Last Edit: November 07, 2016, 07:20:58 PM by davide1970 »

Alexey Pasumansky

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

I think that the following code should work for the project with already loaded cameras, providing that calibration files are stored in the same folder with the photos and have the same names (only different extension):

Code: [Select]
import PhotoScan

chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    path = camera.photo.path[:-3] + "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

Let me know, if it works.
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #7 on: November 07, 2016, 11:21:13 PM »
Hello Alexey,
unfortunately it doesn't work, and I think it's my fault, here below you can find what I wrote and attached the error the software gave me back, can you help me?

import PhotoScan
print("Start loading calibration")
chunk = PhotoScan.app.document.chunk
for camera in chunk.cameras:
    path = camera.photo.path[:-3] + "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(5184)
    s.height = camera.photo.image(3456)
    camera.sensor = s
print("finish loading calibration")


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14010
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #8 on: November 08, 2016, 01:54:08 AM »
Hello Davide,

Yuu do not need to modify the lines:

Code: [Select]
s.width = camera.photo.image().width
s.height = camera.photo.image().height
or just use the direct assignment, s.width = 5184 and s.height = 3456, if you are confident that the image resolution would be the same.
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #9 on: November 08, 2016, 10:37:04 AM »
Hello Alexey,
thank you, now it works!!!

In one of your previews message you mentioned the possibility to use sensor instances, is it possible?
Do you think use sensor instances will be easier? Now i've to edit each time the name of 200 xml files because my photos contain the name of the client and it's always different.

thank you for understanding

Davide

Alexey Pasumansky

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

It's necessary to have some kind of correspondence between the image (camera) and XML that should be loaded. In this script sample the same naming convention is used, but, for example, it might be possible to use the order of cameras, if it is the same in each project.
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #11 on: November 08, 2016, 12:42:24 PM »
Hello Alexey,
I don't want to abuse of your patient and I need a solution.

My file photo structure is i.e. name_surnameIMG50000012.jpg where 5 is the name of the camera and 12 is the number of the photo that camera 5 made.

So I need to link camera5.xml file to all the 20 file.jpg

than I've to make the same thing with the other 7 cameras.

I can not write this link, can you help me?

Davide

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14010
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #12 on: November 08, 2016, 12:49:57 PM »
Hello Davide,

So there are only seven cameras, right? And just to confirm the naming convention, is it ...IMG5.... or IMG_5....?
Best regards,
Alexey Pasumansky,
Agisoft LLC

davide1970

  • Newbie
  • *
  • Posts: 11
    • View Profile
Re: How to load calibration Camera parameter in batch file
« Reply #13 on: November 08, 2016, 01:02:02 PM »
Hello Alexey,
I've 8 cameras and yes the naming convention is ...IMG5...
« Last Edit: November 08, 2016, 01:36:04 PM by davide1970 »

Alexey Pasumansky

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

Then you can use the following code to get the index of camera.xml file and path to the file (these lines should substitute the path variable definition in the previous code):

Code: [Select]
index  = camera.label[c.label.find("IMG") + 3]
path = camera.photo.path.rsplit("/",1)[0] + "/camera" + index + ".xml"
Best regards,
Alexey Pasumansky,
Agisoft LLC