⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainfrm.cpp

📁 图像处理软件,功能比较基础
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		strcpy(inputFileName,dlg.m_sar_path);
		strcpy(inputRefSarName,dlg.m_ref_path);
		strcpy(outputtxtName,dlg.m_txt_path);	
		r=new int [dlg.m_num];
		c=new int [dlg.m_num];
		fp=fopen(dlg.m_inputpath,"r");
		fseek( fp, 76, SEEK_SET );
		fscanf( fp, "%d", &r[0] );
		fseek(fp,27,SEEK_CUR);
		fscanf(fp,"%d",&c[0]);	
		for (i=1;i<dlg.m_num;i++)
		{
			fseek(fp,41,SEEK_CUR);
			fscanf(fp,"%d",&r[i]);
			fseek(fp,27,SEEK_CUR);
			fscanf(fp,"%d",&c[i]);
		}
		fclose(fp);
	

	//===========================生成MASK图形================================	
	Picture maskpic1;
	maskpic1.row=500;
	maskpic1.col=500;
	maskpic1.p=fspace_2d(maskpic1.row,maskpic1.col);
	for(i=0;i<maskpic1.row;i++)
		for (j=0;j<maskpic1.col;j++)
			maskpic1.p[i][j]=255;
		int span;
		for (i=0;i<maskpic1.row;i++)
			for (j=0;j<maskpic1.col;j++)
			{
				span=(int)(pow(i-maskpic1.row/2,2)+pow(j-maskpic1.col/2,2));
				if(span<=Maskinner*Maskinner||span>Maskouter*Maskouter)
					maskpic1.p[i][j]=0;
			}						
			struct _timeb timebuffer,timebuffer1;				
			_ftime( &timebuffer );
			
			for(int x=0;x<dlg.m_num;x++)
			{
				inputpic.p=InputImageWithName(inputFileName,inputpic.row,inputpic.col);	
				inputref.p=InputImageWithName(inputRefSarName,inputref.row,inputref.col);	
				ref=CComlib::ImgScaleCubicLinear(inputref.p ,inputref.row,inputref.col,320,320 ) ;			
				unsigned char **ttemp,**ttempmask;
				ttemp=fspace_2d(256,256);
				ttempmask=fspace_2d(256,256);
				for(int s=0;s<256;s++)
				{
					memcpy(ttemp[s],inputpic.p[s+122]+122,256);
					memcpy(ttempmask[s],maskpic1.p[s+122]+122,256);						
				}
				POINT temppos;			
				temppos.x=temppos.y=0;
				CMatch match;										
				NPOT ret=match.SingleMatch_Box(ref,ttemp,ttempmask,320,320,256,256,temppos);							
				dspace_2d(ref,320,320);
				FILE *fp;	
				POINT tempresult;
				tempresult.x=(ret.x+128)*(inputref.row/320.0)+c[x]-(inputref.row/2);
				tempresult.y=(ret.y+128)*(inputref.row/320.0)+r[x]-(inputref.row/2);
				fp=fopen(outputtxtName,"a");
				fprintf(fp,"图片%d",x+1);												
				fprintf(fp," 理论匹配点(%d,%d), 实际匹配结果 (%d,%d),  误差(%d,%d)  ,相关cor=%f \n",c[x],r[x],tempresult.x,tempresult.y,abs(tempresult.x-c[x]),abs(tempresult.y-r[x]),ret.cor);
				fclose(fp);
				dspace_2d(inputpic.p,inputpic.row,inputpic.col);
				dspace_2d(inputref.p,inputref.row,inputref.col);
				inputpic.p=NULL;
				ChangeNameExtension1(inputFileName);
				ChangeNameExtension1(inputRefSarName);
			}
			delete[] r;
			delete[] c;
	}
	else
		return;		
}



void CMainFrame::OnTestTimeOrg() 
{
	int i,j,rect_length,rect_centre;
	int Maskinner,Maskouter;
	unsigned char **TempImg;
	RadonResult res;
	int true_theta;
	POINT firstpos,endpos;
	int num=0;
	
	CMatchDlg dlg;
	unsigned char **ref;
	FILE *fp;
	int r,c;
	
	//=======================================================================
	char inputFileName[512];
	char inputRefSarName[512];
	char outputtxtName[512];
	Picture inputpic,inputref;
	
	//=======================================================================
	//::MessageBox(NULL,"BEGIN","WARNING",MB_OK);
	//===================================初始化变量区========================
	int result[8];					
	if(dlg.DoModal()==IDOK)
	{
		true_theta=dlg.m_truecorner;
		Maskinner=dlg.m_mask_inner;
		Maskouter=dlg.m_mask_outer;
		rect_length=dlg.m_rect_length;
		rect_centre=76;//(Maskouter-Maskinner)/2+Maskinner;
		strcpy(inputFileName,dlg.m_sar_path);
		strcpy(inputRefSarName,dlg.m_ref_path);
		strcpy(outputtxtName,dlg.m_txt_path);			
		fp=fopen(dlg.m_inputpath,"r");
		fseek( fp, 76, SEEK_SET );
		fscanf( fp, "%d", &r );
		fseek(fp,27,SEEK_CUR);
		fscanf(fp,"%d",&c);	
		fclose(fp);
		
		
		//===========================生成MASK图形================================	
		Picture maskpic1;
		maskpic1.row=500;
		maskpic1.col=500;
		maskpic1.p=fspace_2d(maskpic1.row,maskpic1.col);
		for(i=0;i<maskpic1.row;i++)
			for (j=0;j<maskpic1.col;j++)
				maskpic1.p[i][j]=255;
			int span;
			for (i=0;i<maskpic1.row;i++)
				for (j=0;j<maskpic1.col;j++)
				{
					span=(int)(pow(i-maskpic1.row/2,2)+pow(j-maskpic1.col/2,2));
					if(span<=Maskinner*Maskinner||span>Maskouter*Maskouter)
						maskpic1.p[i][j]=0;
				}								
				inputpic.p=InputImageWithName(inputFileName,inputpic.row,inputpic.col);	
				inputref.p=InputImageWithName(inputRefSarName,inputref.row,inputref.col);	
				ref=CComlib::ImgScaleCubicLinear(inputref.p ,inputref.row,inputref.col,320,320 ) ;			
				unsigned char **ttemp,**ttempmask;
				ttemp=fspace_2d(256,256);
				ttempmask=fspace_2d(256,256);
				for(int s=0;s<256;s++)
				{
					memcpy(ttemp[s],inputpic.p[s+122]+122,256);
					memcpy(ttempmask[s],maskpic1.p[s+122]+122,256);						
				}
				struct _timeb timebuffer,timebuffer1;				
				_ftime( &timebuffer );
				for(int x=0;x<20;x++)
				{	
					
					POINT temppos;			
					temppos.x=temppos.y=0;
					CMatch match;										
					NPOT ret=match.SingleMatch_Box(ref,ttemp,ttempmask,320,320,256,256,temppos);											
					POINT tempresult;
					tempresult.x=(ret.x+128)*(inputref.row/320.0)+c-(inputref.row/2);
					tempresult.y=(ret.y+128)*(inputref.row/320.0)+r-(inputref.row/2);
				}
				_ftime( &timebuffer1);
				int second=(int)(timebuffer1.time-timebuffer.time);
				char buffer[100];
				_itoa( second, buffer, 10 );
				dspace_2d(ref,320,320);
				dspace_2d(inputpic.p,inputpic.row,inputpic.col);
				dspace_2d(inputref.p,inputref.row,inputref.col);
				inputpic.p=NULL;
				::MessageBox(NULL,buffer,"Warning",MB_OK);
	}
	else
		return;		
	
	
	
}

void CMainFrame::OnTestTimeNew() 
{
	int i,j,rect_length,rect_centre;
	int Maskinner,Maskouter;
	unsigned char **TempImg;
	RadonResult res;
	int true_theta;
	POINT firstpos,endpos;
	int num=0;
	
	CMatchDlg dlg;
	unsigned char **ref;
	FILE *fp;
	int r,c;
	
	
	char inputFileName[512];
	char inputRefSarName[512];
	char outputtxtName[512];
	Picture inputpic,inputref;
	
	int result[8];					
	if(dlg.DoModal()==IDOK)
	{
		true_theta=dlg.m_truecorner;
		Maskinner=dlg.m_mask_inner;
		Maskouter=dlg.m_mask_outer;
		rect_length=dlg.m_rect_length;
		rect_centre=76;//(Maskouter-Maskinner)/2+Maskinner;
		strcpy(inputFileName,dlg.m_sar_path);
		strcpy(inputRefSarName,dlg.m_ref_path);
		strcpy(outputtxtName,dlg.m_txt_path);	
		fp=fopen(dlg.m_inputpath,"r");
		fseek( fp, 76, SEEK_SET );
		fscanf( fp, "%d", &r );
		fseek(fp,27,SEEK_CUR);
		fscanf(fp,"%d",&c);			
		fclose(fp);
	
	TempImg=fspace_2d(rect_length,rect_length);
	if(TempImg==NULL)
		return;
	//===========================生成MASK图形================================	
	Picture maskpic1;
	unsigned char **mask;	
	maskpic1.row=500;
	maskpic1.col=500;
	maskpic1.p=fspace_2d(maskpic1.row,maskpic1.col);
	POINT tempresult;
	CMatch match;										
	unsigned char **outsar;
	outsar=fspace_2d(rect_length,rect_length);
	mask=fspace_2d(rect_length,rect_length);

	for(i=0;i<maskpic1.row;i++)
		for (j=0;j<maskpic1.col;j++)
			maskpic1.p[i][j]=255;
		int span;
		for (i=0;i<maskpic1.row;i++)
			for (j=0;j<maskpic1.col;j++)
			{
				span=(int)(pow(i-maskpic1.row/2,2)+pow(j-maskpic1.col/2,2));
				if(span<=Maskinner*Maskinner||span>Maskouter*Maskouter)
					maskpic1.p[i][j]=0;
			}							
			//=======================================================================
			
				inputpic.p=InputImageWithName(inputFileName,inputpic.row,inputpic.col);	
				inputref.p=InputImageWithName(inputRefSarName,inputref.row,inputref.col);	
				ref=CComlib::ImgScaleCubicLinear(inputref.p ,inputref.row,inputref.col,320,320 ) ;
								struct _timeb timebuffer,timebuffer1;				
				_ftime( &timebuffer );
			for(int x=0;x<20;x++)
			{
				
				num=0;					
				for (int theta=0;theta<360;theta=theta+45)
				{
					j=(int)(inputpic.col/2.0-rect_centre*cos(theta*3.1416/180.0));
					i=(int)(inputpic.row/2.0-rect_centre*sin(theta*3.1416/180.0));
					{			
						for (int k=0;k<rect_length;k++)							
						{								
							memcpy(TempImg[k],inputpic.p[i+k-(int)(rect_length/2.0)]+j-(int)(rect_length/2.0),rect_length);
						} 					
						radon(TempImg,rect_length,rect_length,&res);
						if(abs(res.theta-true_theta)<=7)
						{						
							result[num]=res.avernum;
						}	
						else
						{
							result[num]=256;
						}
						num++;
					}
				}	
				int temp1=256;
				int Angle;	
				for (int t=0;t<8;t++)
				{
					if(temp1>result[t])
					{
						temp1=result[t];
						Angle=t*45;
					}
				}
				firstpos.x=(int)(inputpic.col/2.0-rect_centre*cos(Angle*3.1416/180.0));
				firstpos.y=(int)(inputpic.row/2.0-rect_centre*sin(Angle*3.1416/180.0));
				POINT temppos;
				temppos.x=firstpos.x-(rect_length/2.0);
				temppos.y=firstpos.y-(rect_length/2.0);
				for (int k=0;k<rect_length;k++)					
				{
					memcpy(outsar[k],inputpic.p[temppos.y+k]+temppos.x,rect_length);
					memcpy(mask[k],maskpic1.p[temppos.y+k]+temppos.x,rect_length);						
				} 										
				NPOT ret=match.SingleMatch_Box(ref,outsar,mask,320,320,rect_length,rect_length,temppos);									
				tempresult.x=(ret.x+(250-firstpos.x+rect_length/2.0))*(inputref.row/320.0)+c-(inputref.row/2);
				tempresult.y=(ret.y+(250-firstpos.y+rect_length/2.0))*(inputref.row/320.0)+r-(inputref.row/2);
			}
			_ftime( &timebuffer1);
			int second=timebuffer1.time-timebuffer.time;
			char buffer[100];
			_itoa( second, buffer, 10 );
			dspace_2d(ref,320,320);
			dspace_2d(outsar,rect_length,rect_length);
			dspace_2d(mask,rect_length,rect_length);				
			dspace_2d(inputpic.p,inputpic.row,inputpic.col);
			dspace_2d(inputref.p,inputref.row,inputref.col);		
			::MessageBox(NULL,buffer,"WARNING",MB_OK);						
}
}
#include "COutDlg.h"
void CMainFrame::OnOutMathc() 
{
	unsigned char **Input_Rel,**Input_Ref;
	int row_ref,col_ref,row_rel,col_rel;
	CCOutDlg dlg;
	BOOL flag;
	if(dlg.DoModal()==IDOK)
	{
		flag=dlg.m_check;
		if(dlg.m_refpath==""||dlg.m_relpath=="")
		{
			::MessageBox(NULL,"输入参数不完整","WARNING",MB_OK);
			return;
		}

		Input_Rel=InputImageWithName(dlg.m_relpath,row_rel,col_rel);
		Input_Ref=InputImageWithName(dlg.m_refpath,row_ref,col_ref);
		if(row_rel>row_ref||col_rel>col_ref)
		{
			dspace_2d(Input_Rel,row_rel,col_rel);
			dspace_2d(Input_Ref,row_ref,col_ref);
			::MessageBox(NULL,"实时图比参考图小","WARNING",MB_OK);
			return;
		}

		if(row_rel%2!=0&&col_rel%2!=0)
		{
			dspace_2d(Input_Rel,row_rel,col_rel);
			dspace_2d(Input_Ref,row_ref,col_ref);
			::MessageBox(NULL,"实时图不能被均分成四块","WARNING",MB_OK);
			return;
		}
		unsigned char **smallpic[4];
		for (int i=0;i<4;i++)
		smallpic[i]=fspace_2d(row_rel/2,col_rel/2);
		for (i=0;i<row_rel/2;i++)			
		{
			memcpy(smallpic[0][i],Input_Rel[i],col_rel/2);
			memcpy(smallpic[1][i],Input_Rel[i]+col_rel/2*1,col_rel/2);
			memcpy(smallpic[2][i],Input_Rel[i+row_rel/2*1],col_rel/2);
			memcpy(smallpic[3][i],Input_Rel[i+row_rel/2*1]+col_rel/2*1,col_rel/2);	
		}
		unsigned char **mask;
		mask=fspace_2d(row_rel/2,col_rel/2);
		for (i=0;i<row_rel/2;i++)
			for (int j=0;j<col_rel/2;j++)
				mask[i][j]=255;
		//OutputImageWithName(smallpic[0],row_rel/2,col_rel/2,"c:\\1.pic");
		//OutputImageWithName(smallpic[1],row_rel/2,col_rel/2,"c:\\2.pic");
		//OutputImageWithName(smallpic[2],row_rel/2,col_rel/2,"c:\\3.pic");
		//OutputImageWithName(smallpic[3],row_rel/2,col_rel/2,"c:\\4.pic");
		CMatch match;
		NPOT result[4];
		for (i=0;i<4;i++)
		{
			result[i]=match.SingleMatch_Box1(Input_Ref,smallpic[i],mask,row_ref,col_ref,row_rel/2,col_ref/2,flag);
		}
		for (i=0;i<4;i++)
			dspace_2d(smallpic[i],row_rel/2,col_rel/2);
		dspace_2d(mask,row_rel/2,col_rel/2);
		dspace_2d(Input_Rel,row_rel,col_rel);
		dspace_2d(Input_Ref,row_ref,col_ref);
		char buffer[500];
		if(flag==FALSE)
			wsprintf(buffer,"左上块(%d,%d)           右上块块(%d,%d)\n左下块(%d,%d)           右下块(%d,%d)",result[0].x,result[0].y
			,result[1].x,result[1].y
			,result[2].x,result[2].y
			,result[3].x,result[3].y);
		else if(flag==TRUE)
		wsprintf(buffer,"反转\n左上块(%d,%d)           右上块块(%d,%d)\n左下块(%d,%d)           右下块(%d,%d)",result[0].x,result[0].y
			,result[1].x,result[1].y
			,result[2].x,result[2].y
			,result[3].x,result[3].y);
		::MessageBox(NULL,buffer,"RESULT",MB_OK);
	}
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -