www.pudn.com > roadextr.rar > bline.cpp


#include	"stdafx.h" 
#include	"bline.h" 
#include	"valdef.h" 
#include	"canny.h" 
#include	"imgp2.h" 
//#include	"rdfinder.h" 
#include	"strline.h" 
#include	 
#include	 
 
/*	 
*/ 
//void	CenterPointDet_1DProfile(BYTE *pucImg,int	nRow,int nCol, 
//							  int	nMinW,int	nMaxW,int	nRoadGy,BYTE	*pucIO) 
//{ 
//	int	i,j,r,c,dg0,dg1,n0,n1,*pn1D,n,nn; 
//	float	fScore,it0,it1,max,v; 
//	BYTE	*puc1D,*pucLine; 
// 
//	pucLine = new	BYTE[nRow>nCol?nRow:nCol]; 
//	puc1D = new	BYTE[nRow>nCol?nRow:nCol]; 
//	pn1D =  new	int[nRow>nCol?nRow:nCol]; 
// 
//	for(i=0;ifabs(*(pn1D+j+1)) && 
//				fabs(*(pn1D+j))>fabs(*(pn1D+j-1)) && fabs(*(pn1D+j)) > 20) 
//				*(puc1D+j) = 0; 
//			else 
//				*(puc1D+j) = 255; 
//		} 
//		//// compute the scores of possible center point positions 
//		for(j=1;j=nCol-1) 
//					break; 
//				if(*(pn1D+j+n)<0) 
//				{ 
//					it0 = (*(pn1D+j)-*(pn1D+j+n))/150.0; 
//					it0 = it0>1?1.0:it0;	 
//					it1 = fabs(*(pn1D+j)+ *(pn1D+j+n))/100.0; 
//					it1 = it1>1?0:1.0-it1;	 
//					v = (float)(*(pucImg+i*nCol+j+n/2))/(float)nRoadGy; 
//					v = v >1?1:v; 
//					fScore = 0.5* it0 + 0.2 * it1 + 0.3 * v; 
//					if( fScore > 0.5 && *(pucImg+i*nCol+j+n/2)>nRoadGy && fScore>max) 
//					{	 
//					//	*(pucIO+i*nCol+j+n/2) = 0; 
//						nn = i*nCol+j+n/2; 
//						max = fScore; 
//					} 
//				} 
//			} 
//			if(max>0.5) 
//				*(pucIO+nn) = 0; 
//			 
//		} 
//	} 
//	////// procesing cols 
//	for(j=0;jfabs(*(pn1D+i+1)) && 
//				fabs(*(pn1D+i))>fabs(*(pn1D+i-1)) && fabs(*(pn1D+i)) > 20) 
//				*(puc1D+i) = 0; 
//			else 
//				*(puc1D+i) = 255; 
//		} 
//		//// compute the scores of possible center point positions 
//		for(i=1;i=nRow-1) 
//					break; 
//				if(*(pn1D+i+n)<0) 
//				{ 
//					it0 = (*(pn1D+i) - *(pn1D+i+n))/150.0; 
//					it0 = it0>1?1.0:it0;	 
//					it1 = fabs(*(pn1D+i)+ *(pn1D+i+n))/100.0; 
//					it1 = it1>1?0:1.0-it1;	 
//					v = (float)(*(pucImg+(i+n/2)*nCol+j))/(float)nRoadGy; 
//					fScore = 0.5* it0 + 0.2 * it1 + 0.3 * v; 
//					if( fScore > 0.5 && *(pucImg+(i+n/2)*nCol+j)>nRoadGy && fScore > max) 
//					{ 
//					//	*(pucIO+(i+n/2)*nCol+j) = 0; 
//						nn = (i+n/2)*nCol+j; 
//						max = fScore; 
//					} 
//				} 
//			} 
//			if(max>0.5) 
//				*(pucIO+nn) = 0; 
//			 
//		} 
//	} 
//	delete	pucLine; 
//	delete	puc1D; 
//	delete	pn1D; 
//} 
// 
///* 
// 
//*/ 
//void	CoorealationBlackLine(unsigned char *pucImg,int	nRow,int nCol, 
//							  int	nTW,unsigned char ucBGy,BYTE	*pucIO) 
//{ 
//	int		r,c,cc,nN0,nDV,nWW,w,nPos,nRR,kk,i; 
//	double	*pdfP; 
//	unsigned char	*pucI,*pucIBlk; 
//	unsigned long	plSumBlk[3],plSumBlk2[3],plSumTempBlk[3]; 
//	float	fEf; 
//	 
//	pucI = new	BYTE[nRow*nCol]; 
//	pucIBlk = new	BYTE[(nRow>nCol)?nRow:nCol]; 
//	pdfP=new	double[(nRow>nCol)?nRow:nCol]; 
//	if(pucI==NULL ||pucIBlk==NULL) 
//		return; 
// 
//	for(r=0;r=0.6 ) 
//				{ 
//					*(pucI+r*nCol+cc+nN0)=0; 
//				//	cc+=w; 
//				} 
//			} 
//			 
//		 
//		} 
//	} 
//	////// colum matching 
//	for(c=0;c= 0.6) 
//					{ 
//						*(pucI+(cc+nN0)*nCol+c) = 0; 
//				//		cc+=w; 
//					} 
//			} 
//		} 
//	} 
//	 
//	for(r=0;r=nRow-1||cc<1||cc>=nCol-1) 
//					break; 
//				 
//				pucN8[7]=*(pucImg+(rr-1)*nCol+cc+1);	pucN8[6]=*(pucImg+(rr-1)*nCol+cc); 
//				pucN8[5]=*(pucImg+(rr-1)*nCol+cc-1);	pucN8[4]=*(pucImg+rr*nCol+cc-1); 
//				pucN8[3]=*(pucImg+(rr+1)*nCol+cc-1);	pucN8[2]=*(pucImg+(rr+1)*nCol+cc); 
//				pucN8[1]=*(pucImg+(rr+1)*nCol+cc+1);	pucN8[0]=*(pucImg+rr*nCol+cc+1); 
// 
//				ppntNPix[7].nX=cc+1;	ppntNPix[7].nY=rr-1;	ppntNPix[6].nX=cc;		ppntNPix[6].nY=rr-1; 
//				ppntNPix[5].nX=cc-1;	ppntNPix[5].nY=rr-1;	ppntNPix[4].nX=cc-1;	ppntNPix[4].nY=rr; 
//				ppntNPix[3].nX=cc-1;	ppntNPix[3].nY=rr+1;	ppntNPix[2].nX=cc;		ppntNPix[2].nY=rr+1; 
//				ppntNPix[1].nX=cc+1;	ppntNPix[1].nY=rr+1;	ppntNPix[0].nX=cc+1;	ppntNPix[0].nY=rr; 
//				nEnd2Fg=0; 
//				nFg2=0; 
//				for(k=0;k<8;k++) 
//				{	/*if(lsSeg.nPtC>1) 
//					for(kk=2;kk1&&(ppntNPix[k].nX)==lsSeg.pnptPxy[lsSeg.nPtC-2].nX 
//						&&(ppntNPix[k].nY)==lsSeg.pnptPxy[lsSeg.nPtC-2].nY) 
//						 
//						/*	nEnd2Fg=1; 
//					} 
//					if(nEnd2Fg==1)*/ 
//						continue; 
//					if(pucN8[k]==0) 
//					{	nFg2=1; 
//						lsSeg.pnptPxy[n].nX=ppntNPix[k].nX; 
//						lsSeg.pnptPxy[n].nY=ppntNPix[k].nY; 
//						n++; 
//						lsSeg.nPtC=n; 
//					} 
//					if(nFg2==1) 
//						break; 
//				} 
//				if(lsSeg.nPtC>nST) 
//					break; 
//				if(lsSeg.nPtC<=nST) 
//				{	if(nFg2==0/*&&lsSeg.nPtC<=nST*/) 
//					{	for(m=0;mnRow-1||cc<0||cc>nCol-1) 
//					break; 
//				if(rr>0&&rr0&&cc1) 
//						{	for(kk=0;kk=nST*2) 
//					{	nSegPtC=(lsSeg.nPtC%nST==0)? 
//									(lsSeg.nPtC/nST)+1:(lsSeg.nPtC/nST)+1; 
//						//if(lsSeg.nPtC%nST!=0) 
//						//	lsSeg.nPtC=(lsSeg.nPtC-lsSeg.nPtC%nST); 
//						pobjTotalObj[nLineSegC].nObjType = 1; 
//						pobjTotalObj[nLineSegC].nExtrState = AUTO_EDGE; 
//						pobjTotalObj[nLineSegC].nObjSetNum =nLineSegC; 
//						pobjTotalObj[nLineSegC].nObjPtCount = nSegPtC; 
//						pobjTotalObj[nLineSegC].pnptObjPtCen = (dfPOINT *)malloc(nSegPtC*sizeof(dfPOINT)); 
//						if(!(pobjTotalObj[nLineSegC].pnptObjPtCen)) 
//							return	nLineSegC; 
//						 
//						pp=0; 
//						 
//						for(tt=0;tt=lsSeg.nPtC) 
//						//	{	pobjTotalObj[nLineSegC].pnptObjPtCen[tt].nX = lsSeg.pnptPxy[lsSeg.nPtC-1].nX; 
//						//		pobjTotalObj[nLineSegC].pnptObjPtCen[tt].nY = lsSeg.pnptPxy[lsSeg.nPtC-1].nY; 
//						//	} 
//						//	else 
//							if(pp>=lsSeg.nPtC) 
//								pp=lsSeg.nPtC-1; 
// 
//							{	pobjTotalObj[nLineSegC].pnptObjPtCen[tt].dfX = lsSeg.pnptPxy[pp].nX; 
//								pobjTotalObj[nLineSegC].pnptObjPtCen[tt].dfY = lsSeg.pnptPxy[pp].nY; 
//							} 
//							pp+=nST; 
//						}//// erase the traced line 
//						for(tt=0;tt=nRow||c<0||c>=nCol) 
//						continue; 
//					pucPfl[m*nTempW+n] = *(pucImg+r*nCol+c); 
//				} 
//			} 
//			///// find gradient in the profile 
//			for(m=1;mmaxp) 
//				{ 
//					maxp = pp; 
//					nUp = m; 
//				} 
//			} 
//			if(maxp>10) 
//				y_u=(double)nUp-(nSrchR/2.0) ; 
//			else 
//				y_u = nRdW/2.0; 
//			 
//			maxg = 0;	maxp = -10000000000; 
//			for(m=nSrchR/2-nMaxRW/2;m<=nSrchR/2-nMinRW/2;m++) 
//			{	//// find below edge by computing the 1D grident 
//				pp = pnPrf[m];//Coorelation(pucPfl+(m-nTempH/2)*nTempW,pucTemplate,nTempH*nTempW); 
//				if(pp>maxp) 
//				{ 
//					maxp = pp; 
//					nDwn = m; 
//				} 
//			} 
//			if(maxp>10) 
//				y_d = (double)nDwn - (nSrchR/2.0); 
//			else 
//				y_d = -nRdW/2.0; 
//			///// position the dual edge points and the center point 
//			y_d+=0.5; 
//			y_u+=0.5; 
//			g_ = 0; 
//			for(m=nDwn;m=0.37) 
//		{	pobjTotalObj[nCentLinsN+nC].nObjPtCount = nPtC; 
//			pobjTotalObj[nCentLinsN+nC].pnptObjPtCen = new dfPOINT[nPtC]; 
//			pobjTotalObj[nCentLinsN+nC].nExtrState = AUTO_CENTLINE; 
//			for(j=0;j0) 
//		{	 
//			dx = pptCent[m].dfX - pptCent[m-1].dfX; 
//			dy = pptCent[m].dfY - pptCent[m-1].dfY; 
//			dis = sqrt( dx*dx + dy*dy ); 
//			sum_l+=dis; 
//		} 
//	} 
//	rw_ = sum_w/nPtC; 
//	av_grd = av_grd/nPtC; 
//	av_g = sum_g/nPtC; 
//	////compute dlt of width,gray,and gradient 
//	dlt_w = 0;	dlt_g =0; 
//	for(m=0;m1?1.0:av_grd/64.0; /// property of contrast 
//	G_len = sum_l/l_fac>1?1:sum_l/l_fac; /// property of length 
//	dx = pptCent[0].dfX - pptCent[nPtC-1].dfX; 
//	dy = pptCent[0].dfY - pptCent[nPtC-1].dfY; 
//	len = sqrt( dx*dx + dy*dy );  
//	G_str = len/sum_l; /////property of straigthen 
//	G_w_conts = 1.0 - dlt_w/5.0;/////property of width consistency 
//	if(G_w_conts<=0||(sum_l<30&&G_str<0.95))///  
//		return	0.0; 
//	ret = 0.25 * G_w_conts + 0.05 * R_contr + 0.15 *  R_ints + 
//			0.25 * R_int_cont + 0.2 * G_len + 0.1 * G_str; 
//	 
//	return	ret; 
//} 
/*			*/ 
void	SimpleThin(unsigned char *pucImg,int	nRow,int nCol)	 
{	int	ix,iy,gx,gy,gray,pul,k,n[10]; 
	unsigned char	*pucI = (unsigned char	*)malloc(nRow*nCol*sizeof(unsigned char));	 
 
	for(iy=0;iy=1*dwRoadWidth&&i<2*dwRoadWidth)//1  2 
//			{	slr +=  *pucImgBlkData; 
//			} 
//			pucImgBlkData++; 
//		} 
//	} 
//	pucImgBlkData=pucP; 
//	if(wFristFg!=0) 
//	{	sl=*pdwSum+ *(pucImgBlkData+dwDataSize-1); 
//		sl2=*pdwSum2+(DWORD) (*(pucImgBlkData+dwDataSize-1)) * 
//			 *(pucImgBlkData+dwDataSize-1); 
//		slr=*pdwLRSum+ *(pucImgBlkData+2*dwRoadWidth-1);///2* 
//	} 
//	*pdwSum=sl- *pucImgBlkData; 
//	*pdwSum2=sl2-(DWORD)(*pucImgBlkData)*(*pucImgBlkData); 
//	*pdwLRSum=slr-*(pucImgBlkData+1*dwRoadWidth);///1* 
//	sr2=sr=dwRoadWidth;///1* 
//	p=slr-(double)sl*sr/dwDataSize; 
//	bb=(sl2-(double)sl*sl/dwDataSize)*(sr2-(double)sr*sr/dwDataSize); 
////	if(bb<=0) 
////		return(0.0); 
//	bb=sqrt(bb); 
//	p/=bb; 
////	p=0.0-p; 
////	slr/=(dwRoadWidth); 
////	vv= sl-slr; 
////	vv/=(2*dwRoadWidth); 
////	contrast = fabs(slr-vv)/255.; 
////	contrast = (contrast>=0.5)?1.0:(1-(contrast-0.5)*(contrast-0.5)); 
////	p*=contrast;////加入对比度约束 
// 
//	return(p); 
//} 
// 
///*	coorelation of black line	*/ 
//double	Corelation0_1Fast2(BYTE *pucImgBlkData, 
//						DWORD dwRoadWidth, 
//						DWORD dwDataSize, 
//						WORD wFristFg, 
//						DWORD *pdwSum, 
//						DWORD *pdwSum2, 
//						DWORD *pdwLRSum) 
//{	int 		i; 
//	DWORD 		sl,sr,sl2,sr2,slr; 
//	double 		bb,p,vv,contrast; 
//	BYTE		*pucP; 
//	int			nNoRdW; 
// 
//	nNoRdW  = 3; 
//	sl=sr=0L; 
//	sl2=sr2=slr=0L; 
//	pucP=pucImgBlkData; 
//	if(wFristFg==0) 
//	{	for(i=0;i<(int)dwDataSize;i++) 
//		{	sl  += *pucImgBlkData; 
//			sl2 += (DWORD) *pucImgBlkData * *pucImgBlkData; 
//			if(i>=nNoRdW&&i=0.5)?1.0:(1-(contrast-0.5)*(contrast-0.5)); 
////	p*=contrast; 
//	////加入对比度约束/////////////////////// 
// 
//	if(p<0)	p=0.0; 
// 
//	return(p); 
//} 
// 
//double	Corelation0_1FastEdge(BYTE *pucImgBlkData, 
//		  DWORD dwDataSize, 
//		  WORD wFristFg, 
//		  DWORD *pdwSum, 
//		  DWORD *pdwSum2, 
//		  DWORD *pdwLRSum) 
// 
//{ 
//	register int 	i; 
//	DWORD 		sl,sr,sl2,sr2,slr; 
//	double 		bb,p; 
//	BYTE		*pucP; 
// 
//	sl=sr=0L;	sl2=sr2=slr=0L; 
//	pucP=pucImgBlkData; 
//	if(wFristFg==0) 
//	{	for(i=0;i<(int)dwDataSize;i++) 
//		{	sl  += *pucImgBlkData; 
//			sl2 += (DWORD) *pucImgBlkData * *pucImgBlkData; 
//			if(i>=(int)(dwDataSize/2)) 
//			{	slr+=*pucImgBlkData; 
//			} 
//			pucImgBlkData++; 
//		} 
//	} 
//	pucImgBlkData=pucP; 
//	if(wFristFg!=0) 
//	{	sl=*pdwSum+ *(pucImgBlkData+dwDataSize-1); 
//		sl2=*pdwSum2+(DWORD) (*(pucImgBlkData+dwDataSize-1)) * 
//			 *(pucImgBlkData+dwDataSize-1); 
//		slr=(*pdwLRSum+ *(pucImgBlkData+dwDataSize-1)); 
//	} 
//	*pdwSum=sl- *pucImgBlkData; 
//	*pdwSum2=sl2-(DWORD)(*pucImgBlkData)*(*pucImgBlkData); 
//	*pdwLRSum=(slr- *(pucImgBlkData+(DWORD)(dwDataSize/2))); 
//	sr2=sr=(DWORD)(dwDataSize/2); 
//	p=slr-(double)sl*sr/dwDataSize; 
//	bb=(sl2-(double)sl*sl/dwDataSize)*(sr2-(double)sr*sr/dwDataSize); 
//	if(bb<=0) return(0); 
//	bb=sqrt(bb); 
//	p/=bb; 
//	return(p); 
//} 
// 
////////// find dominant gradient pixel 
//int	FinfDominGridentDirPixs(BYTE *pucImg,int	nRow,int nCol) 
//{	 
//	float	pfDirsLists[180],t,maxt_u,maxt; 
//	int		i,r,c,dx,dy,maxI; 
//	for(i=0;i<180;i++) 
//		pfDirsLists[0] = 0.0; 
// 
//	for(r=1;rmaxt_u) 
//		{	maxt_u = pfDirsLists[i]; 
//			maxI = i; 
//		} 
//	} 
//	maxt = maxI * 2.0; 
//	TRACE("maxT = %d\n",(int)maxt); 
//	for(r=1;r=nRow-3||j<=2||j>=nCol-3) 
//				*(pucEdges + i) = 255; 
//		} 
//	} 
//	//// thining 
//	HilditchThin(pucEdges,nRow,nCol); 
//	SimpleThin(pucEdges,nRow,nCol); 
// 
//	LineSeg	plsMaxLine[1]; 
//	plsMaxLine->pnptPxy = new	nPOINT[10000]; 
//	/////  
//	nRmvLen = nLenMax; 
//	double	*pdfX,*pdfY,th; 
//	int	nEdgeTyp,pnWUp[200],pnWDwn[200],maxN,maxWUp,maxWDwn; 
//	pdfX = new	double[10000]; 
//	pdfY = new	double[10000]; 
//	nC_Str = 0; 
//	for(;;) 
//	{ 
//		for(i=0;inPtCnPtC;i++) 
//		{ 
//			*(pdfX+i) = plsMaxLine->pnptPxy[i].nX; 
//			*(pdfY+i) = plsMaxLine->pnptPxy[i].nY; 
//		} 
// 
//		nC = CmprsLine02(pdfX,pdfY,plsMaxLine->nPtC,1.17); 
//		 
//		//// evaluate each segment and output candidates 
//		for(n=0;n<200;n++) 
//		{ 
//			pnWUp[n] = pnWDwn[n] = 0; 
//		} 
//		for(i=0;inPtC;i++) 
//		{	 
//			for(w=nMinRW;w<=nMaxRW;w++) 
//			{ 
//				th = RetPtNormalDir(plsMaxLine->pnptPxy,i,plsMaxLine->nPtC); 
//				if(JudgeAntiEdgePt(pucImg,nRow,nCol,th,w, 
//					(plsMaxLine->pnptPxy+i)->nX,(plsMaxLine->pnptPxy+i)->nY,true,pucEdges)) 
//				{ 
//					pnWUp[w]++; 
//				} 
//				if(JudgeAntiEdgePt(pucImg,nRow,nCol,th,w, 
//					(plsMaxLine->pnptPxy+i)->nX,(plsMaxLine->pnptPxy+i)->nY,false,pucEdges)) 
//				{ 
//					pnWDwn[w]++; 
//				} 
//			} 
//		} 
//		/////////// find peak values	maxWDwn 
//		for(i=0;i<200;i++) 
//		{ 
//			if(i==0||maxN < pnWUp[i]) 
//			{ 
//				maxN = pnWUp[i]; 
//				maxWUp = i; 
//			} 
//		} 
//		for(i=0;i<200;i++) 
//		{ 
//			if(i==0||maxN < pnWDwn[i]) 
//			{ 
//				maxN = pnWDwn[i]; 
//				maxWDwn = i; 
//			} 
//		} 
//		if(maxNnPtC/5) 
//		{ 
//			RemoveOneLine(pucEdges,nRow,nCol,plsMaxLine); 
//			continue; 
//		} 
//		if(maxWUp>maxWDwn) 
//		{ 
//			OutCentreSeg(pobjSegs,nC_Str,maxWUp,pdfX,pdfY,nC,true); 
//		} 
//		else 
//			OutCentreSeg(pobjSegs,nC_Str,maxWDwn,pdfX,pdfY,nC,false); 
//		nC_Str++; 
//		RemoveOneLine(pucEdges,nRow,nCol,plsMaxLine); 
////		break; 
//	} 
///* 
//	for(n=0;n<30;n++) 
//		TRACE("%d ",pnWUp[n]); 
//	TRACE("\n"); 
//	for(n=0;n<30;n++) 
//		TRACE("%d ",pnWDwn[n]); 
//*/	 
//	delete	pucEdges; 
//	delete	pucLines; 
//	delete	pdfX; 
//	delete	pdfY; 
//	delete	plsMaxLine->pnptPxy; 
////	delete	pucIDir; 
////	delete	pucIGd; 
//	 
//	return	nC_Str; 
//} 
// 
//void	SumpnW(int	*pnW,int	C) 
//{ 
//	int	i; 
//	int	*pnWW; 
//	 
//	pnWW = new	int[C]; 
//	for(i=0;inObjType = 1; 
//	(pobjSegs+nC_Str)->pnptObjPtCen = (dfPOINT *)malloc(nC*sizeof(dfPOINT)); 
//	(pobjSegs+nC_Str)->nObjPtCount = nC; 
//	(pobjSegs+nC_Str)->nExtrState = AUTO_EDGE; 
// 
//	for(i=0;ipnptObjPtCen[i].dfX = x1;	 
//		(pobjSegs+nC_Str)->pnptObjPtCen[i].dfY = y1; 
// 
//		pdfX++;	pdfY++; 
//	} 
//	x0 = *pdfX;	y0 = *pdfY; 
//	(pobjSegs+nC_Str)->pnptObjPtCen[nC-1].dfX = bIsUP? x0 - (float)W*sina/2.0 : x0 + (float)W*sina/2.0;	 
//	(pobjSegs+nC_Str)->pnptObjPtCen[nC-1].dfY = bIsUP? y0 + (float)W*cosa/2.0 : y0 - (float)W*cosa/2.0; 
// 
//} 
// 
// 
//void	OutPutSegFrmWidth(mmOBJECT	*pobjSegs,int	nC_Str,int	W,double	*pdfX,double	*pdfY,bool	bIsUP) 
//{ 
//	double	x0,y0,sina,cosa,dis,x1,y1,x2,y2; 
// 
//	x0 = *pdfX;	y0 = *pdfY; 
//	dis = sqrt((*pdfX-*(pdfX+1)) * (*pdfX-*(pdfX+1)) +  
//		(*pdfY - *(pdfY + 1)) * (*pdfY - *(pdfY + 1))); 
//	 
//	sina = (*(pdfY + 1) - *pdfY)/dis; 
//	cosa = (*(pdfX + 1) - *pdfX)/dis; 
//	 
//	if(bIsUP) 
//	{ 
//		x1 = x0 - (float)W*sina/2.0;				y1 = y0 + (float)W*cosa/2.0; 
//		x2 = x0 + dis*cosa - (float)W*sina/2.0;		y2 = y0 + dis*sina + (float)W*cosa/2.0; 
//	} 
//	else 
//	{ 
//		x1 = x0 + (float)W*sina/2.0;				y1 = y0 - (float)W*cosa/2.0; 
//		x2 = x0 + dis*cosa + (float)W*sina/2.0;		y2 = y0 + dis*sina - (float)W*cosa/2.0; 
//	} 
//	(pobjSegs+nC_Str)->nObjType = 1; 
//	(pobjSegs+nC_Str)->pnptObjPtCen = (dfPOINT *)malloc(2*sizeof(dfPOINT)); 
//	(pobjSegs+nC_Str)->nObjPtCount = 2; 
//	(pobjSegs+nC_Str)->pnptObjPtCen[0].dfX = x1;	 
//	(pobjSegs+nC_Str)->pnptObjPtCen[0].dfY = y1; 
//	(pobjSegs+nC_Str)->pnptObjPtCen[1].dfX = x2; 
//	(pobjSegs+nC_Str)->pnptObjPtCen[1].dfY = y2; 
//	(pobjSegs+nC_Str)->nExtrState = AUTO_EDGE; 
// 
//} 
//int	FindStrLineEdgeDir(double	*pdfX,double	*pdfY,BYTE	*pucImg, 
//					   int	nRow,int	nCol) 
//{ 
//	int	r0,c0,r1,c1,gy,gu,gd; 
//	double	x0,y0,sina,cosa,dis,x,y; 
// 
//	x0 = *pdfX;	y0 = *pdfY; 
//	dis = sqrt((*pdfX-*(pdfX+1)) * (*pdfX-*(pdfX+1)) +  
//		(*pdfY - *(pdfY + 1)) * (*pdfY - *(pdfY + 1))); 
//	 
//	sina = (*(pdfY + 1) - *pdfY)/dis; 
//	cosa = (*(pdfX + 1) - *pdfX)/dis; 
// 
//	c0 = (int)(x0 - (float)(1)*sina);	r0 = (int)(y0 + (float)(1)*cosa); 
//	c1 = (int)(x0 - (float)(-1)*sina);	r1 = (int)(y0 + (float)(-1)*cosa); 
//	gu = (int)(*(pucImg+r0*nCol+c0)); 
//	gd = (int)(*(pucImg+r1*nCol+c1)); 
//	gy = gu - gd; 
//	if(gy<0) 
//		return	0; 
//	else if(gy>=0) 
//		return	1; 
//} 
///* 
//*/ 
//void	FindAntiEdge(BYTE	*pucImg,BYTE	*pucI,int	nRow,int	nCol,int	*pnWUp,int	*pnWDwn, 
//					 double	*pdfX,double	*pdfY,int	nMinW,int	nMaxW,int	nEdgeTyp) 
//{ 
//	int	i,w,r,c,gy,r1,c1,r0,c0,gu,gd; 
//	double	x0,y0,sina,cosa,dis,x,y; 
// 
//	x0 = *pdfX;	y0 = *pdfY; 
//	dis = sqrt((*pdfX-*(pdfX+1)) * (*pdfX-*(pdfX+1)) +  
//		(*pdfY - *(pdfY + 1)) * (*pdfY - *(pdfY + 1))); 
//	 
//	sina = (*(pdfY + 1) - *pdfY)/dis; 
//	cosa = (*(pdfX + 1) - *pdfX)/dis; 
//	 
//	for(i=0;i<(int)dis;i++) 
//	{ 
//		for(w=nMinW;w<=nMaxW;w++) 
//		{ 
//			//// process upper  
//			x = x0 + (float)i*cosa - (float)w*sina;			y = y0 + (float)i*sina + (float)w*cosa; 
//			c0 = (int)(x0 + (float)i*cosa - (float)(w+1)*sina);	r0 = (int)(y0 + (float)i*sina + (float)(w+1)*cosa); 
//			c1 = (int)(x0 + (float)i*cosa - (float)(w-1)*sina);	r1 = (int)(y0 + (float)i*sina + (float)(w-1)*cosa); 
//			r = (int)y;	c = (int)x; 
//			if(IsBorder(r,c,nRow,nCol)||IsBorder(r1,c1,nRow,nCol)||IsBorder(r0,c0,nRow,nCol)) 
//				continue; 
//			gu = (int)(*(pucImg+r0*nCol+c0)); 
//			gd = (int)(*(pucImg+r1*nCol+c1)); 
//			gy = gu - gd; 
//						 
//			if(*(pucI+r*nCol+c)==255) 
//				continue; 
//			if((nEdgeTyp==0 && gy>0)||nEdgeTyp==1 && gy<0) 
//				*(pnWUp + w) = *(pnWUp + w)+1; 
//			 
//			/// process down 
//			x = x0 + (float)i*cosa - (float)(-w)*sina;			y = y0 + (float)i*sina + (float)(-w)*cosa; 
//			c0 = (int)(x0 + (float)i*cosa - (float)(-w+1)*sina);	r0 = (int)(y0 + (float)i*sina + (float)(-w+1)*cosa); 
//			c1 = (int)(x0 + (float)i*cosa - (float)(-w-1)*sina);	r1 = (int)(y0 + (float)i*sina + (float)(-w-1)*cosa); 
//			r = (int)y;	c = (int)x; 
//			if(IsBorder(r,c,nRow,nCol)||IsBorder(r1,c1,nRow,nCol)||IsBorder(r0,c0,nRow,nCol)) 
//				continue; 
//			gu = (int)(*(pucImg+r0*nCol+c0)); 
//			gd = (int)(*(pucImg+r1*nCol+c1)); 
//			gy = gu - gd; 
//			 
//			if(*(pucI+r*nCol+c)==255) 
//				continue; 
//			if((nEdgeTyp==0 && gy>0)||nEdgeTyp==1 && gy<0) 
//				*(pnWDwn + w) = *(pnWDwn + w)+1; 
//		} 
//	} 
//		 
//} 
// 
///* 
//*/ 
//void	DetCintPts(BYTE	*pucImg,int	nRow,int	nCol,int	nMaxRW,int	nMinRW) 
//{ 
//	BYTE	*pucIDir,*pucIGd; 
//	int	i,r,c,m,n,aT,rr,cc,r0,c0; 
//	double	dt,th,anti_t; 
//	 
//	pucIDir = new	BYTE[nRow*nCol]; 
//	pucIGd = new	BYTE[nRow*nCol]; 
//	 
//	GetGrientDirImg(pucImg,nRow,nCol,pucIDir,pucIGd); 
//	dt = 360.0/255.0; 
//	for(i=0;i<255;i++) 
//	{ 
//		if(i<=127) 
//			anti_t = (i+127); 
//		else 
//			anti_t = (i-127); 
//		aT = (int)anti_t; 
//		th = i*dt; 
//		for(r=0;r=nRow-1||cc<=1||cc>=nCol-1) 
//							continue; 
//						if( *(pucIDir+rr*nCol+cc)>=aT-20 && *(pucIDir+rr*nCol+cc)<=aT+20 &&  
//							*(pucIDir+rr*nCol+cc)!=255) 
//						{ 
//							r0 = (int)(r + (double)m*sin(PI*th/180.0)/2.0); 
//							c0 = (int)(c + (double)m*cos(PI*th/180.0)/2.0); 
//							if(r0>=1 && r0 < nRow-1 && c0>=1 && c0 <= nCol-1) 
//								*(pucImg+r0*nCol+c0) = 0; 
//						} 
//						//// negtive direction 
//						rr = (int)(r - (double)m*sin(PI*th/180.0)); 
//						cc = (int)(c - (double)m*cos(PI*th/180.0)); 
//						if(rr<=1||rr>=nRow-1||cc<=1||cc>=nCol-1) 
//							continue; 
//						if( *(pucIDir+rr*nCol+cc)>=aT-10 && *(pucIDir+rr*nCol+cc)<=aT+10 &&  
//							*(pucIDir+rr*nCol+cc)!=255) 
//						{ 
//							r0 = (int)(r - (double)m*sin(PI*th/180.0)/2.0); 
//							c0 = (int)(c - (double)m*cos(PI*th/180.0)/2.0); 
//							if(r0 >= 1 && r0 <= nRow-1 && c0 >= 1 && c0 <= nCol-1) 
//								*(pucImg+r0*nCol+c0) = 0; 
//						} 
//					} 
//				} 
//			} 
//		} 
//	} 
//	delete	pucIDir; 
//	delete	pucIGd; 
//} 
// 
//bool	JudgeAntiEdgePt(BYTE	*pucImg,int	nRow,int	nCol,double	th,int	w, /// th is the angle point to right 
//						int	nX,int	nY,bool	bIsRight,BYTE	*pucEdge) /// if it is true, in the positive axis 
//{	 
//	int	r0,c0,r1,c1,d0,dd,x0,y0,x1,y1,r,c; 
//	 
//	r0 = (int)((double)nY - (double)1.0*sin(th));	c0 = (int)((double)nX - (double)1.0*cos(th)); 
//	r1 = (int)((double)nY + (double)1.0*sin(th));	c1 = (int)((double)nX + (double)1.0*cos(th)); 
// 
//	d0 = (int)(*(pucImg+r1*nCol+c1)) - (int)(*(pucImg+r0*nCol+c0)); 
//		 
//	if(bIsRight) 
//	{ 
//		y0 = (int)(nY + (double)(w-1)*sin(th));		x0 = (int)(nX + (double)(w-1)*cos(th)); 
//		y1 = (int)(nY + (double)(w+1)*sin(th));		x1 = (int)(nX + (double)(w+1)*cos(th)); 
//		r = (int)(nY + (double)(w)*sin(th));		c = (int)(nX + (double)(w)*cos(th)); 
//		if(IsBorder(r,c,nRow,nCol)||IsBorder(y1,x1,nRow,nCol)||IsBorder(y0,x0,nRow,nCol)) 
//			return	false; 
//		if(*(pucEdge+r*nCol+c)!=0) 
//			return	false; 
//		 
//	} 
//	else 
//	{ 
//		y0 = (int)(nY + (double)(-w-1)*sin(th));		x0 = (int)(nX + (double)(-w-1)*cos(th)); 
//		y1 = (int)(nY + (double)(-w+1)*sin(th));		x1 = (int)(nX + (double)(-w+1)*cos(th)); 
//		r = (int)(nY - (double)(w)*sin(th));			c = (int)(nX - (double)(w)*cos(th)); 
//		if(IsBorder(r,c,nRow,nCol)||IsBorder(y1,x1,nRow,nCol)||IsBorder(y0,x0,nRow,nCol)) 
//			return	false; 
//		if(*(pucEdge+r*nCol+c)!=0) 
//			return	false; 
////		*(pucImg+r*nCol+c) = 128; 
//	} 
//	dd =  (int)(*(pucImg + y1*nCol + x1)) - (int)(*(pucImg + y0*nCol + x0)); 
//	if(dd*d0<0) 
//		return	true; 
//	else 
//		return	false; 
//} 
// 
//double	RetPtNormalDir(nPOINT	*pnptPts,int	n,int	nC) 
//{ 
//	double	x0,y0,x1,y1,t,dx,dy; 
//	int	n0,n1; 
// 
//	if(n==0) 
//	{	n0 = 0; 
//		n1 = 2; 
//	} 
//	else if(n==nC-1) 
//	{ 
//		n0 = n-2; 
//		n1 = n; 
//	} 
//	else  
//	{ 
//		n0 = n-1; 
//		n1 = n+1; 
//	} 
// 
//	dx = (pnptPts+n1)->nX - (pnptPts+n0)->nX; 
//	dy = (pnptPts+n1)->nY - (pnptPts+n0)->nY; 
//	 
//	t = atan2(dy,dx); /// t is (-PI,PI) 
//	t = t<0 ? t+2.0*PI : t;	 
//	return	t-PI/2; 
//} 
// 
///* 
//*/ 
//int	DetLinesByWinHoughT(BYTE	*pucImg,int	nRow,int	nCol,int	nWinW,mmOBJECT	*pobjSegs) 
//{ 
//	int	i,j,m,n,r,c,x0,y0,grd,nT,jj,rr,cc,nRetC,N; 
//	BYTE	*pucGrd,*pucDir; 
//	float	pfH[180],thDir,t,v,t_1,t_2,maxv,x,y,th,d,u; 
//	char	*pcPts; 
// 
//	pucGrd = new	BYTE[nRow*nCol]; 
//	pucDir = new	BYTE[nRow*nCol]; 
//	pcPts = new	char[nRow*nCol]; 
//	 
//	GetGrientDirImg(pucImg,nRow,nCol,pucDir,pucGrd); 
//	 
//	for(i=0;i0 /* && (fabs(th - t_1)<30 || fabs(th - t_2)<30 )  */)  
//					{	 
//					//	d = sqrt(m*m+n*n); 
//						if(m==0)	t=0; 
//						if(n==0)	t = PI/2; 
//						else 
//							t = atan((double)m/(float)n); /// atan((double)m/(float)n) 
//						t = t<0? t + PI : t; ////  (0,PI) 
//						t = t*180.0/PI; 
//						nT = (int)(t/3); 
//					//	u = grd/50.0 >1.0 ? 1.0 : grd/50.0; 
//						pfH[nT] = pfH[nT] + 1; 
//					} 
//					//// find normal dirction of the straight edge .........					 
//				} 
//			} 
//			//// find a peak value 
//			for(j=0;j<60;j++) 
//			{	if(j==0||maxv nWinW/3 && (fabs(th - t_1)<30 || fabs(th - t_2)<30 ) ) /// 		&& fabs(t-PI/2)>0.01 
//			{	 
//				*(pucImg + y0 * nCol + x0) = 255 ; //// set white to the image 
//				*(pcPts + y0 * nCol + x0) = jj; //// the angle of the line is (0, 180), the interval is 3  
//				N++; 
//				for(m=-nWinW/2;m<=nWinW/2;m++) ///  
//				{	 
//			/*		if(fabs(t-PI/2)<0.02) 
//					{ 
//						*(pucGrd + (m+y0) * nCol + x0) = 0; 
//						*(pucImg + (m+y0) * nCol + x0) = 255; 
//					} 
//					else 
//			*/		{	x = (double)m*cos(t); 
//						y = (double)m*sin(t); 
//						if(y>=-nWinW/2 && y <=nWinW/2 && x>=-nWinW/2 && x <=nWinW/2) 
//						{ 
//							rr = y0 + (int)y; 
//							cc = x0 + (int)x; 
//						 
//					//		*(pucImg + rr * nCol + cc) = 255 ; //// set white to the image 
//							*(pucGrd + rr * nCol + cc) = 0;  //// remove the points on the extracted line 
//							 
//						} 
//					}	 
//				}					 
//			} 
//		} 
//	} 
// 
//	TRACE("N = %d\n",N); 
// 
//	nRetC = TraceLinesFrmHoughTPts(pcPts,pucGrd,pucDir,nRow,nCol,nWinW,pobjSegs); 
// 
//	delete	pucGrd; 
//	delete	pucDir; 
//	delete	pcPts; 
//	return	nRetC; //// nRetC 
//} 
// 
///* 
//*/ 
//int	TraceLinesFrmHoughTPts(char	*pcPts,BYTE	*pucGrd,BYTE	*pucDir, 
//						   int	nRow,int	nCol,int	nWinW,mmOBJECT	*pobjSegs) 
//{ 
//	 
//	int	nLineC,i,j,r,c,x0,y0,nPtCL,nPtCR,nPtC,x,y; 
//	dfPOINT	pptL[200],pptR[200],pptLR[200]; 
//	nPOINT	pnptP[1]; 
// 
//	nLineC = 0; 
//	 
//	for(r=0;rnX;	 
//					pptL[nPtCL].dfY = pnptP->nY;	 
//					nPtCL++; 
//					x0 = pnptP->nX; 
//					y0 = pnptP->nY; 
//				} 
//				else 
//					break; 
//			} 
//			////// trace direction 2 
//			x0 = c;			y0 = r; 
//			nPtCR = 0; 
//			pptR[nPtCR].dfX = x0;					pptR[nPtCR].dfY = y0; 
//			nPtCR++; 
//			for(;;) 
//			{	if(FindColsestPt(pcPts,pucGrd,pucDir,nRow,nCol,nWinW,x0,y0,pnptP,false)) 
//				{ 
//					pptR[nPtCR].dfX = pnptP->nX; 
//					pptR[nPtCR].dfY = pnptP->nY; 
//					nPtCR++; 
//					x0 = pnptP->nX; 
//					y0 = pnptP->nY; 
//				} 
//				else 
//					break; 
//			} 
//			*(pcPts+r*nCol+c) = -1; 
//			if(nPtCR+nPtCL > 6)//// record the line  2 
//			{	 
//				nPtC = 0; 
//				for(i=0;inObjType = 1; 
//				(pobjSegs+nLineC)->pnptObjPtCen = (dfPOINT *)malloc(nPtC*sizeof(dfPOINT)); 
//				(pobjSegs+nLineC)->nObjPtCount = nPtC; 
//				(pobjSegs+nLineC)->nExtrState = AUTO_EDGE; 
//				 
//				for(i=0;ipnptObjPtCen[i].dfX = pptLR[i].dfX;	 
//					(pobjSegs + nLineC)->pnptObjPtCen[i].dfY = pptLR[i].dfY;					 
//				} 
//				nLineC++; 
//			} 
//		}	 
//	} 
//	return	nLineC; 
//} 
// 
///* 
//*/ 
//bool	FindColsestPt(char	*pcPts,BYTE	*pucGrd,BYTE	*pucDir, 
//					  int	nRow,int	nCol,int	nWinW,int	x0,int	y0,nPOINT	*pnptP,bool	bDir) 
//{ 
//	int	r,c,x,y,t0,t,tt0,tt; 
//	float	v,th0,xx,yy,mind,d,s; 
//	 
//	v = 360.0/255.0; 
//	 
//	t0 = 3 * (int)(*(pcPts+y0*nCol+x0)); //// line direction  
//	tt0 = (int)(v * (float)(*(pucDir+y0*nCol+x0))); //// approximate normal direction of the line 
//	if(fabs(tt0 - (t0 + 90)) < fabs(tt0 - (t0 - 90))) 
//		tt0 = t0 + 90; 
//	else 
//		tt0 = t0 - 90; 
//	mind = 9999999.9; 
//	for(r=-nWinW;r<=nWinW;r++) 
//	{	for(c=-nWinW;c<=nWinW;c++) 
//		{ 
//			if( c==0 && r==0 ) 
//				continue; 
//			x = x0 + c; 
//			y = y0 + r; 
//			if(x<0||x>=nCol||y<0||y>=nRow) 
//				continue; 
//			 
//			if(*(pcPts+y*nCol+x) == -1 ) 
//				continue; 
//			t = 3 * (int)(*(pcPts+y*nCol+x));  
//			if(fabs(t-t0)>6)///// direction condition 
//				continue; 
//			tt = (int)(v * (float)(*(pucDir + y*nCol + x))); 
//			if(fabs(tt - (t + 90)) < fabs(tt - (t - 90))) 
//				tt = t + 90; 
//			else 
//				tt = t - 90; 
//			if(fabs(tt-tt0)>6) //// normal direction condition 
//				continue; 
//			th0 = bDir? t0*PI/180.0 : (t0+180)*PI/180.0;								 
// 
//			xx = (x - x0)*cos(th0) + (y-y0)*sin(th0); 
//			yy = -(x - x0)*sin(th0) + (y-y0)*cos(th0); 
// 
//			if( fabs(yy)>2.0 || xx <=1.0 ) 
//				continue; 
//			d = sqrt(xx*xx+yy*yy); 
//			s = 0.4*(1.0 - xx/(float)nWinW) + 0.6*fabs(yy)/10.0; 
//			if(xxnX = x; 
//				pnptP->nY = y; 
//			} 
//		} 
//	} 
//	if(mind > 999999) 
//		return	false; 
//	else 
//		return	true; 
//}