<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://programmingexamples.net/w/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=OpenCV%2FCommonTasks%2FRemoveDistortion</id>
		<title>OpenCV/CommonTasks/RemoveDistortion - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://programmingexamples.net/w/index.php?action=history&amp;feed=atom&amp;title=OpenCV%2FCommonTasks%2FRemoveDistortion"/>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=OpenCV/CommonTasks/RemoveDistortion&amp;action=history"/>
		<updated>2026-04-21T12:11:12Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.23.5</generator>

	<entry>
		<id>http://programmingexamples.net/w/index.php?title=OpenCV/CommonTasks/RemoveDistortion&amp;diff=533&amp;oldid=prev</id>
		<title>Daviddoria: /* CMakeLists.txt */</title>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=OpenCV/CommonTasks/RemoveDistortion&amp;diff=533&amp;oldid=prev"/>
				<updated>2011-01-21T20:47:41Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;CMakeLists.txt&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 20:47, 21 January 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 113:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 113:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ADD_EXECUTABLE(RemoveDistortion RemoveDistortion.cxx)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ADD_EXECUTABLE(RemoveDistortion RemoveDistortion.cxx)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;TARGET_LINK_LIBRARIES(RemoveDistortion &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;opencv_core opencv_highgui&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;TARGET_LINK_LIBRARIES(RemoveDistortion &lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;${OpenCV_LIBS}&lt;/ins&gt;)&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;&amp;#160; &amp;#160; &amp;#160; &amp;#160; &amp;#160; opencv_features2d opencv_calib3d opencv_legacy opencv_contrib&lt;/del&gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;)&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Daviddoria</name></author>	</entry>

	<entry>
		<id>http://programmingexamples.net/w/index.php?title=OpenCV/CommonTasks/RemoveDistortion&amp;diff=497&amp;oldid=prev</id>
		<title>Daviddoria: Created page with '==RemoveDistortion.cxx== &lt;source lang=&quot;cpp&quot;&gt; #include &quot;cv.h&quot; #include &quot;opencv2/core/core.hpp&quot; #include &quot;opencv2/imgproc/imgproc.hpp&quot; #include &quot;opencv2/calib3d/calib3d.hpp&quot; #inclu…'</title>
		<link rel="alternate" type="text/html" href="http://programmingexamples.net/w/index.php?title=OpenCV/CommonTasks/RemoveDistortion&amp;diff=497&amp;oldid=prev"/>
				<updated>2011-01-20T23:58:31Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;#039;==RemoveDistortion.cxx== &amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt; #include &amp;quot;cv.h&amp;quot; #include &amp;quot;opencv2/core/core.hpp&amp;quot; #include &amp;quot;opencv2/imgproc/imgproc.hpp&amp;quot; #include &amp;quot;opencv2/calib3d/calib3d.hpp&amp;quot; #inclu…&amp;#039;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==RemoveDistortion.cxx==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;&lt;br /&gt;
#include &amp;quot;cv.h&amp;quot;&lt;br /&gt;
#include &amp;quot;opencv2/core/core.hpp&amp;quot;&lt;br /&gt;
#include &amp;quot;opencv2/imgproc/imgproc.hpp&amp;quot;&lt;br /&gt;
#include &amp;quot;opencv2/calib3d/calib3d.hpp&amp;quot;&lt;br /&gt;
#include &amp;quot;opencv2/highgui/highgui.hpp&amp;quot;&lt;br /&gt;
&lt;br /&gt;
#include &amp;lt;iostream&amp;gt;&lt;br /&gt;
#include &amp;lt;string&amp;gt;&lt;br /&gt;
&lt;br /&gt;
std::vector&amp;lt;cv::Point3f&amp;gt; Create3DChessboardCorners(cv::Size boardSize, float squareSize);&lt;br /&gt;
&lt;br /&gt;
struct CameraStruct&lt;br /&gt;
{&lt;br /&gt;
  cv::Mat CameraMatrix;&lt;br /&gt;
  cv::Mat ImagePoints;&lt;br /&gt;
  cv::Mat DistortionCoefficients;&lt;br /&gt;
  cv::Mat Image;&lt;br /&gt;
};&lt;br /&gt;
&lt;br /&gt;
CameraStruct CalibrateCamera(cv::Mat image, cv::Size boardSize);&lt;br /&gt;
&lt;br /&gt;
int main( int argc, char* argv[])&lt;br /&gt;
{&lt;br /&gt;
  std::string imageFileName = argv[1];&lt;br /&gt;
  std::string outputFileName = argv[2];&lt;br /&gt;
&lt;br /&gt;
  cv::Mat image = cv::imread(imageFileName, 1);&lt;br /&gt;
&lt;br /&gt;
  if(image.empty())&lt;br /&gt;
    {&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;Could not read image!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    return -1;&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  CameraStruct camera = CalibrateCamera(image, cv::Size(6,9)); // If the board does not have the name number of squares in each dimension, the order of boardSize is not important.&lt;br /&gt;
&lt;br /&gt;
  cv::Mat outputImage;&lt;br /&gt;
  cv::undistort(camera.Image, outputImage, camera.CameraMatrix, camera.DistortionCoefficients);&lt;br /&gt;
&lt;br /&gt;
  cv::imwrite(outputFileName, outputImage);&lt;br /&gt;
&lt;br /&gt;
  return 0;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
CameraStruct CalibrateCamera(cv::Mat image, cv::Size boardSize)&lt;br /&gt;
{&lt;br /&gt;
  float squareSize = 1.f; // This is &amp;quot;1 arbitrary unit&amp;quot;&lt;br /&gt;
&lt;br /&gt;
  cv::Size imageSize = image.size();&lt;br /&gt;
&lt;br /&gt;
  // Find the chessboard corners&lt;br /&gt;
  std::vector&amp;lt;std::vector&amp;lt;cv::Point2f&amp;gt; &amp;gt; imagePoints(1);&lt;br /&gt;
  bool found = findChessboardCorners(image, boardSize, imagePoints[0]);&lt;br /&gt;
  if(!found)&lt;br /&gt;
    {&lt;br /&gt;
    std::cerr &amp;lt;&amp;lt; &amp;quot;Could not find chess board!&amp;quot; &amp;lt;&amp;lt; std::endl;&lt;br /&gt;
    exit(-1);&lt;br /&gt;
    }&lt;br /&gt;
&lt;br /&gt;
  drawChessboardCorners(image, boardSize, cv::Mat(imagePoints[0]), found );&lt;br /&gt;
&lt;br /&gt;
  std::vector&amp;lt;std::vector&amp;lt;cv::Point3f&amp;gt; &amp;gt; objectPoints(1);&lt;br /&gt;
  objectPoints[0] = Create3DChessboardCorners(boardSize, squareSize);&lt;br /&gt;
&lt;br /&gt;
  std::vector&amp;lt;cv::Mat&amp;gt; rotationVectors;&lt;br /&gt;
  std::vector&amp;lt;cv::Mat&amp;gt; translationVectors;&lt;br /&gt;
&lt;br /&gt;
  cv::Mat distortionCoefficients = cv::Mat::zeros(8, 1, CV_64F); // There are 8 distortion coefficients&lt;br /&gt;
  cv::Mat cameraMatrix = cv::Mat::eye(3, 3, CV_64F);&lt;br /&gt;
&lt;br /&gt;
  int flags = 0;&lt;br /&gt;
  double rms = calibrateCamera(objectPoints, imagePoints, imageSize, cameraMatrix,&lt;br /&gt;
                  distortionCoefficients, rotationVectors, translationVectors, flags|CV_CALIB_FIX_K4|CV_CALIB_FIX_K5);&lt;br /&gt;
&lt;br /&gt;
  CameraStruct camera;&lt;br /&gt;
  camera.CameraMatrix = cameraMatrix;&lt;br /&gt;
  camera.ImagePoints = cv::Mat(imagePoints[0]);&lt;br /&gt;
  camera.DistortionCoefficients = distortionCoefficients;&lt;br /&gt;
  camera.Image = image;&lt;br /&gt;
&lt;br /&gt;
  return camera;&lt;br /&gt;
}&lt;br /&gt;
&lt;br /&gt;
std::vector&amp;lt;cv::Point3f&amp;gt; Create3DChessboardCorners(cv::Size boardSize, float squareSize)&lt;br /&gt;
{&lt;br /&gt;
  // This function creates the 3D points of your chessboard in its own coordinate system&lt;br /&gt;
&lt;br /&gt;
  std::vector&amp;lt;cv::Point3f&amp;gt; corners;&lt;br /&gt;
&lt;br /&gt;
  for( int i = 0; i &amp;lt; boardSize.height; i++ )&lt;br /&gt;
  {&lt;br /&gt;
    for( int j = 0; j &amp;lt; boardSize.width; j++ )&lt;br /&gt;
    {&lt;br /&gt;
      corners.push_back(cv::Point3f(float(j*squareSize),&lt;br /&gt;
                                float(i*squareSize), 0));&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  return corners;&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==CMakeLists.txt==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;cmake&amp;quot;&amp;gt;&lt;br /&gt;
cmake_minimum_required(VERSION 2.6)&lt;br /&gt;
&lt;br /&gt;
PROJECT(RemoveDistortion)&lt;br /&gt;
&lt;br /&gt;
FIND_PACKAGE(OpenCV REQUIRED )&lt;br /&gt;
INCLUDE_DIRECTORIES( ${OPENCV_INCLUDE_DIR} )&lt;br /&gt;
&lt;br /&gt;
ADD_EXECUTABLE(RemoveDistortion RemoveDistortion.cxx)&lt;br /&gt;
TARGET_LINK_LIBRARIES(RemoveDistortion opencv_core opencv_highgui&lt;br /&gt;
opencv_flann opencv_imgproc opencv_highgui opencv_ml opencv_video opencv_objdetect&lt;br /&gt;
          opencv_features2d opencv_calib3d opencv_legacy opencv_contrib&lt;br /&gt;
)&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Daviddoria</name></author>	</entry>

	</feed>