Forum

Author Topic: Focal Length Calculation  (Read 6818 times)

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Focal Length Calculation
« on: March 17, 2017, 12:26:30 PM »
While doing the image alignment process for generating orthophotos, I assume that Agisoft calculates the focal length internally (if it is not available in the EXIF data). Is there any way to access this calculated value of the focal length through the software API?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #1 on: March 20, 2017, 05:19:23 PM »
Hello varadg,

Each camera calibration group (chunk.sensors[0] instance, for example) contains the adjusted calibration values in sensor.calibration, so you can access the same values that you see from the GUI in the Adjusted tab of Camera Calibration window, for example:
Code: [Select]
sensor.calibration.f
sensor.calibration.cx
sensor.calibration.cy
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #2 on: March 21, 2017, 11:01:09 AM »
Thanks for the reply Alexey. Very helpful.

Related to this, I wanted to ask another question : In my processing, I am using the same camera over multiple projects - and the calibration parameters of the same are NOT embedded in the EXIF data of the images. I was thinking that I would let Agisoft process the first project as is and generating estimates for the calibration parameters. Then, I could embed this data into the EXIF of images used in the other projects and can potentially improve the speed of processing.

Is this a valid approach? If yes, which EXIF information should I focus on embedding within the images?


Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #3 on: March 21, 2017, 11:14:38 AM »
Hello varadg,

If you wish to use the results of camera calibration from one project in the other projects, you can export the calibration from the Camera Calibration window of the processed project ot XML format, then load it to another project via the same window and Fix the calibration, thus preventing PhotoScan from the adjusting of the values, however, I don't think you'll get considerable speed up with such approach.

Using the API you can save the calibration for the given calibration group:
Code: [Select]
sensor.calibration.save(path)If you need to import the calibration to the sensor, then use the following:
Code: [Select]
calib = PhotoScan.Calibration()
calib.load(path)
sensor.user_calib = calib
sensor.fixed = True
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #4 on: March 21, 2017, 11:45:57 AM »
Thanks for the guidance Alexey. But why do you think this will not provide speedup? I thought that calculating focal length and calibration parameters were an important and time-consuming step in the orthophoto generation process. I thought given this information beforehand would save considerable effort of the software. Is my understanding incorrect?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #5 on: March 21, 2017, 12:03:33 PM »
Hello varadg,

Estimation of the interior calibration parameters is just a substep of Align Photos operation, apart from it the procedure also includes feature point detection, image matching and exterior parameters estimation.
In principle, you can run rather quick test - align the image set as usual, letting PhotoScan to estimate the calibration parameters, then export the adjusted values, load them to the Initial tab and fix the calibration, then re-start the processing using the same parameters and compare the processing time.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #6 on: March 21, 2017, 04:38:32 PM »
Hi Alexey. I tried to do this comparison and followed the procedure described by you. However, when I load the saved calibration in the 2nd run, the matchPhotos / alignCameras process outputs 0 matches in tie points and consequently the process errors out. Any idea what I may be doing wrong or how to fix this?

Here is the relevant snippet of code -

Code: [Select]
doc = PhotoScan.app.document

chunk = doc.addChunk()
chunk.addPhotos(images)

...

calib = PhotoScan.Calibration()
calib.load(path_to_calibration.xml)

sensor = doc.chunk.sensors[0]
sensor.user_calib = calib
sensor.fixed = True

chunk.matchPhotos(accuracy=PhotoScan.HighestAccuracy, preselection=PhotoScan.GenericPreselection, keypoint_limit=40000, tiepoint_limit=4000)

chunk.alignCameras(adaptive_fitting=False)
...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #7 on: March 21, 2017, 04:39:53 PM »
Hello varadg,

Have you tried to reproduce the workflow via GUI?
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #8 on: March 21, 2017, 04:43:54 PM »
No, I haven't. Since my use case is geared towards the API usage. Why will that make a difference though?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #9 on: March 21, 2017, 04:47:49 PM »
Hello varadg,

Using GUI you can check if the workflow is correct or any steps are missing.

If you reproduce the same issue through GUI, it means that something is not correct, otherwise, it would be indicating that some additional steps should be added to the script.

Also you can check after the script run, if the Initial calibration values in the Camera Calibration window are exactly the same, that you've got in the previous run and the calibration is fixed.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #10 on: March 21, 2017, 06:16:17 PM »
Hi Alexey. You were right in mentioning that providing these parameters before hand would hardly provide any speedup. I tried it through the GUI and both took approximately the same amount of time. So, I guess there is no point pursuing this further with respect to gains in performance.

So, what extra information / metadata will actually help performance? Will adding geotags in the metadata help speed up the alignment process and, hence, improve the performance of the pipeline?

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #11 on: March 22, 2017, 01:33:39 PM »
Hey Alexey. Can you give your opinion on the above question? What metadata will actually help in boosting performance noticeably?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14846
    • View Profile
Re: Focal Length Calculation
« Reply #12 on: March 22, 2017, 01:37:11 PM »
Hello varadg,

Information about the camera location coordinates will be helpful for large datasets, as it allows to use Reference pre-selection option in combination with Generic preselection to speed up the image matching stage.
Best regards,
Alexey Pasumansky,
Agisoft LLC

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #13 on: March 22, 2017, 01:55:57 PM »
Thanks a lot. I will try to embed the lat/long/alt information in the EXIF data and do a test run with the augmented dataset.

varadg

  • Newbie
  • *
  • Posts: 30
    • View Profile
Re: Focal Length Calculation
« Reply #14 on: March 27, 2017, 09:45:38 AM »
Hey Alexey. I just noticed something weird. I embedded the focal length information as EXIF tags (FocalLengthIn35mm) in the images in my project. I noticed that the processing time goes down noticeably. To be clear, I did not load calibration parameters as discussed here previously, just added focal length information to the EXIF. I tested this multiple times - the results are not as good as loading all calibration parameters, but the processing time is always lower.

Can you explain as to why this might be happening? Why does simply adding focal length information offer such an increase in performance?