Forum

Author Topic: Calibration from xml files  (Read 3446 times)

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Calibration from xml files
« on: August 08, 2018, 04:19:21 PM »
Hi team,
I would like to ask You how can I use calibrated parameters from xml file,
I have 2 different camera exif model  , and I would like to apply different  params for different  models,
for all my cameras in few chunks from my 2 xml files (with parameters),
I've tried few combination and doe's not want to go
That my script:

Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"


for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            calib = True
        if dd == "HERO4 Session":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            calib = True

I'm taking out a meta model , printing it and working well but I cant apply my xml file , what I have to change over here ???

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Calibration from xml files
« Reply #1 on: August 08, 2018, 04:43:58 PM »
Doe's one works only for first group:
Second stay empty:
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"

cameraId = 0
for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            doc = PhotoScan.app.document
            sensor = chunk.addSensor()

            sensor.calibration = calib
            sensor.user_calib = calib
        else:
            #dd == "HERO4 Session"
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            doc = PhotoScan.app.document
            sensor = chunk.sensors[0]

            sensor.calibration = calib
            sensor.user_calib = calib

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Calibration from xml files
« Reply #2 on: August 08, 2018, 04:57:17 PM »
Hello magic,

When you are creating a new sensor, you need to copy also all the parameters, such as width, height, type. Then you should assign the new sensor to the camera:
camera.sensor = sensor
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Calibration from xml files
« Reply #3 on: August 08, 2018, 05:14:18 PM »
Hi Alexey,
I have to set the sensor to?? I can't pass the params from xml without sensor , and width and height the are already in my
xml , but modified it like this and now, it works but for all images, don't see a difference, between models , he apply my script to all cameras
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"

cameraId = 0
for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        print(camera, dd)
        if dd == "HERO4 Session":
            print(camera, " hero session")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            doc = PhotoScan.app.document.chunk
            sensor = chunk.sensors[0]
            sensor.width = camera.sensor.width
            sensor.height = camera.sensor.height
            camera.sensor = sensor
            #sensor = chunk.addSensor()

            sensor.calibration = calib
            sensor.user_calib = calib
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            doc = PhotoScan.app.document.chunk
            #sensor = chunk.addSensor()
            sensor = chunk.sensors[0]
            sensor.width = camera.sensor.width
            sensor.height = camera.sensor.height
            camera.sensor = sensor


and that is a my print for models:
Code: [Select]
2018-08-08 16:09:52 <Camera 'BR01_2018-07-24_GOPR0459.JPG'>  hero session
2018-08-08 16:09:52 <Camera 'BR01_2018-07-24_GOPR0460.JPG'> HERO4 Session
2018-08-08 16:09:52 <Camera 'BR01_2018-07-24_GOPR0460.JPG'>  hero session
2018-08-08 16:09:52 <Camera 'BR01_2018-07-24_GOPR0461.JPG'> HERO4 Session
2018-08-08 16:09:52 <Camera 'BR01_2018-07-24_GOPR0461.JPG'>  hero session
2018-08-08 16:09:52 <Camera 'G0123782.JPG'> HERO6 Black
2018-08-08 16:09:52 <Camera 'G0123782.JPG'>  hero black
2018-08-08 16:09:52 <Camera 'G0123783.JPG'> HERO6 Black
Why my if-s doe's not work???
I think there is some problem with sensor declaration, when I comment  >>sensor = chunk.sensors[0]
and I use >>sensor = chunk.addSensor() like this:
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"

cameraId = 0
for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        print(camera, dd)
        if dd == "HERO4 Session":
            print(camera, " hero session")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            doc = PhotoScan.app.document.chunk
            #sensor = chunk.sensors[0]
            sensor = chunk.addSensor()
            sensor.width = camera.sensor.width
            sensor.height = camera.sensor.height
            camera.sensor = sensor

            sensor.calibration = calib
            sensor.user_calib = calib
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            doc = PhotoScan.app.document.chunk
            sensor = chunk.addSensor()
            #sensor = chunk.sensors[0]
            sensor.width = camera.sensor.width
            sensor.height = camera.sensor.height
            camera.sensor = sensor

            sensor.calibration = calib
            sensor.user_calib = calib
I have no more models groups but my parameters are applied correctly, What I have to change Alexey??
« Last Edit: August 08, 2018, 05:28:24 PM by magic »

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Calibration from xml files
« Reply #4 on: August 08, 2018, 05:23:22 PM »
Hello magic,

In you latest script version you have removed the creation of the new sensor and applying the changes to the same sensor all the time.

Actually, you can create two new sensors prior to the loop for "session" and "black" images, specify the sensor.width and sensor.height, then import the calibration from XML for each sensor and then in the loop only define to which calibration group the camera should be assigned:
Code: [Select]
if dd == "HERO4 Session":
    camera.sensor = sensor_session
if dd == "HERO4 Black":
    camera.sensor = sensor_black
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Calibration from xml files
« Reply #5 on: August 08, 2018, 05:42:28 PM »
I don't know did I understood, should be then something like that ??
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"

cameraId = 0
for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        print(camera, dd)
        sensor = chunk.addSensor()
        sensor.width = camera.sensor.width
        sensor.height = camera.sensor.height
        calib = PhotoScan.Calibration()
        sensor_session = calib.load(session_xml)
        sensor_black =calib.load(black_xml)
        #doc = PhotoScan.app.document
        # sensor = chunk.sensors[0]

        sensor.calibration = calib
        sensor.user_calib = calib
        if dd == "HERO4 Session":
            print(camera, " hero session")
            camera.sensor = sensor_session

        if dd == "HERO6 Black":
            print(camera, " hero black")
            camera.sensor = sensor_black
But when I run it ,have an error:
Code: [Select]
     24         if dd == "HERO4 Session":
     25             print(camera, " hero session")
---> 26             camera.sensor = sensor_session
     27
     28         if dd == "HERO6 Black":

TypeError: expected  PhotoScan.Sensor object

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Calibration from xml files
« Reply #6 on: August 08, 2018, 05:53:23 PM »
Or something like that Alexey ?? still have all cameras separated , not two models
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"

cameraId = 0
for chunk in PhotoScan.app.document.chunks:
    #chunk.estimateImageQuality(chunk.cameras)
    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        print(camera, dd)
        if dd == "HERO4 Session":
            print(camera, " hero session")
            calib = PhotoScan.Calibration()
            calib.load(session_xml)
            doc = PhotoScan.app.document
            #sensor_session = chunk.sensors[0]
            sensor_session = chunk.addSensor()
            sensor_session.width = camera.sensor.width
            sensor_session.height = camera.sensor.height
            camera.sensor = sensor_session

            sensor_session.calibration = calib
            sensor_session.user_calib = calib
        if dd == "HERO6 Black":
            print(camera, " hero black")
            calib = PhotoScan.Calibration()
            calib.load(black_xml)
            doc = PhotoScan.app.document
            sensor_black = chunk.addSensor()
            #sensor_black = chunk.sensors[0]
            sensor_black.width = camera.sensor.width
            sensor_black.height = camera.sensor.height
            camera.sensor = sensor_black

            sensor_black.calibration = calib
            sensor_black.user_calib = calib

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14813
    • View Profile
Re: Calibration from xml files
« Reply #7 on: August 08, 2018, 07:59:57 PM »
Hello magic,

I see it as something like the following:

Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"
calib_black = PhotoScan.Calibration()
calib_session = PhotoScan.Calibration()
calib_session.load(session_xml)
calib_black.load(black_xml)


doc = PhotoScan.app.document
for chunk in doc.chunks:

    sensor_session = chunk.addSensor()
sensor_black = chunk.addSensor()
sensor_session.width = calib_session.width
sensor_session.height = calib_session.height
sensor_black.width = calib_black.width
sensor_black.height = calib_black.height
sensor_session.user_calib = calib_session
sensor_black.user_calib = calib_black

    for camera in chunk.cameras:

        cam_model = camera.photo.meta["Exif/Model"]
        print(camera, cam_model)
        if cam_model == "HERO4 Session":
            print(camera, " hero session")
            camera.sensor = sensor_session
        elif cam_model == "HERO6 Black":
            print(camera, " hero black")
            camera.sensor = sensor_black
else:
    print(camera, " skipped")
Best regards,
Alexey Pasumansky,
Agisoft LLC

magic

  • Jr. Member
  • **
  • Posts: 53
    • View Profile
Re: Calibration from xml files
« Reply #8 on: August 13, 2018, 01:33:55 PM »
I've modified that a little and it's working too, Thanks Alexey :-)
Code: [Select]
import PhotoScan

black_xml = "F:\calibration_ps\CAL_HERO6_2.xml"            ### PATH POUR HERO6 BLACK
session_xml = "F:\calibration_ps\CAL_SESSION4_2.xml"       ### PATH POUR HERO4 SESSION
doc = PhotoScan.app.document

for chunk in doc.chunks:
    calib_session = PhotoScan.Calibration()
    sensor_session = chunk.addSensor()
    calib_session.load(session_xml)
    sensor_session.width = calib_session.width
    sensor_session.height = calib_session.height
    sensor_session.user_calib = calib_session
    calib_black = PhotoScan.Calibration()
    calib_black.load(black_xml)
    sensor_black = chunk.addSensor()
    sensor_black.width = calib_black.width
    sensor_black.height = calib_black.height
    sensor_black.user_calib = calib_black

    for camera in chunk.cameras:
        #print(camera)
        dd = camera.photo.meta["Exif/Model"]
        print(camera, dd)
        if dd == "HERO4 Session":
            camera.sensor = sensor_session

        if dd == "HERO6 Black":
            print(camera, " hero black")
            camera.sensor = sensor_black

        else:
            pass