图片内定向

**

内定向

**

#include "iostream"
#include "fstream"
#include "opencv2\opencv.hpp""
using namespace std;



int _Interior_orientation()
{
	ifstream file;
	file.open("E:\\专业课作业\\摄影测量\\内定向程序设计\\rc30.txt",ios::in);//打开文件

	double x0, y0,f;//三个内方位元素
	double Frame_coordinates[8][2];//定义数组存放框标坐标值
	//	读取内方位元素
	file >> x0;
	file >> y0;
	file >>f;
	//读取框标坐标
	for (int x = 0; x < 8; x = x++)
	{
		for (int y = 0; y < 2; y = y++)
		{
			file >> Frame_coordinates[x][y];
		}
	}


	file.close();

	file.open("E:\\专业课作业\\摄影测量\\内定向程序设计\\行列号.txt", ios::in);
	double _RC_value[8][2];
	for (int i = 0; i < 8; i = i++)
	{
		for (int j = 0; j < 2; j = j++)
		{
			file >> _RC_value[i][j];
		}
	}
	//for (int i = 0; i < 8; i = i++)
	//{
	//	for (int j = 0; j < 2; j = j++)
	//	{
	//		cout << Frame_coordinates[i][j] << "\t\t";
	//	}
	//	cout << endl;
	//}
	file.close();

	file.open("E:\\专业课作业\\摄影测量\\内定向程序设计\\数据说明.txt", ios::in);
	double derta;
	file >> derta;
	file.close();
	//创建A矩阵
	double A[8][6];
	A[0][0] = 1;
	A[0][1] = _RC_value[0][0] * derta;
	A[0][2] = -(_RC_value[0][1] * derta);
	A[0][3] = 0;
	A[0][4] = 0;
	A[0][5] = 0;
	A[1][0] = 0;
	A[1][1] = 0;
	A[1][2] = 0;
	A[1][3] = 1;
	A[1][4] = _RC_value[0][0] * derta;
	A[1][5] = -(_RC_value[0][1] * derta);

	A[2][0] = 1;
	A[2][1] = _RC_value[1][0] * derta;
	A[2][2] = -(_RC_value[1][1] * derta);
	A[2][3] = 0;
	A[2][4] = 0;
	A[2][5] = 0;



	A[3][0] = 0;
	A[3][1] = 0;
	A[3][2] = 0;
	A[3][3] = 1;
	A[3][4] = _RC_value[1][0] * derta;
	A[3][5] = -(_RC_value[1][1] * derta);

	A[4][0] = 1;
	A[4][1] = _RC_value[2][0] * derta;
	A[4][2] = -(_RC_value[2][1] * derta);
	A[4][3] = 0;
	A[4][4] = 0;
	A[4][5] = 0;
	A[5][0] = 0;
	A[5][1] = 0;
	A[5][2] = 0;
	A[5][3] = 1;
	A[5][4] = _RC_value[2][0] * derta;
	A[5][5] = -(_RC_value[2][1] * derta);

	A[6][0] = 1;
	A[6][1] = _RC_value[3][0] * derta;
	A[6][2] = -(_RC_value[3][1] * derta);
	A[6][3] = 0;
	A[6][4] = 0;
	A[6][5] = 0;
	A[7][0] = 0;
	A[7][1] = 0;
	A[7][2] = 0;
	A[7][3] = 1;
	A[7][4] = _RC_value[3][0] * derta;
	A[7][5] = -(_RC_value[3][1] * derta);

	double L[8][1] = 
	  { Frame_coordinates[0][0], Frame_coordinates[0][1],
		Frame_coordinates[1][0], Frame_coordinates[1][1], 
		Frame_coordinates[2][0], Frame_coordinates[2][1], 
		Frame_coordinates[3][0], Frame_coordinates[3][1]};

	cv::Mat a(8, 6, CV_64FC1, A);//a为A矩阵
	//cv::Mat at(6, 8, CV_64FC1);
	cv::Mat l(8, 1, CV_64FC1, L);
	cv::Mat X(6, 1, CV_64FC1);

	X = (a.t()*a).inv()*a.t()*l;

	double m0, m1, m2, n0, n1, n2;
	m0 = X.at<double>(0, 0);
	m1 = X.at<double>(1, 0);
	m2 = X.at<double>(2, 0);
	n0 = X.at<double>(3, 0);
	n1 = X.at<double>(4, 0);
	n2 = X.at<double>(5, 0);

	cout << "m0="<< m0 << endl;
	cout << "m1=" << m1 << endl;
	cout << "m2=" << m2 << endl;
	cout << "n0=" << n0 << endl;
	cout << "n1=" << n1 << endl;
	cout << "n2=" << n2 << endl;

	int row, col;
	cout << "请输入行数" << endl;
	cin >> row;
	cout << "请输入列数" << endl;
	cin >> col;
	
	double Img_x, Img_y;
	Img_x = m0 + m1*(row*derta) - m2*(col*derta)-x0;
	Img_y = n0 + n1*(row*derta) - m2*(col*derta)-y0;

	cout << "对应的像平面坐标为(" << Img_x << "," << Img_y << ")" << endl;
	system("pause");
	return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值