zoukankan      html  css  js  c++  java
  • VC6.0图形处理8Hough变换(下)

    源码下载: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);



    }
  • 相关阅读:
    leetcode【dynamic】【0】
    VIM 常用指令
    《Java多线程编程核心技术》笔记
    log4j配置文件详解
    CSU 1803 2016(同余公式)2016年湖南省第十二届大学生计算机程序设计竞赛
    NYOJ 1233 差值(字符串排序+大数减法)
    HDU 5723 Abandoned country(最小生成树+DFS)
    POJ 1451 T9 字典树
    POJ 2965 The Pilots Brothers' refrigerator 状态压缩+广搜
    POJ 1753 Flip game状态压缩+广搜
  • 原文地址:https://www.cnblogs.com/libing64/p/2878768.html
Copyright © 2011-2022 走看看