⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gaoview.cpp

📁 用于对含有较粗光带的图像处理时对光带的中心线进行提取的操作
💻 CPP
字号:
// gaoView.cpp : implementation of the CGaoView class
//

#include "stdafx.h"
#include "gao.h"
#include "zhixin.h"
#include "gaoDoc.h"
#include "gaoView.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CGaoView

IMPLEMENT_DYNCREATE(CGaoView, CView)

BEGIN_MESSAGE_MAP(CGaoView, CView)
	//{{AFX_MSG_MAP(CGaoView)
	ON_COMMAND(ID_zhixin, Onzhixin)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CGaoView construction/destruction

CGaoView::CGaoView()
{
	// TODO: add construction code here

}

CGaoView::~CGaoView()
{
}

BOOL CGaoView::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CGaoView drawing

void CGaoView::OnDraw(CDC* pDC)
{
	CGaoDoc* 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);	//显示
	}
}

/////////////////////////////////////////////////////////////////////////////
// CGaoView printing

BOOL CGaoView::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CGaoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CGaoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CGaoView diagnostics

#ifdef _DEBUG
void CGaoView::AssertValid() const
{
	CView::AssertValid();
}

void CGaoView::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CGaoDoc* CGaoView::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CGaoDoc)));
	return (CGaoDoc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CGaoView message handlers

void CGaoView::Onzhixin() 
{
	// TODO: Add your command handler code here
	BeginWaitCursor(); 
	
	// 循环控制变量
	int y;
	int x;
	
	
	// 获取文档
	CGaoDoc * pDoc = (CGaoDoc *)this->GetDocument();
	
	//  获得图象CDib类的指针
	CDib * pDib = pDoc->m_pDibInit;
	
	// 获得图象的头文件信息
	LPBITMAPINFOHEADER lpBMIH=pDib->m_lpBMIH;
	
	// 判断是否是8-bpp位图
	if (lpBMIH->biBitCount != 8)
	{
		// 提示用户
		MessageBox("目前只支持256色位图的图象分割!", "系统提示" ,
			MB_ICONINFORMATION | MB_OK);
		
		// 返回
		return;
	}
	
	// 图象的长宽大小
	CSize sizeImage		= pDib->GetDimensions();
	int nWidth			= sizeImage.cx		;
	int nHeight			= sizeImage.cy		;
	
	// 指向梯度数据的指针
	double * pdGrad;
	
	// 按照图像的大小开辟内存空间,存储梯度计算的结果
	pdGrad=new double[nHeight*nWidth];
	
	//图像数据的指针
	LPBYTE  pImageData = pDib->m_lpImage;
	
	// 图像在计算机在存储中的实际大小
	CSize sizeImageSave	= pDib->GetDibSaveDim();
	
	// 图像在内存中每一行象素占用的实际空间
	int nSaveWidth = sizeImageSave.cx;
	
	//  质点法
	int pCounter=0;
	
    int *pXnew,*pYnew;
	pXnew=new int[nWidth];
	pYnew=new int[nWidth];
	
	Zhixinfa(pDib, pdGrad,pCounter,pXnew,pYnew);
	
	for(y=0; y<nHeight ; y++ )
		for(x=0 ; x<nWidth ; x++ )
		{
			
			*( pImageData+y*nSaveWidth+x )=*( pdGrad+y*nSaveWidth+x );
			
		}
		
		
		
		
		//释放梯度结果使用的内存空间
		delete pdGrad;
		delete pXnew;
		delete pYnew;
		pdGrad=NULL;
		
		// 恢复光标形状
		EndWaitCursor(); 
		
		// 设置脏标记
		pDoc->SetModifiedFlag(TRUE);
		
		// 更新视图
		pDoc->UpdateAllViews(NULL);
	
	
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -