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

📄 wk.cpp

📁 曲线角点检测的二种算法
💻 CPP
字号:
/*------------------------------------------------------*\
*
*  wk.cpp
*  Corner Point Detection
*  2003-5-27pm
*  NUAA 
*  
*  
*  J.F.Ling
*  Oldbe
*  www.Oldbe.com
*  lingjf@iholley.com
*
\*------------------------------------------------------*/

#include <StdAfx.h> // can be del ::non_MFC

#include <windows.h>
#include <string.h>
#include <math.h>
#include "wk.h"



// implement cwk:
CWK::CWK(HWND hwnd_pa) 
{
	m_hwnd_pa=hwnd_pa;
	::AfxGetApp()->GetMainWnd()->SetWindowText("正态权值算法");
}
CWK::~CWK()
{
	::AfxGetApp()->GetMainWnd()->SetWindowText("");
}
void 
CWK::setparam(const char * filename ,		 
			  double _b____b,					 
			  double _u____u,					 
			  int dmin___k,						 
			  int dmax___delta,						 
              double alpa___alpa,					 		  
			  int n___ramda )
{
	strcpy(wkp.fn,filename);
	wkp._b= _b____b;
	wkp._u=_u____u;
	wkp.k=dmin___k;
	wkp.delta=dmax___delta;
    wkp.alpa=alpa___alpa;
	wkp.ramda=n___ramda;
	
}
char*
CWK::getfn()
{
	return wkp.fn; 
}
void 
CWK::startwk()
{
    wkp.totaln=rchaincode(wkp.fn);	
	gweigted_k();
	clvalue();
	gwk();
}

void CWK::gweigted_k()
{
    w.clear();
	for(int i=0 ; i< wkp.k ; i++)
	{
		w.push_back(gformula(wkp._b,wkp._u,(double)i));
	}	
}



void CWK::g10_1(vector<POT> n , vector <POT> & v)
{
	 int len = n.size();
	 POT p0={0,0};
	 v.clear();
	 for (int i =0 ;i<len ;i++) 
	 {
		 v.push_back(p0);
	 }
	 for(i=0 ; i<len ;i++)
	 {
		 v[i].x=n[(i+1)%len].x-n[i].x;
		 v[i].y=n[(i+1)%len].y-n[i].y;
	 }
}
 

void CWK::clvalue()
{
	value.clear();
	vlsv.clear();
	vwk.clear();
	int n=list_n.size();
    int i=0 ;	

	vector <POT> list_v ;

    g10_1(list_n,list_v);
    
    double beta =0 ;
	double cos_q=0 ;
	for( i=0 ; i<n ;i++)
	{
		vPOT vf={0.,0.},vb={0.,0.} ;

		for(int j=0 ; j<wkp.k ; j++)
		{
			vf.x=vf.x+list_v[(i+j)%n].x*w[j] ; 
			vf.y=vf.y+list_v[(i+j)%n].y*w[j] ; 
		}
		for(j=0 ;j<wkp.k;j++)
		{
			vb.x=vb.x-list_v[(i-j-1+n)%n].x*w[j]; 
			vb.y=vb.y-list_v[(i-j-1+n)%n].y*w[j]; 
		}
	    cos_q=(vf.x*vb.x+vf.y*vb.y)/(sqrt(vf.x*vf.x+vf.y*vf.y)*sqrt(vb.x*vb.x+vb.y*vb.y));
		beta=acos2(cos_q);
	    value.push_back(beta);
		vlsv.push_back(beta);
		vwk.push_back(vb);
		vwk.push_back(vf);
	}
}

void CWK::gwk()
{
	int i=0 , j=0 ;
	
	bl.clear();
	int len =value.size();

	
	for( i=0 ;i<len;i++)
	{   
		j=0 ;
		if(value[i]>wkp.alpa*PI/180.0)
		{
			bl.push_back(false);
			value[i]=PI ;
			goto again ;			
		}
		else
		{
			for( j=1 ;j<wkp.delta ;j++)
			{
				if(value[i]>value[(i+j)%len]||value[i]>=value[(i-j+len)%len])
				{   /*
					  important: first is ">" and late is ">=".

					  in order to keep one corner point at such 
					  situation : there are two or more maxinum value 
					              in [i-len ,i+len]
					*/
					bl.push_back(false);
					goto again ;				
				}
			}
			bl.push_back(true);
		
			for( j=1 ;j<=wkp.ramda ;j++)
			{
				value[(i+j)%len]=PI ;
				value[(i-j+len)%len]=PI ;
			}	
		}
again:;
	}
	
	for( i=len-1 ;i>=0;i--)
	{   
		j=0 ;
		if(value[i]>wkp.alpa*PI/180.0) goto again2 ;	
		else
		{
			for( j=1 ;j<wkp.delta ;j++)
			{
				if(value[i]>value[(i+j)%len]||value[i]>value[(i-j+len)%len])
				{   
					value[i]=PI ;
					goto again2 ;				
				}
			}
			bl[i]=true;
			
			for( j=1 ;j<=wkp.ramda ;j++)
			{
				value[(i+j)%len]=PI ;
				value[(i-j+len)%len]=PI ;
			}	
		}
again2:;
	}
}




bool CWK::gnxtcp(int & idx) const 
{
#define FOREVER  true
	static int isaved = bl.size()-1;
    int len=bl.size();
	for(int i=isaved  ; FOREVER ; i--)
	{
		if(i<0)
			return false ;
		else
			if(bl[i])  
				break ;
	}

	isaved=i-1 ;
	idx=i;
	return true ;
#undef FOREVER
}



void CWK::get_data(const char * logname) 
{
	ofstream oon (logname);
oon<<"J.F.Ling"<<endl;
	SYSTEMTIME st ;
	GetLocalTime(&st);
oon<<st.wYear<<"-"<<st.wMonth<<"-"<<st.wDay <<endl 
   <<st.wHour<<":"<<st.wMinute<<":"<<st.wSecond<<endl 
   <<"*******************************source data file*********************************************"
   <<endl
   <<wkp.fn
   <<endl 
   <<"length="<<wkp.totaln<<endl 
   <<"******************************end of source data file***************************************"
   <<endl<<endl;

oon<<"*****************************************weigted_k******************************************"
   <<"\n   while σ="<<wkp._b<<",μ="<<wkp._u<<",κ="<<wkp.k<<endl;
	int j ;
	double sum=0 ;
	for(j=0  ;j<wkp.k ;j++)
	{
		sum+=w[j];
	}
	for(j=0 ; j<wkp.k ;j++)
	{
		oon<<j<<".  "<<w[j]<<"     "<<100*w[j]/sum<<"% ."<<j<<endl;
	}	
oon<<"***********************************end of weigted_k*****************************************"
   <<endl<<endl ;

oon<<"*********************************value******************************************************"
   <<"\n   while κ="<<wkp.k
   <<",α=" <<wkp.alpa
   <<",δ="<<wkp.delta
   <<",λ="<<wkp.ramda
   <<endl ;
	int count =0 ;
	for(j=0  ;j<wkp.totaln;j++)	
	{
		if(bl[j])
		{
		count++;
		oon<<j<<". "
		   <<".Y.! "
		   <<"arcos.="<<vlsv[j]<<"; "
		   <<"θ="<<vlsv[j]*180.0/PI<<"; "
		   <<"org:("<<list_n[j].x<<","<<list_n[j].y<<")"
		 //  <<"("<<list_v[j].x<<","<<list_v[j].y<<"); "
		   <<endl; 	
		}
		else
		oon<<j<<". "
		   <<".N.! "
		   <<"arcos.="<<vlsv[j]<<"; "
		   <<"θ="<<vlsv[j]*180.0/PI<<"; "
		   <<"org:("<<list_n[j].x<<","<<list_n[j].y<<")"
		 //  <<"("<<list_v[j].x<<","<<list_v[j].y<<"); "
		   <<endl; 	
	}
oon<<"∑="<<count<<endl ;
oon<<"***********************************end of value*********************************************"
   <<endl <<endl ;   

}
 

⌨️ 快捷键说明

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