双目相机空间坐标重建.图像畸变处理(四)

news/2024/7/21 6:13:17 标签: 计算机视觉, opencv, 图像处理

双目相机空间坐标重建.图像畸变处理(四)

在这里插入图片描述

cv::Mat Im0 = cv::imread(“E:\zcb_work\2113\pic\ch1\left11.jpg”, 0);
if (Im0.empty())
return -1;
printf("++++ open image succesful +++\r\n");
imshow(“image0”, Im0);

double fx1 = 534.10766364;//mm
double fy1 = 534.01052742;//mm
double cx1 = 341.14525437;//mm
double cy1 = 234.85237461;//mm

double k1 = -0.291268580087220;
double k2 = 0.112956040249740;
double p1 = 0.000644024243857767;
double p2 = -0.000278487828264588;
double k3 = 0;

#if 1
//pic2 camera position
printf("pic2 camera position\r\n");	
{
		int i = 0;
		int j = 0;
		for( i = 0; i < h;i++)
		{			
			for( j = 0; j < w ;j++)
			{
			        double xDistortion = (j - cx1) / fx1;
			        double yDistortion = (i - cy1) / fy1;

			        double xCorrected, yCorrected;

			        double x0 = xDistortion;
			        double y0 = yDistortion;
					
			        for (int j = 0; j < 10; j++)
			        {
			            double r2 = xDistortion*xDistortion + yDistortion*yDistortion;

			            double distRadialA = 1 / (1 + k1 * r2 + k2 * r2 * r2 + k3 * r2 * r2 * r2);
			            double distRadialB = 1;

			            double deltaX = 2* p1 * xDistortion * yDistortion + p2 * (r2 + 2 * xDistortion * xDistortion);
			            double deltaY = p1 * (r2 + 2* yDistortion * yDistortion) + 2* p2 * xDistortion * yDistortion;

			            xCorrected = (x0 - deltaX)* distRadialA * distRadialB;
			            yCorrected = (y0 - deltaY)* distRadialA * distRadialB;

			            xDistortion = xCorrected;
			            yDistortion = yCorrected;
			        }
					
				Pxy1[2*(i * w + j) + 0] = fx1 * xCorrected +cx1;
				Pxy1[2*(i * w + j) + 1] = fy1 * yCorrected +cy1;
				
				 if((0 < Pxy1[2*(i * w + j) + 0]  &&  Pxy1[2*(i * w + j) + 0]< Im0.cols - 1) \
				&& (0 < Pxy1[2*(i * w + j) + 1]  &&  Pxy1[2*(i * w + j) + 1]< Im0.rows - 1))
				{
					Im2.at<uchar>(round(Pxy1[2*(i * w + j) + 1]),round(Pxy1[2*(i * w + j) + 0])) = Im0.at<uchar>(i, j);
					Im3.at<uchar>(i, j) = Im0.at<uchar>(round(Pxy1[2*(i * w + j) + 1]),round(Pxy1[2*(i * w + j) + 0]));
				}
			}
		}
}
#endif

imshow(“image2”, Im2);
imshow(“image3”, Im3);

在这里插入图片描述

在这里插入图片描述


http://www.niftyadmin.cn/n/883482.html

相关文章

双目相机空间坐标重建.拼接融合(五)

双目相机空间坐标重建.拼接融合&#xff08;五&#xff09; // testOpenCV.cpp : 定义控制台应用程序的入口点。 //#include "stdafx.h"#pragma warning(disable : 4996)#include "stdafx.h" #include <iostream> #include <vector> #include …

双目相机空间坐标重建.之直线投影(六)

双目相机空间坐标重建.之直线投影&#xff08;六&#xff09;

图像融合之.金字塔(六)

https://zhuanlan.zhihu.com/p/58722618 这其实也是一种Alpha融合&#xff0c;实际上上面的过程就是&#xff1a; leftImageWeight * leftImage rightImageWeight * rightImage OutputImage 其中&#xff1a; leftImageWeight rightImageWeight 1

水平视角垂直视角概念

水平视角垂直视角概念&#xff0c;如下作图&#xff0c;指的是水平上&#xff0c;视野宽度&#xff0c;右图&#xff0c;是垂直方向上&#xff0c;视野高度。

opencv柱面投影,C语言实现

在做全景拼接的时候&#xff0c;为了保持图片中的空间约束与视觉的一致性&#xff0c;需要进行柱面投影&#xff0c;否则离中心图像距离越远的图像拼接后变形越大。 柱面投影公式为 这个是https://blog.csdn.net/zouxin_88/article/details/85167602的代码&#xff0c;rgb彩色…

opencv将图像拷贝到待合并图像的感兴趣区域

将图像拷贝到待合并图像的感兴趣区域 #include<cv.h> #include<highgui.h> using namespace cv;int main() {Mat image1imread("1.jpg");Mat image2imread("2.jpg");if (image1.empty() || image2.empty()){printf("open error");r…

OpenCV SURF图像拼接、配准和图像融合技术(一)

SURF的构建流程是&#xff1a;构建Hessian矩阵、H矩阵判别式、构建尺度空间、精确定位特征点、主方向确定、特征点描述子生成、误匹配点剔除、融合图像、优化连接处的图像。 下面是 博主抄袭别人改进的 //zjy 2021.7.19 周五 SURF图像融合 #include <iostream> #i…

Opencv Surf特征实现图像无缝拼接生成全景图像(二)

https://blog.csdn.net/b695886658/article/details/80856080?utm_mediumdistribute.pc_relevant.none-task-blog-2defaultbaidujs_baidulandingword~default-0.essearch_pc_relevant&spm1001.2101.3001.4242.1 找到图像1和图像2中最强的匹配点所在的位置通过映射矩阵变换…