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

📄 showprocedure.cpp

📁 车牌识别(改定位)武汉理工大学
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	POSITION pos = m_ListCtrlFileName.GetFirstSelectedItemPosition();
	if (pos)
	{
		int nItem = m_ListCtrlFileName.GetNextSelectedItem(pos);
		CString strFileName;
		strFileName = m_ListCtrlFileName.GetItemText(nItem,0);
		strFileName = m_strFolder + strFileName;
		Run(strFileName);
	}
	*pResult = 0;
}

void CShowProcedure::OnRclickListFileName(NMHDR* pNMHDR, LRESULT* pResult) 
{
	CRect rcWin;

	char szFilter[] = "BMP Files (*.bmp)|*.bmp||";
	CFileDialog     fd(FALSE,"*.bmp",NULL,0,szFilter,this);
	
	POSITION pos = m_ListCtrlFileName.GetFirstSelectedItemPosition();
	CString strOrgPath;
	if (pos)
	{
		int nItem = m_ListCtrlFileName.GetNextSelectedItem(pos);
		strOrgPath = m_ListCtrlFileName.GetItemText(nItem,0);
		strOrgPath = m_strFolder + strOrgPath;
		
		CMenu mnuScale;
		mnuScale.LoadMenu(IDR_MENU);
		CMenu* pPopup = mnuScale.GetSubMenu(0);
		if(!pPopup) return;

		m_ListCtrlFileName.GetItemRect(nItem,rcWin,LVIR_LABEL);
		ClientToScreen(rcWin);
		CPoint point;
		point = rcWin.CenterPoint();
		int nCmd = (int)pPopup->TrackPopupMenu(TPM_RETURNCMD|TPM_LEFTALIGN|TPM_LEFTBUTTON,point.x,point.y,AfxGetMainWnd(),NULL);
		switch(nCmd) 
		{
		case ID_MENU_OPEN:
			{
				CImage imgTemp;						
				if (imgTemp.Load(strOrgPath)) 
				{
					imgTemp.ShowImg();
				}					
			}		
			break;
		case ID_MENU_SAVE:
			{					
				if (fd.DoModal()==IDOK) 
				{
					CFile file;
					if (file.Open(strOrgPath,CFile::modeRead))
					{
						UINT nLen = file.GetLength();
						BYTE *pBuf = new BYTE[nLen];
						if (nLen!=file.Read(pBuf,nLen)) 
						{
							delete []pBuf;
							AfxMessageBox("保存不成功!");
							file.Close();
						}
						else
						{
							file.Close();
							if (file.Open(fd.GetPathName(),CFile::modeCreate|CFile::modeWrite))
							{
								file.Write(pBuf,nLen);
							}
							file.Close();
						}
						delete []pBuf;
					}						
				}
			}		
			break;
		case ID_MENU_DELETE:
			{
				if (MessageBox("确认删除","提示信息",MB_YESNO)==IDYES)
				{
					CFile::Remove(strOrgPath);
					m_ListCtrlFileName.DeleteItem(nItem);
				}
			}		
			break;
		default: break;
		}
	}	
	*pResult = 0;
}


void CShowProcedure::OnTrainChar() 
{	
	CString strOutPath;
	strOutPath.Format("%sAnnChar1.ann",GetAppPath());
	CString strListChar = "ABCDEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[0].SetFeaType(0);
	m_RecBaseCharInt[0].Train(strOutPath,strListChar,nPerNum);
	/*	
		CString strPath;
		strPath.Format("%sannChar.ann",GetAppPath());
		m_BpNet.TrainChar(strPath);*/
	
}

void CShowProcedure::OnButtonCdgo() 
{
	CString strPath;
	strPath.Format("%sannCDG0.ann",GetAppPath());
	m_BpNet.TrainSimilar(strPath,SIMILAR_CDG0);
}

void CShowProcedure::OnButtonA4() 
{	
	CString strPath;
	strPath.Format("%sannA4.ann",GetAppPath());
	m_BpNet.TrainSimilar(strPath,SIMILAR_A4);
}

void CShowProcedure::OnButton7t() 
{	
	CString strPath;
	strPath.Format("%sann7T.ann",GetAppPath());
	m_BpNet.TrainSimilar(strPath,SIMILAR_7T);
}

void CShowProcedure::OnButtonPr8() 
{
	CString strPath;
	strPath.Format("%sannPR89.ann",GetAppPath());
	m_BpNet.TrainSimilar(strPath,SIMILAR_PR89);
}

void CShowProcedure::OnButtonNum1() 
{
	CString strPath;
	strPath.Format("%sannInt1.ann",GetAppPath());
	m_BpNet.TrainInt1(strPath);
}
static int nN = 0;
BOOL CShowProcedure::Run(CImage &ImgIn,char *cResult)
{
	nN++;
	CString strPath;
	strPath.Format("%s\\org\\%d.bmp",GetAppPath(),nN);
	ImgIn.SaveBMP(strPath);
	m_ImgOrg = ImgIn;
	m_ImgAfterCut.Detroy();
	m_ImgGray.Detroy();
	m_ImgTwo.Detroy();
	m_ImgLocation.Detroy();
	m_ImgChePai.Detroy();
	m_ImgTextPic.Detroy();
	m_strResult = "";
	
	//剪图
	BOOL m_bBlackText=FALSE;

	int nCutLineNum = (ImgIn.GetWidth()==320)?0:0;
	CRect rcRealNeed = CRect(0,0,m_ImgOrg.GetWidth(),m_ImgOrg.GetHeight()-nCutLineNum);
	if (!m_ImgOrg.CutFromImg(m_ImgAfterCut,rcRealNeed))
	{
		m_strColorType = m_ImgAfterCut.GetColorType(m_bBlackText);
		InvalidateRect(NULL);
		return FALSE;
	}
	
	//转化为灰度图象
	if (!m_ImgAfterCut.Rgb2Gray(m_ImgGray,0.30,0.59,0.11)) 
	{
		InvalidateRect(NULL);
		return FALSE;
	}	
//	m_ImgGray.HistogramEqualization();
	//求垂直梯度
    //CImage imgTemp;
	if (!m_ImgGray.Grad1(m_ImgTwo))
	{
		InvalidateRect(NULL);
		return FALSE;
	}
	//根据梯度将灰度图转化为二值化图
	
	strPath.Format("%sconfig.sys",GetAppPath());
	int nTh =GetPrivateProfileInt("ParaSet","Grad",25,strPath);
	CImage imgTemp,imgTemp2;
	imgTemp2 = m_ImgTwo;
	if (!m_ImgTwo.Threthold(imgTemp,nTh))
	{
		InvalidateRect(NULL);
		return FALSE;
	}
	m_ImgTwo = imgTemp;
	
	//求出车牌位置
	CList<CRect,CRect> rcChePaiList;
	CRect rcChePai;
	if (!imgTemp.GetChePaiRect(m_ImgLocation,m_ImgGray,rcChePaiList)) 
	{
		//根据梯度将灰度图转化为二值化图
		int nTh = 30;
		if (!imgTemp2.Threthold(imgTemp,nTh))
		{
			InvalidateRect(NULL);
			return FALSE;
		}
		m_ImgTwo = imgTemp;
		
		if (!imgTemp.GetChePaiRect(m_ImgLocation,m_ImgGray,rcChePaiList)) 
		{
			InvalidateRect(NULL);
			return FALSE;
		}		
	}
	//判断哪个区域是车牌,并且剪切车牌
	rcChePai = rcChePaiList.GetTail();
	if (!m_ImgGray.CutFromImg(m_ImgChePai,rcChePai)) 
	{
		InvalidateRect(NULL);
		return FALSE;
	}
	
	m_TextImgList.RemoveAll();
	if (!m_ImgChePai.CutText(m_TextImgList,m_bBlackText))
	{
		InvalidateRect(NULL);
		return FALSE;		
	}
	if (m_TextImgList.GetCount()<1) {
		InvalidateRect(NULL);
		return FALSE;
	}

	m_strResult = RecChar(m_TextImgList);

	POSITION pos = m_TextImgList.GetHeadPosition();
	int nCount = m_TextImgList.GetCount();
	m_ImgTextPic.Create(CSize(34*nCount,64),FALSE);
	int nTop = 0;
	COleDateTime time = COleDateTime::GetCurrentTime();
	while (pos)
	{
		CImage imgTemp = m_TextImgList.GetNext(pos);		
		imgTemp.Stretch(CSize(32,64));	

		if (m_bExample)
		{
			strPath.Format("%sExaple\\%s%d.bmp",
				GetAppPath(),TimeToString(COleDateTime::GetCurrentTime()),rand());
			imgTemp.SaveBMP(strPath);
		}
		
		for(int i=0;i<64;i++)
		{
			for(int j=0;j<32;j++)
			{
				m_ImgTextPic.m_pR[m_ImgTextPic.GetWidth()*i+j+nTop*34] = 
					imgTemp.m_pR[imgTemp.GetWidth()*i+j];
			}
		}
		nTop++;
	}
	InvalidateRect(NULL);
	UpdateData(FALSE);
	strcpy(cResult,m_strResult);
	return TRUE;
}

void CShowProcedure::OnButtonChar3() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnChar3.ann",GetAppPath());
	CString strListChar = "ABCDEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[2].SetFeaType(3);
	m_RecBaseCharInt[2].Train(strOutPath,strListChar,nPerNum);

/*
	CString strOutPath;
	strOutPath.Format("%sAnnChar3.ann",GetAppPath());
	CString strListChar = "ABCDEFGHJKLMNPRSUVY";
	int nPerNum = 200;
	m_RecBaseChar3.SetFeaType(2);
	m_RecBaseChar3.Train(strOutPath,strListChar,nPerNum);
*/
}

void CShowProcedure::OnButtonInt3() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnInt3.ann",GetAppPath());
	CString strListChar = "0123456789";
	int nPerNum = 200;
	m_RecBaseInt3.SetFeaType(3);
	m_RecBaseInt3.Train(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnButtonCharAndInt() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnCharInt3.ann",GetAppPath());
	CString strListChar = "012345679ABCEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[2].SetFeaType(3);
	m_RecBaseCharInt[2].Train(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnBUTTONCharInt1() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnCharInt1.ann",GetAppPath());
	CString strListChar = "012345679ABCEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[0].SetFeaType(0);
	m_RecBaseCharInt[0].Train(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnBUTTONCharInt2() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnCharInt2.ann",GetAppPath());
	CString strListChar = "012345679ABCEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[1].SetFeaType(1);
	m_RecBaseCharInt[1].Train(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnButtonGetError() 
{
	// TODO: Add your control notification handler code here
	m_dError = m_BpNet.m_BpNetChar.GetError();
	CString strText;
	strText.Format("%.6f",m_dError);
	GetDlgItem(IDC_EDIT_ERROR)->SetWindowText(strText);
//	UpdateData(FALSE);
}

void CShowProcedure::OnReverseclr() 
{
	// TODO: Add your control notification handler code here

/*	BOOL m_bBlackText=TRUE;
	CString strPath;
	if(m_strColorType=="黄")
	{
		m_bBlackText = FALSE;
	}
	else if(m_strColorType=="蓝")
	{
		m_bBlackText = TRUE;
	}
	CImage Temp2 = m_ImgChePai;
	//m_ImgChePai.ShowImg();
    CSegmentationByProjection Segment;
	m_TextImgList.RemoveAll();
	if (!Segment.Segment(m_TextImgList,rcChePai,m_ImgGray,m_bBlackText))
	{
		InvalidateRect(NULL);
		return;		
	}
	m_ImgChePai = Temp2;
	if (m_TextImgList.GetCount()<1) {
		InvalidateRect(NULL);
		return;
	}
	
	m_strResult = RecChar(m_TextImgList);
	
	POSITION pos = m_TextImgList.GetHeadPosition();
	int nCount = m_TextImgList.GetCount();
	m_ImgTextPic.Create(CSize(34*nCount,64),FALSE);
	int nTop = 0;
	COleDateTime time = COleDateTime::GetCurrentTime();
	while (pos)
	{
		CImage imgTemp = m_TextImgList.GetNext(pos);		
		imgTemp.Stretch(CSize(32,64));	
		
		if (m_bExample)
		{
			strPath.Format("%sExaple\\%s%d.bmp",
				GetAppPath(),TimeToString(COleDateTime::GetCurrentTime()),rand());
			imgTemp.SaveBMP(strPath);
		}
		
		for(int i=0;i<64;i++)
		{
			for(int j=0;j<32;j++)
			{
				m_ImgTextPic.m_pR[m_ImgTextPic.GetWidth()*i+j+nTop*34] = 
					imgTemp.m_pR[imgTemp.GetWidth()*i+j];
			}
		}
		nTop++;
	}
	InvalidateRect(NULL);
	UpdateData(FALSE);
	return;*/
}
void CShowProcedure::OnButtonChar1() 
{
	CString strOutPath;
	strOutPath.Format("%sAnnChar2.ann",GetAppPath());
	CString strListChar = "ABCDEFGHJKLMNPRSUVY";
	int nPerNum = 100;
	m_RecBaseCharInt[1].SetFeaType(1);
	m_RecBaseCharInt[1].Train(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnButtonChinese1() 
{
	CString strOutPath;
	strOutPath.Format("%sChinese1.ann",GetAppPath());
	CString strListChar = "012";
	int nPerNum = 50;
	m_RecBaseChinese[0].SetFeaType(0);
	m_RecBaseChinese[0].TrainChinese(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnButtonChinese2() 
{
	CString strOutPath;
	strOutPath.Format("%sChinese2.ann",GetAppPath());
	CString strListChar = "012";
	int nPerNum = 50;
	m_RecBaseChinese[1].SetFeaType(1);
	m_RecBaseChinese[1].TrainChinese(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnButtonChinese3() 
{
	CString strOutPath;
	strOutPath.Format("%sChinese3.ann",GetAppPath());
	CString strListChar = "012";
	int nPerNum = 50;
	m_RecBaseChinese[2].SetFeaType(2);
	m_RecBaseChinese[2].TrainChinese(strOutPath,strListChar,nPerNum);
}

void CShowProcedure::OnCheckExample() 
{
	// TODO: Add your control notification handler code here
	
}

⌨️ 快捷键说明

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