VC6.0图形处理8--Hough变换(下)

源码下载:http://download.csdn.net/detail/renshengrumenglibing/3875522

//请先仔细研读Hough变化的算法问题

void CBMPViewerDoc::OnMenuitem32796() //Hough变化

{//现在只能处理二值图像



// TODO: Add your command handler code here
int linewidth;
linewidth=(pbi->bmiHeader.biWidth*pbi->bmiHeader.biBitCount+31)/32*4;




HLOCAL hTemp;
hTemp = LocalAlloc(LHND ,linewidth * bi.biHeight );

LPSTR lpTemp;
lpTemp = (char*)LocalLock(hTemp);
unsigned char *lpScr;
unsigned char * lpDest;




HLOCAL hTransArea;


hTransArea = LocalAlloc(LHND, bi.biWidth * bi.biHeight *sizeof(int));
LPSTR lpTransArea;
lpTransArea = (char *)(LocalLock(hTransArea));


//变换域尺寸
int iMaxAngleNumber;
int iMaxDist;


unsigned char pixel;


int iDest;
int iAngleNumber;
//变换域两个最大值
int MaxValue1 , MaxValue2;
//最大距离
iMaxDist = (int)(sqrt(bi.biHeight *bi.biHeight + bi.biWidth + bi.biWidth));
//每格两度
iMaxAngleNumber = 180;
//为内存赋初值


int Dist;//存放变换域中最大那个数的位置
int AngleNumber;


memset(lpTransArea , 0 , bi.biWidth * bi.biHeight *sizeof(int));




// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){
for(int j = 0 ; j< bi.biWidth ; j++){
lpScr = (unsigned char *)lpBuf+linewidth*(bi.biHeight - i -1) + j;
pixel = *lpScr;
if(pixel ==0){
for(iAngleNumber = 0 ; iAngleNumber < iMaxAngleNumber; iAngleNumber++){
iDest = (int)(fabs(i*cos(iAngleNumber*2*PI/180.0)) + j*(sin(iAngleNumber*2 *PI/180.0)));
*(lpTransArea+iDest*iMaxAngleNumber + iAngleNumber) = *(lpTransArea+iDest*iMaxAngleNumber + iAngleNumber)+1;


}
}




}

}


//找变换域中的两个最大点
MaxValue1 = 0 ;

for( iDest = 0 ; iDest < iMaxDist ; iDest++){
for(iAngleNumber = 0 ; iAngleNumber < iMaxAngleNumber ; iAngleNumber++){

lpDest =(unsigned char*)(lpTransArea + iDest*iMaxAngleNumber + iAngleNumber);

if(*lpDest > MaxValue1){
MaxValue1 = *lpDest;
Dist = iDest;
AngleNumber = iAngleNumber;


}
}
}


//重绘该直线


for(int m = 0 ;m< bi.biHeight; m++){
for(int n = 0 ; n< bi.biWidth; n++){
lpDest = (unsigned char *)lpTemp + linewidth * (bi.biHeight-m -1) + n;
iDest = (int)(fabs(m*cos(AngleNumber*2*PI/180.0)) + n*(sin(AngleNumber*2 *PI/180.0)));
if((iDest -Dist) < 2 &&(iDest - Dist) > -2){
*lpDest = 0 ;
}
else{
*lpDest = 255;
}






}
}


memcpy(lpBuf, lpTemp, linewidth * bi.biHeight);
// Invalidata(TRUE);
UpdateAllViews(NULL,0,NULL);



}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值