?? hongmoview.cpp
字號:
// hongmoView.cpp : implementation of the CHongmoView class
//
#include "stdafx.h"
#include "hongmo.h"
#include "hongmoDoc.h"
#include "hongmoView.h"
#include "GlobalApi.h"
#include "GUIYIHUA.h"
#include "Cdib.h"
#include "math.h"
#include <complex>
using namespace std;
#define pi 3.1415927
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CHongmoView
IMPLEMENT_DYNCREATE(CHongmoView, CScrollView)
BEGIN_MESSAGE_MAP(CHongmoView, CScrollView)
//{{AFX_MSG_MAP(CHongmoView)
ON_COMMAND(ID_CAOZUO_CANNYDETECTION, OnCaozuoCannydetection)
ON_COMMAND(ID_CAOZUO_DINGWEI, OnCaozuoDingwei)
ON_COMMAND(ID_CAOZUO_GUIYIHUA, OnCaozuoGuiyihua)
ON_COMMAND(ID_CAOZUO_JUNHENG, OnCaozuoJunheng)
//}}AFX_MSG_MAP
// Standard printing commands
ON_COMMAND(ID_FILE_PRINT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_DIRECT, CScrollView::OnFilePrint)
ON_COMMAND(ID_FILE_PRINT_PREVIEW, CScrollView::OnFilePrintPreview)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHongmoView construction/destruction
CHongmoView::CHongmoView()
{
// TODO: add construction code here
}
CHongmoView::~CHongmoView()
{
}
BOOL CHongmoView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CScrollView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView drawing
void CHongmoView::OnDraw(CDC* pDC)
{
CHongmoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CSize sizeDibDisplay;
if(!pDoc->m_pDibInit->IsEmpty())
{
sizeDibDisplay = pDoc->m_pDibInit->GetDimensions();
pDoc->m_pDibInit->Draw(pDC,CPoint(0,0),sizeDibDisplay);
}
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView printing
BOOL CHongmoView::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CHongmoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CHongmoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CHongmoView diagnostics
#ifdef _DEBUG
void CHongmoView::AssertValid() const
{
CScrollView::AssertValid();
}
void CHongmoView::Dump(CDumpContext& dc) const
{
CScrollView::Dump(dc);
}
CHongmoDoc* CHongmoView::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CHongmoDoc)));
return (CHongmoDoc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CHongmoView message handlers
void CHongmoView::OnInitialUpdate()
{
// CView::OnInitialUpdate();
// TODO: Add your specialized code here and/or call the base class
CScrollView::OnInitialUpdate();
CHongmoDoc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
CSize sizeTotal = pDoc->m_pDibInit->GetDimensions();
//已改動
SetScrollSizes(MM_TEXT, sizeTotal);
GetParentFrame()->RecalcLayout();
ResizeParentToFit();
}
void CHongmoView::OnCaozuoCannydetection()
{
// TODO: Add your command handler code here
CHongmoDoc * pDoc = (CHongmoDoc *)this->GetDocument();
CDib * pDib = pDoc->m_pDibInit;
LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
// 判斷是否是8-bpp位圖
if (lpBMIH->biBitCount != 8)
{
// 提示用戶
MessageBox("目前只支持256色位虹膜圖像的邊緣檢測!", "系統提示" ,
MB_ICONINFORMATION | MB_OK);
// 返回
return;
}
//更改光標形狀
BeginWaitCursor();
/*************************************************/
//循環變量
int i;
int j;
/*************************************************/
CSize sizeImage = pDib->GetDimensions();
int nWidth = sizeImage.cx;
int nHeight= sizeImage.cy;
int nSaveWidth = pDib->GetDibSaveDim().cx;
// 開辟內存,存儲圖象數據
unsigned char * pUnchImage = new unsigned char[nWidth*nHeight];
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
pUnchImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
// canny算子計算后的結果
unsigned char * pUnchEdge = new unsigned char[nWidth*nHeight];
// 導數x的方向指針
double * CosTheta = new double [nWidth*nHeight];
// 導數y的方向指針
double * SinTheta = new double [nWidth*nHeight];
/*************************************************/
// 調用Canny()函數對虹膜圖像進行邊緣檢測
Canny(pUnchImage, nWidth, nHeight, 0.8, 0.44, 0.83, pUnchEdge,CosTheta,SinTheta);
/*************************************************/
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth;j++)
{
pDib->m_lpImage[i*nWidth+j]=pUnchEdge[i*nWidth+j];
}
}
/*************************************************/
// 釋放內存
delete []pUnchImage;
pUnchImage = NULL;
delete []pUnchEdge;
pUnchEdge = NULL;
delete []CosTheta;
CosTheta = NULL;
delete []SinTheta;
SinTheta = NULL;
/*************************************************/
// 恢復光標
EndWaitCursor();
// 設置臟標記
pDoc->SetModifiedFlag(TRUE);
// 更新視圖
pDoc->UpdateAllViews(NULL);
}
void CHongmoView::OnCaozuoDingwei()
{
// TODO: Add your command handler code here
CHongmoDoc * pDoc = (CHongmoDoc *)this->GetDocument();
CDib * pDib = pDoc->m_pDibInit;
LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
// 判斷是否是8-bpp位圖
if (lpBMIH->biBitCount != 8)
{
// 提示用戶
MessageBox("目前只支持256色位虹膜圖像的邊緣檢測!", "系統提示" ,
MB_ICONINFORMATION | MB_OK);
// 返回
return;
}
//更改光標形狀
BeginWaitCursor();
/*************************************************/
//循環變量
int i;
int j;
/*************************************************/
CSize sizeImage = pDib->GetDimensions();
int nWidth = sizeImage.cx;
int nHeight= sizeImage.cy;
int nSaveWidth = pDib->GetDibSaveDim().cx;
// 開辟內存,存儲圖象數據
unsigned char * pUnchImage = new unsigned char[nWidth*nHeight];
unsigned char* HoughImage = new unsigned char[nWidth*nHeight];
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
pUnchImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
for(i=0; i<nHeight; i++)
{
for(j=0; j<nWidth; j++)
{
HoughImage[i*nWidth+j] = pDib->m_lpImage[i*nSaveWidth+j];
}
}
// canny算子計算后的結果
unsigned char * pUnchEdge = new unsigned char[nWidth*nHeight];
// 導數x的方向指針
double * CosTheta = new double [nWidth*nHeight];
// 導數y的方向指針
double * SinTheta = new double [nWidth*nHeight];
/*************************************************/
// 調用Canny()函數對虹膜圖像進行邊緣檢測
Canny(pUnchImage, nWidth, nHeight, 0.8, 0.44, 0.83, pUnchEdge,CosTheta,SinTheta);
/*************************************************/
// 確定內圓半徑范圍
int temp1 = 30;
int temp2 = 70;
int temp_2 = 0;
int temp_3 = 0;
int temp_4 = 0;
// 調用Hough()函數提取內圓圓心和半徑
Hough(temp1,temp2,nWidth,nHeight,CosTheta,SinTheta,pUnchEdge,temp_2,temp_3,temp_4);
//在原圖像上用Bresenham畫圓算法生成小圓
Bresenham(temp_2,temp_3,temp_4,nWidth,nHeight,HoughImage);
/*************************************************/
//去除不必要的邊界點
for(i = 0; i < nHeight; i++)
{
for(j = 0; j < nWidth; j++)
{
if((i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)>temp_4*temp_4 && (i-temp_2)*(i-temp_2)+(j-temp_3)*(j-temp_3)<(temp_4+50)*(temp_4+50))
{
pUnchEdge[i*nWidth+j] = 0;
}
}
}
for(i = 0; i < nHeight; i++)
{
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -