VC6.0图形处理9--轮廓提取

//前面请参照之前的文章


void CBMPViewerDoc::OnMenuitem32797() //轮廓提取 适合已经转变为二值图像

{
// 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;
int sum;


// TODO: Add your command handler code here
for(int i = 0 ; i< bi.biHeight ; i++){

for(int j = 0 ; j< bi.biWidth ; j++){
lpDest = (unsigned char *)lpTemp + linewidth *(bi.biHeight - i -1) + j;
if((i == 0 ) || (j ==0) || (i == bi.biHeight) || (j == bi.biWidth) ){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - i -1) + j;
*lpDest = 255;
}
else{
sum = 0;
for(int m = i -1 ; m <= i+1 ;m++){
for(int n = j-1; n<=j+1; n++){
lpScr = (unsigned char*)lpBuf + linewidth*(bi.biHeight - m -1) + n;
sum += *lpScr;
}
}





if(sum %9 !=0 )
{
*lpDest = 0;
}

else *lpDest= 255;

}
}

}

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

UpdateAllViews(NULL,0,NULL);



}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值