Forum

Author Topic: New cameras after 'Undistort photos'?  (Read 6843 times)

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
New cameras after 'Undistort photos'?
« on: January 24, 2017, 05:16:38 PM »
The Tools > Export > Undistort photos function will create idealized images by removing lens distortion from the original photos, right?

Is there some way to also idealize the cameras, such that the new cameras match optimally to the undistorted images?

Or do I need to create a new project from those undistorted images and force the new camera model to be without any distortion coefficients?

Thanks!

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #1 on: February 01, 2017, 10:01:55 PM »
The Tools > Export > Undistort photos function will create idealized images by removing lens distortion from the original photos, right?

Is there some way to also idealize the cameras, such that the new cameras match optimally to the undistorted images?

Or do I need to create a new project from those undistorted images and force the new camera model to be without any distortion coefficients?

Thanks!

Is there a way to recompute the cameras so they match the undistorted images (without reimporting the new images)?

Thanks!

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #2 on: February 07, 2017, 03:22:28 PM »
Anyone?

I need idealized cameras that fit to the undistorted/idealized images because I want to export the cameras for use in a 3D app which does not know about lens distortion etc.

PhotoModeler has this function, so I was hoping there is a way to do it in PhotoScan, too?

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #3 on: February 10, 2017, 12:57:21 PM »
Isn't there anyone around that has looked into this before?

Idealized cameras are needed for most  3D animation packages, so what's the best way to convert an aligned project to something that uses undistorted images AND (pure pinhole) cameras without lens distortion?

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #4 on: February 13, 2017, 01:03:10 PM »
*crickets*

*tumbleweed*

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #5 on: February 22, 2017, 08:37:05 PM »
Last attempt to elicit at least some response from anyone around here.
Is it really that unusual to want to remove the lens distortion from images and cameras in sync?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14755
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #6 on: February 22, 2017, 08:51:57 PM »
Hello maddin,

With the distortion coefficients you can calculate how the original pixel is moved to get the undistorted position. So I think that the combination of the distortion coefficients and original (distorted) photos should be equal to the undistorted photos and zero values for the distortion coefficients.
Best regards,
Alexey Pasumansky,
Agisoft LLC

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #7 on: February 22, 2017, 09:03:47 PM »
With the distortion coefficients you can calculate how the original pixel is moved to get the undistorted position. So I think that the combination of the distortion coefficients and original (distorted) photos should be equal to the undistorted photos and zero values for the distortion coefficients.

Thank you for the reply! So you are saying that I should simply export the undistorted photos and use the original camera alignment while zeroing out the distortion coefficients?
FWIW, PhotoModeler applies an additional optimization step after computing the undistorted images and removing the distortion coefficients. At least for non-trivial image center values I can see how this makes sense, no?

And is it possible to replace all camera image file paths while keeping the rest of each camera node intact?

Thanks again!

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #8 on: February 23, 2017, 06:53:29 PM »
OK, here's what I tried:

I have a project with good camera alignment (the largest camera error is 1.9 pix, the overall RMS is 0.66 pix).

With that project open, I do the following steps

1.) Export the 'adjusted' camera calibration (with all the distortion parameters) to XML
2.) Export all photos as undistorted, keeping the filename but save to a new folder
3.) Change the path of all photos to that new 'undistorted' folder
4.) Load the saved camera calibration from step 1 as 'Initial' calibration, select 'Precalibrated' and 'Fix calibration'
5.) In Camera Calibration, manually set all the camera calibration parameters except f to zero
6.) Click on 'Optimize Cameras'

--> the result is pretty bad, with camera errors as high as 20 pix

Looks like it's not that straightforward to convert a project to use undistorted images.
First thing that comes to my mind is that key/tie points as well as all marker placements would need to be undistorted as well, right?

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14755
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #9 on: February 24, 2017, 06:01:09 PM »
Hello maddin,

You can calculate the "calibration" for the undistorted images modifying the adjusted values:
- k1, k2, k3, k4 = 0;
- p1, p2, p3, p4 = 0;
- b2 = 0;
- if "square pixels" option was used in the Undistort dialog, then b1 = 0;
- if "center principle point" option was used, then cx = cy = 0.

According to these modifications input the values to the Initial values and use Fix Calibration flag.
Best regards,
Alexey Pasumansky,
Agisoft LLC

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #10 on: February 24, 2017, 06:38:23 PM »
You can calculate the "calibration" for the undistorted images modifying the adjusted values:
- k1, k2, k3, k4 = 0;
- p1, p2, p3, p4 = 0;
- b2 = 0;
- if "square pixels" option was used in the Undistort dialog, then b1 = 0;
- if "center principle point" option was used, then cx = cy = 0.

According to these modifications input the values to the Initial values and use Fix Calibration flag.

That's what I did but the result was a very bad alignment. I had to redo everything: Import the undistorted photos, rerun the alignment and clean the sparse point cloud, then build the dense point cloud.

Would have been great to be able to reuse the original alignment...

Alexey Pasumansky

  • Agisoft Technical Support
  • Hero Member
  • *****
  • Posts: 14755
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #11 on: February 24, 2017, 06:41:48 PM »
Hello maddin,

And what happens, if you just swap the images in the original set to undistorted photos and modify the calibration parameters as mentioned above?
Best regards,
Alexey Pasumansky,
Agisoft LLC

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #12 on: February 24, 2017, 06:48:27 PM »
And what happens, if you just swap the images in the original set to undistorted photos and modify the calibration parameters as mentioned above?

That's exactly what I tried. Since the undistorted photos change pixels quite a bit (distortion removed, pixels cropped), none of the image features/points is in the right place anymore, thus the alignment is really bad.

BTW, shouldn't "undistort" try not to delete any pixels but rather create black borders?

maddin

  • Full Member
  • ***
  • Posts: 161
    • View Profile
Re: New cameras after 'Undistort photos'?
« Reply #13 on: February 24, 2017, 10:08:27 PM »
I stand corrected: Just tested this again using the Agisoft Doll tutorial, to make sure I have well-aligned cameras.
When exporting the undistored photos and the model as FBX, the photos and the mesh DO align nicely in 3ds Max (ignoring the annoying FBX bug that causes the data to be rotated by 90 degrees).

So the FBX export seems to turn the camera model into a pinhole camera, and the undistort takes care of the photos, no need to mess around with the camera calibration inside of PS.