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

📄 printpatview.cpp

📁 模式识别中经典试验
💻 CPP
📖 第 1 页 / 共 2 页
字号:
 // PrintPatView.cpp : implementation of the CPrintPatView class
//

#include "stdafx.h"
#include "PrintPat.h"

#include "PrintPatDoc.h"
#include "PrintPatView.h"
#include "Dib.h"
#include "MainFrm.h"
#include "vfw.h"


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

/////////////////////////////////////////////////////////////////////////////
// CPrintPatView

IMPLEMENT_DYNCREATE(CPrintPatView, CFormView)

BEGIN_MESSAGE_MAP(CPrintPatView, CFormView)
	//{{AFX_MSG_MAP(CPrintPatView)
	ON_WM_PAINT()
	ON_WM_CREATE()
	ON_BN_CLICKED(IDC_MAN, OnManRecognise)
	ON_BN_CLICKED(IDC_AUTO, OnAutoRecognise)
	ON_BN_CLICKED(IDC_RED_BLUE, OnRedBlueMode)
	ON_BN_CLICKED(IDC_RED_GREEN, OnRedGreenMode)
	ON_BN_CLICKED(IDC_BLUE_GREEN, OnBlueGreenMode)
	ON_BN_CLICKED(IDC_PAT_TWO, OnPatTwoMode)
	ON_BN_CLICKED(IDC_PAT_THREE, OnPatThreeMode)
	ON_BN_CLICKED(IDC_PRINT_PAT, OnPrintPatSelect)
	ON_BN_CLICKED(IDC_SIGN_PAT, OnSignPatSelect)
	ON_BN_CLICKED(IDC_SHADE_PAT, OnShadePatSelect)
	ON_BN_CLICKED(IDC_BEGIN_SAMPLING, OnBeginSampling)
	ON_WM_LBUTTONDOWN()
	ON_WM_MOUSEMOVE()
	ON_BN_CLICKED(IDC_IS_SAMPLE_FINISH, OnIsSampleFinishCheck)
	ON_BN_CLICKED(IDC_BUTTON_PATTEN_REC, OnButtonPattenRec)
	ON_BN_CLICKED(IDC_SAMPLE_AGAIN, OnSampleAgain)
	//}}AFX_MSG_MAP
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_X,OnUpdaeUIXIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_Y,OnUpdaeUIYIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_R,OnUpdaeUIRIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_G,OnUpdaeUIGIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_B,OnUpdaeUIBIndicator)
	ON_UPDATE_COMMAND_UI(ID_INDICATOR_CURRENTCOLOR,OnUpdaeUICurrentColorIndicator)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPrintPatView construction/destruction

CPrintPatView::CPrintPatView()
	: CFormView(CPrintPatView::IDD)
{
	//{{AFX_DATA_INIT(CPrintPatView)
	m_isSampleFinish = FALSE;
	//}}AFX_DATA_INIT
	// TODO: add construction code here

	//默认为手动判别模式
	m_RecMode = manual;

	//模式种类为0
	m_NumKinds = 0;
	
	//等待选择两种模式下的类型
	m_TwoKindMode = noChoice;
	
	//不选任何颜色
	m_patTypeSel = (PattenType)0;
	
	//图像显示区域鼠标左击要用到的
	m_nHeight  = 0;
	m_NumKinds = 0;

	//状态蓝要用的
	m_indicator_B=m_indicator_G=m_indicator_R=m_indicator_X=m_indicator_Y = 2000;
	
	//图像的高度和宽度
	m_nHeight = 0;
	m_nWidth  = 0;
	//清空链表
	MyPatternShade.RemoveAll();
	MyPatternSign.RemoveAll();
	MyPatternPrint.RemoveAll();
	m_drawLinePointsList.RemoveAll();

	m_BeginSamp = FALSE;
	m_NewlySamp = FALSE;

	ListIndex = 0;
}

CPrintPatView::~CPrintPatView()
{
}

void CPrintPatView::DoDataExchange(CDataExchange* pDX)
{
	CFormView::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPrintPatView)
	DDX_Control(pDX, IDC_LIST_FUNCTION, m_functionListBox);
	DDX_Control(pDX, IDC_IS_SAMPLE_FINISH, m_isSampleFinishCheck);
	DDX_Control(pDX, IDC_LIST_EDIT, m_pattenListBox);
	DDX_Check(pDX, IDC_IS_SAMPLE_FINISH, m_isSampleFinish);
	//}}AFX_DATA_MAP
}

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

	return CFormView::PreCreateWindow(cs);
}

void CPrintPatView::OnInitialUpdate()
{
	CFormView::OnInitialUpdate();
	GetParentFrame()->RecalcLayout();
	ResizeParentToFit();

}

/////////////////////////////////////////////////////////////////////////////
// CPrintPatView diagnostics

#ifdef _DEBUG
void CPrintPatView::AssertValid() const
{
	CFormView::AssertValid();
}

void CPrintPatView::Dump(CDumpContext& dc) const
{
	CFormView::Dump(dc);
}

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

/////////////////////////////////////////////////////////////////////////////
// CPrintPatView message handlers

void CPrintPatView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// TODO: Add your message handler code here
	CPrintPatDoc* pDoc=GetDocument();
	
	Pix24Bitmap PixTemp;
	CDib* pDib = pDoc->GetDibPoint();
 
	HDC hDC = dc.GetSafeHdc();
	if(pDib)
	{
		m_nWidth = pDib->GetWidth();
		m_nHeight = pDib->GetHeight();
		HDRAWDIB m_hDrawDib; // 视频函数
		m_hDrawDib=DrawDibOpen();
		DrawDibDraw(m_hDrawDib,hDC,20,30,m_nWidth,m_nHeight,
					pDib->GetBitmapInfoHeaderPoint(),pDib->GetDibDataPoint(),
					0,0,m_nWidth,m_nHeight,1);
		DrawDibClose(m_hDrawDib);

			
	}/*
	if(pDib)
	{
		//获取位图的宽度和高度
		m_nWidth = (int)pDib->GetWidth();
		m_nHeight = (int)pDib->GetHeight();

		for(int i=0;i<m_nHeight;i++)
			for(int j=0;j<m_nWidth;j++)
			{
				PixTemp=(pDoc->GetDibPoint())->LoadBitmapIndex(i,j);			
				dc.SetPixelV(j+20,i+30,RGB(PixTemp.Red,PixTemp.Green,PixTemp.Blue));				
			}
			
	}
*/

	// Do not call CFormView::OnPaint() for painting messages
}

int CPrintPatView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
	if (CFormView::OnCreate(lpCreateStruct) == -1)
		return -1;
	
	// TODO: Add your specialized creation code here
	CClientDC dc(this);
	//创建设备兼容位图
	m_bitmap.CreateCompatibleBitmap(&dc, 800, 600);

	CDC memDC;
	memDC.CreateCompatibleDC(&dc);

	CBitmap* pOldBitmap = memDC.SelectObject(&m_bitmap);
	CBrush* pBrush = new CBrush(RGB(255, 255, 255));
	CRect rect(0, 0, 800, 600);
	int nOldBkMode = memDC.SetBkMode(TRANSPARENT);
	memDC.FillRect(rect, pBrush);

	memDC.SelectObject(pOldBitmap);
    delete pBrush;
	ReleaseDC(&dc);

	return 0;
}

void CPrintPatView::OnManRecognise() 
{
	// TODO: Add your control notification handler code here
	m_RecMode = manual;
}

void CPrintPatView::OnAutoRecognise() 
{
	// TODO: Add your control notification handler code here
	m_RecMode = automation;
}

void CPrintPatView::OnRedBlueMode() 
{
	// TODO: Add your control notification handler code here
	m_TwoKindMode = rANDb;
}

void CPrintPatView::OnRedGreenMode() 
{
	// TODO: Add your control notification handler code here
	m_TwoKindMode = rANDg;
}

void CPrintPatView::OnBlueGreenMode() 
{
	// TODO: Add your control notification handler code here
	m_TwoKindMode = bANDg;
}

void CPrintPatView::OnPatTwoMode() 
{
	// TODO: Add your control notification handler code here
	m_NumKinds = 2;
}

void CPrintPatView::OnPatThreeMode() 
{
	// TODO: Add your control notification handler code here
	m_NumKinds = 3;
}	

void CPrintPatView::OnPrintPatSelect() 
{
	// TODO: Add your control notification handler code here
	m_patTypeSel = print;
	m_pattenListBox.InsertString(ListIndex,"印章采样");
	ListIndex++;
}

void CPrintPatView::OnSignPatSelect() 
{
	// TODO: Add your control notification handler code here
	m_patTypeSel = sign;
	m_pattenListBox.InsertString(ListIndex,"签字采样");
	ListIndex++;
}

void CPrintPatView::OnShadePatSelect() 
{
	// TODO: Add your control notification handler code here
	m_patTypeSel = shade;
	m_pattenListBox.InsertString(ListIndex,"底纹采样");
	ListIndex++;
}

void CPrintPatView::OnBeginSampling() 
{
	// TODO: Add your control notification handler code here
	m_BeginSamp=TRUE;
	m_NewlySamp=FALSE;
	DrawReferenceFrame();
/*	//根据特征绘图
	CClientDC dc(this); // device context for painting
	
	CPen  newpenSolid,*oldpen;
	CBrush newbrush(RGB(255,0,0)),*oldbrush;
	newpenSolid.CreatePen(PS_SOLID,1,RGB(0,0,0));
	oldpen=dc.SelectObject(&newpenSolid);

	dc.Rectangle(420,6,800,266);//原点是(420,266);
	for(int i=520;i<800;i=i+100)
	{
		dc.MoveTo(i,266);
		dc.LineTo(i,6);
	}
	for(int j=196;j>6;j=j-70)
	{
		dc.MoveTo(420,j);
		dc.LineTo(800,j);
	}
	oldbrush=dc.SelectObject(&newbrush);
	CString str1="0";
	dc.TextOut(417,266,str1);
	str1="100";
	dc.TextOut(517,266,str1);
	str1="200";
	dc.TextOut(617,266,str1);
	str1="300";
	dc.TextOut(717,266,str1);
	str1="70";
	dc.TextOut(404,190,str1);
	str1="140";
	dc.TextOut(396,120,str1);
	str1="210";
	dc.TextOut(396,50,str1);
	
	switch(m_TwoKindMode) {
	case rANDb:
		str1="R";
		dc.TextOut(790,266,str1);
		str1="X2:";
		dc.TextOut(769,266,str1);
		str1="B";
		dc.TextOut(408,6,str1);
		str1="X1:";
		dc.TextOut(387,6,str1);
		break;
	case rANDg:
		str1="R";
		dc.TextOut(790,266,str1);
		str1="X2:";
		dc.TextOut(769,266,str1);
		str1="G";
		dc.TextOut(408,6,str1);
		str1="X1:";
		dc.TextOut(387,6,str1);
		break;
	case bANDg:
		str1="G";
		dc.TextOut(790,266,str1);
		str1="X2:";
		dc.TextOut(769,266,str1);
		str1="B";
		dc.TextOut(408,6,str1);
		str1="X1:";
		dc.TextOut(387,6,str1);
		break;

	default:
		break;
	}
//	dc.Ellipse(438,244,442,248);//440,246
	dc.SelectObject(oldpen);
	newpenSolid.DeleteObject();
	dc.SelectObject(oldbrush);
	newbrush.DeleteObject();
	*/
}

void CPrintPatView::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if((m_nHeight == 0) | (m_nWidth == 0))
		return;

	
	if(m_BeginSamp || m_NewlySamp)
	{
		CPrintPatDoc* pDoc=GetDocument();
		Pix24Bitmap PixTemp;
		CString List;
		Pels   PelsSamp;
		CDib* pDib = pDoc->GetDibPoint();
		
		//画点准备
		CClientDC dc(this); // device context for painting
		CPen  newpenSolid,*oldpen;
		CBrush newbrush1(RGB(255,0,0)),newbrush3(RGB(0,0,255)),newbrush2(RGB(0,255,0)),*oldbrush;
		newpenSolid.CreatePen(PS_SOLID,1,RGB(0,0,0));
		oldpen=dc.SelectObject(&newpenSolid);
		oldbrush=dc.SelectObject(&newbrush1);
		POINT pointSamp;
		//准备完毕哦

		CRect m_Rect;
		m_Rect.SetRect(20,30,m_nWidth+20,m_nHeight+30);


		if(m_Rect.PtInRect(point))				//采样状态且在图片所在区域
		{
			PixTemp = pDib->LoadBitmapIndex(point.y-30,point.x-20);
			if(m_NumKinds == 2)					//两类模式下
				if(m_TwoKindMode == rANDb)		//R&B坐标下R:印章横坐标 B:底纹纵坐标
				{	
					PelsSamp.Coordinate.x = point.x-20;
					PelsSamp.Coordinate.y = point.y-30;
					PelsSamp.Blue		  = PixTemp.Blue;
					PelsSamp.Green        = PixTemp.Green;
					PelsSamp.Red          = PixTemp.Red;
					if(m_patTypeSel == print)	//红色横坐标
					{
						MyPatternPrint.AddTail(PelsSamp);
						List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternPrint.GetCount(),
						PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
						m_pattenListBox.InsertString(ListIndex,List);
						ListIndex++;
					
						dc.SelectObject(&newbrush1);
						pointSamp.x = PelsSamp.Red+420;
						pointSamp.y = 266-PelsSamp.Blue;
						dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
					}
					if(m_patTypeSel == shade)			//Blue
					{
						MyPatternShade.AddTail(PelsSamp);
						List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternShade.GetCount(),
						PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
						m_pattenListBox.InsertString(ListIndex,List);
						ListIndex++;
					
						dc.SelectObject(&newbrush3);
						pointSamp.x = PelsSamp.Red+420;
						pointSamp.y = 266-PelsSamp.Blue;
						dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
					}
				}
				if(m_TwoKindMode == rANDg)		//R&G坐标下R:印章横坐标G:签字纵坐标
				{	
					PelsSamp.Coordinate.x = point.x-20;
					PelsSamp.Coordinate.y = point.y-30;
					PelsSamp.Blue		  = PixTemp.Blue;
					PelsSamp.Green        = PixTemp.Green;
					PelsSamp.Red          = PixTemp.Red;
					if(m_patTypeSel == print)	//横坐标
					{
						MyPatternPrint.AddTail(PelsSamp);
						List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternPrint.GetCount(),
						PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
						m_pattenListBox.InsertString(ListIndex,List);
						ListIndex++;
					
						dc.SelectObject(&newbrush1);
						pointSamp.x = PelsSamp.Red+420;
						pointSamp.y = 266-PelsSamp.Green;
						dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
					}
					if(m_patTypeSel == sign)	//绿色纵坐标
					{
						MyPatternSign.AddTail(PelsSamp);
						List.Format("%3d,%5d,%5d,%5d,%5d,%5d",MyPatternSign.GetCount(),
						PelsSamp.Coordinate.x,PelsSamp.Coordinate.y,PelsSamp.Red,PelsSamp.Green,PelsSamp.Blue);
						m_pattenListBox.InsertString(ListIndex,List);
						ListIndex++;
					
						dc.SelectObject(&newbrush2);
						pointSamp.x = PelsSamp.Red+420;
						pointSamp.y = 266-PelsSamp.Green;
						dc.Ellipse(pointSamp.x-2,pointSamp.y-2,pointSamp.x+2,pointSamp.y+2);
					}
				}
				if(m_TwoKindMode == bANDg)		//B&G坐标下B:底纹纵坐标G:签字横坐标
				{	
					PelsSamp.Coordinate.x = point.x-20;
					PelsSamp.Coordinate.y = point.y-30;
					PelsSamp.Blue		  = PixTemp.Blue;

⌨️ 快捷键说明

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