Chessboard Pdf Open Cv

Posted on
Chessboard Pdf Open Cv Average ratng: 5,5/10 2721votes
Opencv Chessboard Pattern Pdf

I've already talked about and. Now we'll actually implement it. And we'll do it in C++. Because it's a lot more easier and make much more sense. No more stupid CV_MAT_ELEM macros. And things will just work.

Chessboard Pdf Open Cv

Apr 14, 2012 Camera calibration using a chessboard, C++, OpenCV. OpenCV chessboard detection - OpenCV function for detecting chessboards in images; MATLAB Harris corner detection - MATLAB function for performing Harris corner.

But, I won't talk about how the C++ is working. Figure it out yourself;) The setup The first thing we need for this is the latest version of OpenCV. If you're using 1.0 or 1.1pre or any of those, you need to get the latest version. It has the C++ interface. Previous version simply do not have it. Once you have it, if you use Visual Studio. If not, check around the OpenCV wiki, and you should see where you can find instructions for your IDE.

Onto the project Once you have your IDE or whatever environment setup, start by creating a new project. Include the standard OpenCV headers. Vector >object_points; vector >image_points; What do these mean? For those unfamiliar with C++, a 'vector' is a list. This list contains items of the type mentioned within the angular brackets (it's called generic programming). So, we're creating a list of list of 3D points (Point3f) and a list of list of 2D points (Point2f). Object_points is the physical position of the corners (in 3D space).

This has to be measured by us. [write relationg between each list item and list's eh you get the point] image_points is the location of the corners on in the image (in 2 dimensions). Once the program has actual physical locations and locations on the image, it can calculate the relation between the two. And because we'll use a chessboard, these points have a definite relations between them (they lie on straight lines and on squares). So the 'expected' - 'actual' relation can be used to correct the distortions in the image. Next, we create a list of corners. This will temporarily hold the current snapshot's chessboard corners. Visual Basic 6 By Gary Cornell Free Ebook here.

We also declare a variable that will keep a track of successfully capturing a chessboard and saving it into the lists we declared above. Mat image; Mat gray_image; capture >>image; The >>is the C++ interface at work again! Next, we do a little hack with object_points. Ideally, it should contain the physical position of each corner. The most intuitive way would be to measure distances 'from' the camera lens. That is, the camera is the origin and the chessboard has been displaced. Usually, it's done the other way round.

The chessboard is considered the origin of the world. So, it is the camera that is moving around, taking different shots of the camera. So, you can set the chessboard on some place (like the XY plane, of ir you like, the XZ plane). Mathematically, it makes no difference which convention you choose.

But it's easier for us and computationally faster in the second case. We just assign a constant position to each vertex. And we do that next. Vector obj; for ( int j = 0; j. CalibrateCamera ( object_points, image_points, image. Size (), intrinsic, distCoeffs, rvecs, tvecs ); After this statement, you'll have the intrinsic matrix, distortion coefficients and the rotation+translation vectors.

The intrinsic matrix and distortion coefficients are a property of the camera and lens. So as long as you use the same lens (ie you don't change it, or change its focal length, like in zoom lenses etc) you can reuse them. In fact, you can save them to a file if you want and skip the entire chessboard circus!

Note: The calibrateCamera function converts all matrices into 64F format even if you initialize it to 32F. Thanks to Michael Koval! Now that we have the distortion coefficients, we can undistort the images. Here's a small loop that will do this.

Release (); return 0; } My results I ran this program on a low quality webcam. I used a hand-made chessboard pattern and used 20 chessboard positions to calibrate. Here's an undistort I did: Make your own chessboard! If you're not working at some university, its very likely you don't have a chessboard pattern that will work perfectly. You need an asymmetric chessboard: 5x6 or a 7x8 or27x3. So make one yourself.

Take a piece of paper and draw on it with a marker. Paste it on some cardboard. I made mine from a small notebook page. It's a 5x4 chessboard. Not very big, but it works. Here's what it looks like: You can even see the lines from the notebook.: But the inner corners are detected pretty well. You'll definitely want a better one if you work with higher resolutions.

If you're looking for precision, get it printed. Here's a picture that you can print on an A4 size paper at 300dpi (its PNG and around 35kb in size).