# How many distortion values to include

**URL:** <https://forum.opencv.org/t/how-many-distortion-values-to-include/5408>\
**Category:** C++\
**Tags:** calib3d\
**Created:** [September 29, 2021, 6:15pm UTC](https://forum.opencv.org/t/how-many-distortion-values-to-include/5408 "2021-09-29T18:15:07Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rg0001](https://avatars.discourse-cdn.com/v4/letter/r/9dc877/32.png) [@rg0001](https://forum.opencv.org/u/rg0001)\
**Post date:** [September 29, 2021, 6:15pm UTC](https://forum.opencv.org/t/how-many-distortion-values-to-include/5408/1 "2021-09-29T18:15:07Z")

</div>

So I have a calibrate program that works well and outputs intrinsic data such as the camera intrinsics and 5 distortion coefficients. Recently I encountered a program (below) that uses 4 of the available 5 distortion coefficients. Which 4 of the 5 do I use (I’ve commented the 5th out otherwise it will produce an exception)? Below is the program that uses the 4 distortion coefficients I am assuming the coefficients follow k1, k2, p1, p2, k3?

Is there any general rule of thumb about which parameter to ignore when your distal coefficients total less than what’s available?

```auto
#include "pch.h"

#include <iostream>
#include <opencv2/highgui.hpp>
#include <opencv2/calib3d.hpp>
#include <opencv2/core/mat.hpp>

// set mats
/**/
using namespace std;
using namespace cv;

void set_camIntrinsics(Mat &cam_intrinsic, Mat &distCoeffs)
{
	//set_intriniscs 
	double	CV_CX = 386.6963736491591,
		CV_CY = 234.7746525148251,
		CV_FX = 260.257998425127,
		CV_FY = 260.1583925187085;

	cam_intrinsic.at<double>(0, 0) = CV_FX;
	cam_intrinsic.at<double>(1, 0) = 0.0;
	cam_intrinsic.at<double>(2, 0) = 0.0;

	cam_intrinsic.at<double>(0, 1) = 0.0;
	cam_intrinsic.at<double>(1, 1) = CV_FY;
	cam_intrinsic.at<double>(2, 1) = 0.0;

	cam_intrinsic.at<double>(0, 2) = CV_CX;
	cam_intrinsic.at<double>(1, 2) = CV_CY;
	cam_intrinsic.at<double>(2, 2) = 1.0;
	// new coeffs 11.29.19

	double	CV_K1 = -0.2666308246430311,
		CV_K2 = 0.06474699227144737,
		CV_P1 = 0.0003621024764932747,
		CV_P2 = -0.000726010205813438,
		CV_P3 = -0.006384634912197317;

	distCoeffs.at<double>(0) = CV_K1;
	distCoeffs.at<double>(1) = CV_K2;
	distCoeffs.at<double>(2) = CV_P1;
	distCoeffs.at<double>(3) = CV_P2;
	//distCoeffs.at<double>(4) = CV_P3;
}
int main()
{
	cv::Mat cam_intrinsic = cv::Mat(3, 3, CV_64F, double(0));
	cv::Mat distCoeffs = cv::Mat(1, 4, CV_64F, double(0));

	set_camIntrinsics(cam_intrinsic, distCoeffs);

	cv::Mat input_frame = cv::imread("fisheye_pic.png");
	cv::Mat output_frame;

	cv::fisheye::undistortImage(input_frame, output_frame, cam_intrinsic, distCoeffs, cv::noArray(), cv::Size(input_frame.cols, input_frame.rows));

	cv::imshow("Input Image", input_frame);
	cv::imshow("Output Image", output_frame);
	cv::waitKey(-1);
	return 0;

	cv::waitKey(1);
}

```
