bc... []

picture.cpp ( File view )

  • By shanzhu 2015-10-16
  • View(s):11
  • Download(s):1
  • Point(s): 1
			#include"picture.h"
#include <cmath>
#include <ctime>

short int Fix1(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);			//经度校正
short int Fix2(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);			//双经度校正
short int Fix3(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);			//经纬映射校正
short int Fix4(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);			//柱面校正
short int Fix5(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);			//等距球面透视投影校正

//获取文件类型
UINT16 Picture::Ftype(const char *fname)
{

	UINT16 pictype;
	ifstream pic(fname,ios::binary);
	if(pic.fail())
	{

		cout << "open failed!" << endl;
		exit(-1);
	
}
	pic.read((char *)&pictype,sizeof(UINT16));
	pic.close();
	return pictype;

}

short int Picture::Fix()
{

	
	//校正图像坐标,半径,鱼眼图像坐标(x,y),圆心,方位角,入射角,视角
	int u,v;
	double r,x,y,cx,cy,phi0=0,sita0=0,gama0=0,f;

	//插值四点坐标,矩形有效区域
	int x1,x2,y1,y2,U_L,U_R,V_B,V_T;

	//回调函数,用于选择校正公式
	short int (*fix)(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0);

	r=0.5*(w<h?w:h);
	f=r*2/3.14159265;
	cx=0.5*(w-1);
	cy=0.5*(h-1);
	U_L=floor(0.5*w-r+1.1);
	U_R=floor(0.5*w+r-1.6);
	V_B=floor(0.5*h-r+1.1);
	V_T=floor(0.5*h+r-1.6);
	cout << "半径" << r << endl;
	cout << "圆心" << cx << ',' << cy << endl;
	cout << "边界" << U_L << ',' << U_R << ',' << V_B << ',' << V_T << endl;
	//cout << "初始化变量成功" << endl;

	int i,w1=w,h1=h;
	switch(choose)
	{

	case 1:
		fix=&Fix1;
		break;
	case 2:
		fix=&Fix2;
		break;
	case 3:
		fix=&Fix3;
		break;
	case 4:
		fix=&Fix4;
		w=w*3*2;
		break;
	case 5:
		cout << "需要确定展开角度\n方位角(度):" << endl;
		cin >> phi0;
		cout << "仰角(度):" << endl;
		cin >> sita0;
		cout << "视角(度):" << endl;
		cin >> gama0;
		phi0=phi0*3.14159265/180;
		sita0=(90-sita0)*3.14159265/180;
		gama0=gama0*3.14159265/180;
		fix=&Fix5;
		break;
	default:
		cout << "无此选项" << endl;
		return -1;
	
}

	if(fix_data==NULL)
	{

		cout << "fix data failed!" << endl;
	
}
	cout << "------------\n开始校正..." << endl;

	clock_t clo1,clo2;
	clo1=clock();
	for(v=0;v<h;++v)
	{

		for(u=0;u<w;++u)
		{

			//使用计算公式
			(*fix)(u,v,cx,cy,x,y,r,f,phi0,sita0,gama0);

			//越界判断及处理
			if(x<U_L)
			{

				x=U_L;
			
}
			else if(x>U_R)
			{

				x=U_R;
			
}
			if(y<V_B)
			{

				y=V_B;
			
}
			else if(y>V_T)
			{

				y=V_T;
			
}

			//双线性插值
			x1=x;
			x2=x1+1;
			y1=y;
			y2=y1+1;
			if(fabs(x-x1)<0.0001)					//若该点x正好是整数
			{

				x2=x1;
			
}
			if(fabs(y-y1)<0.0001)					//若该点y正好是整数
			{

				y2=y1;
			
}
			////读取并记录x1,y1的rgb值			
			////读取并记录x2,y1的rgb值		
			////读取并记录x1,y2的rgb值
			////读取并记录x2,y2的rgb值
			for(i=0;i<3;++i)
			{

				fix_data[v*w*3+u*3+i]=org_data[y1*w1*3+x1*3+i]*(1-x+x1)*(1-y+y1)
					+org_data[y1*w1*3+x2*3+i]*(x-x1)*(1-y+y1)
					+org_data[y2*w1*3+x1*3+i]*(1-x+x1)*(y-y1)
					+org_data[y2*w1*3+x2*3+i]*(x-x1)*(y-y1);
			
}
		
}
	
}
	clo2=clock();
	cout << "校正完毕,耗时" << (float)(clo2-clo1)/CLOCKS_PER_SEC << endl;
	return 0;

}

//经度校正
short int Fix1(int &u,int &v,
		double &cx,double &cy,
		double &x,double &y,
		double &r,double &f,
		double &phi0,double &sita0,double &gama0)
{

	y=v;
	x=
...
...
(Please download the complete source code to view)
			
...
Expand> <Close

Want complete source code? Download it here

Point(s): 1

Download
0 lines left, continue to read

File list

Tips: You can preview the content of files by clicking file names^_^
Name Size Date
picture.cpp5.94 kB24-05-12|12:27
picture.h4.80 kB24-05-12|10:52
BMP.cpp7.40 kB27-05-12|00:21
main.cpp670.00 B24-05-12|12:25
...

picture.cpp (6.43 kB)

Need 1 point
Your Point(s)

Your Point isn't enough.

Get point immediately by PayPal

More(Debit card / Credit card / PayPal Credit / Online Banking)

Submit your source codes. Get more point

LOGIN

Don't have an account? Register now
Need any help?
Mail to: support@codeforge.com

切换到中文版?

CodeForge Chinese Version
CodeForge English Version

Where are you going?

^_^"Oops ...

Sorry!This guy is mysterious, its blog hasn't been opened, try another, please!
OK

Warm tip!

CodeForge to FavoriteFavorite by Ctrl+D