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

📄 mssb1dlg.cpp

📁 1、编制程序显示印章图像(24位真彩色位图); 2、读出位图中每一像素点的(R
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// MSSB1Dlg.cpp : implementation file
//模式识别实验1--印章识别

#include "stdafx.h"
#include "MSSB1.h"
#include "MSSB1Dlg.h"
#include <vector>
#include "math.h"


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

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

using   namespace   std;

BYTE point2rGb[3];
CPoint LinePoint[2];
CPoint tempF,tempT;
CString info,info1,info2,info3,info4;
int LineNum;


class CAboutDlg : public CDialog
{
public:
	CAboutDlg();

// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	//}}AFX_DATA

	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CAboutDlg)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:
	//{{AFX_MSG(CAboutDlg)
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
	//{{AFX_DATA_INIT(CAboutDlg)
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMSSB1Dlg dialog

CMSSB1Dlg::CMSSB1Dlg(CWnd* pParent /*=NULL*/)
	: CDialog(CMSSB1Dlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMSSB1Dlg)
	m_r = 0;
	m_g = 0;
	m_b = 0;
	m_y = 0;
	m_x = 0;
	m_selClassPoint = -1;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMSSB1Dlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMSSB1Dlg)
	DDX_Text(pDX, IDC_EDIT1, m_r);
	DDX_Text(pDX, IDC_EDIT2, m_g);
	DDX_Text(pDX, IDC_EDIT3, m_b);
	DDX_Text(pDX, IDC_EDIT5, m_y);
	DDX_Text(pDX, IDC_EDIT4, m_x);
	DDX_Radio(pDX, IDC_RADIO1, m_selClassPoint);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMSSB1Dlg, CDialog)
	//{{AFX_MSG_MAP(CMSSB1Dlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON6, OnButton6)
	ON_BN_CLICKED(IDC_BUTTON2, OnButton2)
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	ON_WM_MOUSEMOVE()
	ON_WM_LBUTTONDOWN()
	ON_WM_LBUTTONUP()
	ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
	ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
	ON_BN_CLICKED(IDC_BUTTON5, OnButton5)
	ON_CBN_SELCHANGE(IDC_COMBO1, OnSelchangeCombo1)
	ON_CBN_SELCHANGE(IDC_COMBO2, OnSelchangeCombo2)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMSSB1Dlg message handlers

BOOL CMSSB1Dlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// Add "About..." menu item to system menu.

	// IDM_ABOUTBOX must be in the system command range.
	ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
	ASSERT(IDM_ABOUTBOX < 0xF000);

	CMenu* pSysMenu = GetSystemMenu(FALSE);
	if (pSysMenu != NULL)
	{
		CString strAboutMenu;
		strAboutMenu.LoadString(IDS_ABOUTBOX);
		if (!strAboutMenu.IsEmpty())
		{
			pSysMenu->AppendMenu(MF_SEPARATOR);
			pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
		}
	}

	// Set the icon for this dialog.  The framework does this automatically
	//  when the application's main window is not a dialog
	SetIcon(m_hIcon, TRUE);			// Set big icon
	SetIcon(m_hIcon, FALSE);		// Set small icon
	
	// TODO: Add extra initialization here

	pCombox1=(CComboBox*)GetDlgItem(IDC_COMBO1);
    pCombox2=(CComboBox*)GetDlgItem(IDC_COMBO2);
    m_sel3ClassQuestion=-1;
	m_selRGB=-1;
	LineNum=0;
		
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMSSB1Dlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

void CMSSB1Dlg::OnPaint() 
{
	if (IsIconic())
	{
		CPaintDC dc(this); // device context for painting

		SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

		// Center icon in client rectangle
		int cxIcon = GetSystemMetrics(SM_CXICON);
		int cyIcon = GetSystemMetrics(SM_CYICON);
		CRect rect;
		GetClientRect(&rect);
		int x = (rect.Width() - cxIcon + 1) / 2;
		int y = (rect.Height() - cyIcon + 1) / 2;

		// Draw the icon
		dc.DrawIcon(x, y, m_hIcon);
	}
	else
	{
		CDialog::OnPaint();
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMSSB1Dlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}


void CMSSB1Dlg::readBmp()                  //读取BMP图片RGB值
{
	CClientDC dc(this);
	COLORREF m;
	
	for(int i=0;i<332;i++)
	{
		for(int j=0;j<234;j++)
		{
            m = dc.GetPixel(i+23,j+75);
            color[i][j] = m;			
		}
	}

}
void CMSSB1Dlg::DrawPattenPoint(COLORREF m,int ClassPoint,int selRG)
{
  
	int r = GetRValue(m);
	int g = GetGValue(m);
	int b = GetBValue(m);
  

  int selClassPoint = ClassPoint;
  int selRGB = selRG;

  switch(selClassPoint) 
  {
    case 0: switch(selRGB)
			{
				case 0:DrawA(r,g);break;
				case 1:DrawA(r,b);break;
				case 2:DrawA(g,b);break;
				case 3:break;
			}
  	  break;
    case 1: switch(selRGB)
			{
				case 0:DrawB(r,g);break;
				case 1:DrawB(r,b);break;
				case 2:DrawB(g,b);break;
				case 3:break;
			}
  	  break;
	case 2: switch(selRGB)
			{
				case 0:DrawC(r,g);break;
				case 1:DrawC(r,b);break;
				case 2:DrawC(g,b);break;
				case 3:break;
			}
		break;
    default: MessageBox("Function DrawPattenPoint is wrong?");
  }
}

void CMSSB1Dlg::OnButton6() 
{
	// TODO: Add your control notification handler code here
	MessageBox("      本程序是在XXX同学的指导和讨论下完成的。");
}

void CMSSB1Dlg::OnButton2() 
{
	// TODO: Add your control notification handler code here
    CFile bmp("b.bmp",CFile::modeRead);
    //ShowWindow(1021,);
}

void CMSSB1Dlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
	CFile bmp("a.bmp",CFile::modeRead);
    //ShowWindow(1020,);
}


void CMSSB1Dlg::OnMouseMove(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
 UpdateData();                //从对话框控件中得到数据
	   DrawXYZ(); 
       CClientDC dc(this);

	   if(point.y<309 && point.y>75 && point.x>23)
	   {
		   if(point.x<355)
		   { 
               COLORREF m = dc.GetPixel(point);
			   BYTE r = GetRValue(m);
			   BYTE g = GetGValue(m);
			   BYTE b = GetBValue(m);

			   m_x = point.x-23;// - 11;
		       m_y = point.y-75;// - 11;
			   m_r = r;
			   m_g = g;
			   m_b = b;

			   CBrush brush;
               cur_color = RGB(m_r,m_g,m_b);
			   brush.CreateSolidBrush(cur_color);
			   CBrush *m_OldBrush=(CBrush*)dc.SelectObject(&brush);
			   dc.Ellipse(345,25,365,45);
			   dc.SelectObject(m_OldBrush);

		   }
		   if(point.x>367)
		   {
               m_x = point.x-368;
			   m_y =309-point.y;
		   }
	      UpdateData(false);
	   }

	   if(point.x>367 && point.y<309)
	   {
		   if(classOne1.size()!=0 && classTwo1.size()!=0 && classThree1.size()!=0)
		   {
			   if(LinePoint[0].x>367 && LinePoint[0].y<309)
			   {   
				   dc.SetROP2(2);
				   dc.MoveTo(LinePoint[0]);
				   dc.LineTo(LinePoint[1]);
				   dc.MoveTo(LinePoint[0]);
				   dc.LineTo(point);
				   LinePoint[1] = point;
			   }
		   }
	   }

	CDialog::OnMouseMove(nFlags, point);
}

void CMSSB1Dlg::OnLButtonDown(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	
	  UpdateData();                      //从对话框控件中得到数据
	  CClientDC dc(this);
		  COLORREF m = dc.GetPixel(point);
		  BYTE r = GetRValue(m);
		  BYTE g = GetGValue(m);
		  BYTE b = GetBValue(m);


///////////采集样本点保存在vector容器中,显示在RGB坐标上及显示在Edit框中///////////	
	      if(point.x>22 && point.x<354 && point.y>75 && point.y<309)
		  {  


		     if(m_selClassPoint < 0 || m_selRGB < 0 || m_sel3ClassQuestion < 0)
			 {
			   MessageBox("请首先选择采集样本点所属类型,RGB坐标类型,三类判别问题类型");
			 }
		    else if(m_selClassPoint == 0)
			{
			   UpdateData(); 

			   CString s;
			   s.Format("%d. ",r);
			   info1+=s;
			   s.Format("%d. ",g);
			   info1+=s;
			   s.Format("%d",b);
			   info1+=s;
			   info1+="\r\n";
			   ShowWindow(1013,info1);
			   
			   DrawPattenPoint(m,m_selClassPoint,m_selRGB);
 			   classOne1.push_back(m);
			   
			}
		    else if(m_selClassPoint == 1)
			{
			   UpdateData(); 
			   
               CString s;
			   s.Format("%d. ",r);
			   info2+=s;
			   s.Format("%d. ",g);
			   info2+=s;
			   s.Format("%d",b);
			   info2+=s;
			   info2+="\r\n";
			   ShowWindow(1014,info2);

			   DrawPattenPoint(m,m_selClassPoint,m_selRGB);
 			   classTwo1.push_back(m);
			}
		    else if(m_selClassPoint == 2)
			{
			   UpdateData(); 

               CString s;
			   s.Format("%d. ",r);
			   info3+=s;
			   s.Format("%d. ",g);
			   info3+=s;
			   s.Format("%d",b);
			   info3+=s;
			   info3+="\r\n";
			   ShowWindow(1015,info3);

			   DrawPattenPoint(m,m_selClassPoint,m_selRGB);
 			   classThree1.push_back(m);
			}
		  }
		  
//////////////手动画判别直线//////////////////
          if(point.x>367 && point.y<309)
		  {
			  if(classOne1.size()!=0 && classTwo1.size()!=0 && classThree1.size()!=0)
			  {
				  if(LineNum < 3)
				  {
					  LineNum++;
					  LinePoint[0] = point;
					  LinePoint[1] = point;
				  }
				  else MessageBox("可以按 |识别| 按钮判别了!");
			  }
			  else  MessageBox("请采集完三类样本点之后再手动判别!");
          }
		
	CDialog::OnLButtonDown(nFlags, point);
}

void CMSSB1Dlg::OnLButtonUp(UINT nFlags, CPoint point) 
{
	// TODO: Add your message handler code here and/or call default
	if(point.x>367 && point.y<309)
	   {
		if(classOne1.size()!=0 && classTwo1.size()!=0 && classThree1.size()!=0)
		{
			if(LinePoint[0].x>367 && LinePoint[0].y<309)
			{   
				tempF.x = LinePoint[0].x - 368;
				tempF.y = 309 - LinePoint[0].y;
				tempT.x = point.x - 368;

⌨️ 快捷键说明

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