OpenCV - calibrate the camera using still images in water

I have a camera mounted vertically underwater in a tank, looking down. There is a flat grid on the bottom of the tank (approximately 2 m from the camera). I want to be able to place markers at the bottom and use computer vision to find out the exact position of their real life.

So, I need to display from pixels to mm. If I'm not mistaken, cv :: calibrateCamera (...) does just that, but depends on moving the template in front of the camera. I only have static shots of the scene, and the camera never moves in relation to the grid. This way, I only have a “single” image to find the options. How to do this using a grid?

Thanks.

+4
source share
2 answers

An interesting problem! The “pretty” part is the effect on the internal refractive parameters at the water-glass interface, namely an increase in the focal length (or, conversely, a decrease in the field of view) compared to the same lens in air. Theoretically, you can calibrate in air and then correct the difference in refractive index, but calibrating directly in water is likely to give you more accurate results.

Do you know your accuracy requirements? And have you checked that your lens / sensor combination is adequate to match (with sufficient margin)? To answer the question that you need to evaluate (either by calculating from the specification of the lens and sensor, or experimentally using a resolution chart), can you resolve the minimum distances required by your application on the image.

From the wording of your question, I think that you are only interested in measurements on one plane. Thus, you only need to (a) eliminate the non-linear distortion of the lens (barrel or pad) and (b) evaluate the homography between the plane of interest and image. After you acquire the latter, you can directly convert from the undistorted coordinates of the image into the world using matrix multiplication. In addition, if (as I believe) the plane of interest is approximately parallel to the image plane, you should have no problem keeping the entire field of view.

Of course, in order for all this to work as expected, you must make sure that the bottom of the tank is really flat, within the tolerances for measuring your application. Otherwise, you are really dealing with a 3D problem, and you need to change your procedures accordingly.

The actual procedure is highly dependent on the size of the tank, which you do not indicate clearly. If it is small enough to make a movable calibration target, like a chessboard, by all means. You can see this other answer for suggestions. Below I will talk about a more interesting case when your tank is large, for example. size of the swimming pool.

I would continue by holding the calibration markers in a regular grid at the bottom of the pool. I would choose markers such as these , perhaps I printed them myself with a good laser printer on plastic with an adhesive backing (provided that you can leave them in place forever). You should plan on having several of them, say, an 8x8 or 10x10 grid, covering as much of the camera’s field of view in the working position and position as possible. To facilitate grid alignment, you can use a laser projector with a suitable fan angle or a laser pointer attached to a rotating support. Note that there is no need for them to be attached to the exact XY grid (which can be complicated, depending on the size of your pool), only that their positions with respect to any arbitrarily selected (but fixed) three of them will be known. In other words, you can attach them to the base approximately in a grid, and then measure the distances of the three extreme corners from each other as accurately as you can, thereby creating a basic triangle, and then measure the distances of all other corners from the top of the triangle, and finally , restore their true position with a little trigonometry. This is basically a shooting issue, and depending on your accuracy and budget requirements, you might want to enroll a local friendly professional surveyor (and their tools) to make it as accurate as possible.

Once you have the grid, you can fill the pool, get the camera, focus and f-stop the lens as needed for the application. From now on, you can not touch the focus and f-stop ever again, under a miscalibrating penalty - exposure can only be controlled by exposure time, so make sure you have enough light. Turn off all autofocus and auto iris functions, if any. If the camera has a non-rigid lens mount (such as DLSR), you will need some kind of mechanical installation to make sure that the lens-body pair remains rigid. F-stop as close as possible, given the available light and sensor to have an available depth of field. Then take a few photos (~ 10) of the grid by moving and turning the camera, and move a little closer and further than the expected distance from the plane. You will want to “see” on some images some significant perspective of the grid angle - this is necessary for accurate calibration of the focal length. Avoid JPG and any other lossy compression format when storing images - use lossless PNG or TIFF.

Once you have the images, you can manually mark and identify validation markers in the images. For a one-time project like this, I wouldn’t worry about automatic identification, just do it manually (for example, in Matlab or even in Photoshop or Gimp). To help identify markers, you can, for example, type a number next to them. Once you have manual tags, you can automatically refine them to subpixel accuracy, for example. using cv :: findCornerSubpix.

You are almost ready. Submit the “control” measured position of real angles and observed in all images to your favorite camera calibration program, for example. summary :: calibrateCamera. You use the nominal focal length of the camera (converted to pixels) for an initial estimate along with zero distortion. If all goes well, you will get the internal parameters of the camera that you save, and the camera will fit on all the images that you throw away.

Now you can set the camera in your final setting, if necessary for your application, and make another image of the grid. Mark and specify the angular positions as before. Undistort their image position using the distortion parameters returned by the calibration. Finally, calculate the homography between the original positions of the real markers (in meters) and their undistorted positions, and you're done.

NTN

+3
source

To calibrate the camera, you will need several images of a chessboard (or one of the other patterns found here ). What you can do is calibrate the camera outside the water or perform a sequential calibration.

As soon as you have this information (focal length, lens center, distortion, etc.). You can use solvePNP to evaluate the orientation of a single board. This rating gives you the distance from the camera to the board.

A completely different alternative could be to find which lens the camera is using and manually fill in the data. I have not tried this, so I'm not sure how much this will work.

+1
source

Source: https://habr.com/ru/post/1492681/


All Articles