其他分享
首页 > 其他分享> > opencv 矫正图片

opencv 矫正图片

作者:互联网

如何矫正

如图,右边的图片最终矫正到左边这样,但是还有很大的缺陷,就是上方矫正不强图片矫正


探索以下参数的含义,实际上从图片我们可以看出,我们要裁剪掉右边一部分,右边一部分明显下陷,需要往上提,这样图片就会切除右边部分,所以下面K3 的参数是右边比左边小,7.0697810243404e+002,这个数比8.6846697810243404e+002 要小一些,下面往上提,这样下面可以拉直,可以上面就直不了了。
int main()
{

		const cv::Mat K3 = (cv::Mat_<double>(3, 3) << 7.0697810243404e+002, 0.0, 3.9050000000000000e+002
			, 0.0, 8.6846697810243404e+002, 1.1050000000000000e+002, 0.0, 0.0, 1.0);
		const cv::Mat D0 = (cv::Mat_<double>(5, 1) << -3.6802327018241026e-001, 3.515243805833121e-001, 0.0, 0.0,
			-5.7843596847939704e-001);
		cv::Mat K = K3;
		cv::Mat D = D0;

		const int ImgWidth = 800;
		const int ImgHeight = 450;

		cv::Mat map1, map2;
		cv::Size imageSize(ImgWidth, ImgHeight);
		const double alpha = 0;
		cv::Mat NewCameraMatrix = getOptimalNewCameraMatrix(K, D,
			imageSize, alpha, imageSize, 0);
		initUndistortRectifyMap(K, D, cv::Mat(), NewCameraMatrix,
			imageSize, CV_16SC2, map1, map2);

		cv::Mat frame1 = imread("c.jpg"/*, IMREAD_GRAYSCALE*/);
		int w = frame1.cols;
		int h = frame1.rows;
		cv::Mat UndistortImage1;
		remap(frame1, UndistortImage1, map1, map2, cv::INTER_LINEAR);

		//Point2f AffinePoints0[4] = { Point2f(0, 0), Point2f(800,0),
		//Point2f(0,450), Point2f(800, 450) };
		//Point2f AffinePoints1[4] = { Point2f(0, 0), Point2f(800,0),
		//	Point2f(-50,500), Point2f(850, 500) };
		//
		//Mat dst_perspective = PerspectiveTrans(UndistortImage1, AffinePoints0, AffinePoints1);
		//imshow("test2", dst_perspective);

		imshow("1", frame1);
		imshow("2", UndistortImage1);
		cv::waitKey(0);
}

修正

还有待修正,期待有经验的人员加入一起讨论。

标签:矫正,右边,Mat,K3,opencv,cv,图片
来源: https://blog.csdn.net/qianbo042311/article/details/119061460