www.gusucode.com > 基于C++的TRY2LPR-1.0开源车牌识别核心-源码程序 > 基于C++的TRY2LPR-1.0开源车牌识别核心-源码程序\code\Reco\Reco.cpp

    /*
* Copyright (c) 2003, try2it.com
* All rights reserved.
* Download by http://www.NewXing.com
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
* 
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
* 
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*
* 文件名称:Reco.cpp
* 文件标识:LPR-03-001
* 摘要:牌照识别的字符识别Dll
*
* 当前版本:1.0
* 作者:try2it.com
* 开始日期:2003年09月15日
* 完成日期:2003年10月10日
*/

#include "stdafx.h"
#include <stdio.h>
#include "../include/types.h"
#include "RecoHelper.h"
#include "RecoProcess.h"

#include "Reco.h"

char pPath[MAX_PATH];
TGrayImg ModelImg[35];   

BOOL APIENTRY DllMain( HANDLE hModule, 
                       DWORD  ul_reason_for_call, 
                       LPVOID lpReserved
					 )
{
	int i, res;

	switch (ul_reason_for_call)
	{
		case DLL_PROCESS_ATTACH:

			for (i=0; i<=35; i++)
			{
				if (i==1 || i==18) continue;
				
				res = LoadTemplate((HMODULE)hModule, &ModelImg[i], i);
				if (0 == res)
					return FALSE;
			}
			break;

		case DLL_THREAD_ATTACH:
			break;
		case DLL_THREAD_DETACH:
			break;
        case DLL_PROCESS_DETACH:

			FreeAllMemNode();

			break;
    }
    return TRUE;
}

RECO_API int CALLAGREEMENT GetReco(char *pLPNo, PGrayImg pLPCharImg, TLPNumType LPNumType)
{
	TGrayImg TempImg, LPCharImg;   

	int ModelID, StartID, EndID;

	int MatchNum[36];
	int MaxMatchNum;
	int CarSignID;

	int res = 1;

	*pLPNo = '?';
	if (pLPCharImg->pImg != NULL)
	{
		switch (LPNumType)
		{
		case LPNUM_CHN:    
			break;

		case LPNUM_ENNUM:  
			StartID = 0;
			EndID = 35;
			break;

		case LPNUM_NUM:    
			StartID = 0;
			EndID = 9;
			break;

		case LPNUM_EN:
			StartID = 10;
			EndID = 35;
			break;

		default:
			return 0;
		}

		ModelID = StartID;

		MaxMatchNum = 0x7FFFFFFF;

		res = GetStdImg(&LPCharImg, pLPCharImg);
		if (0 == res)
			return 0;

		if (LPCharImg.Width*1.0/LPCharImg.Height<0.25)
			CarSignID = 1;
		else
		{
			for (ModelID=StartID; ModelID<=EndID; ModelID++)
			{
				if (ModelID == 1)
					continue;  
				if (ModelID == 'I'-'A'+10)
					continue;
				
				if (LPNumType == LPNUM_ENNUM)
					if (ModelID == 'O'-'A'+10)
						continue;

				res = Zoom(&TempImg, &LPCharImg, ModelImg[ModelID].Width*1.0/LPCharImg.Width,
								 ModelImg[ModelID].Height*1.0/LPCharImg.Height);
				if (0 == res)
					return 0;

				res = ImgMatch(&MatchNum[ModelID], &TempImg, &ModelImg[ModelID]);
				if (0 == res)
					return 0;

				if (MaxMatchNum > MatchNum[ModelID])
				{
					MaxMatchNum = MatchNum[ModelID];
					CarSignID = ModelID;
				}

				res = GrayImg_Free(&TempImg);
				if (0 == res)
					return 0;
			}
		}
		
		RecoAgain(&CarSignID, &LPCharImg, MatchNum, LPNumType);

		if (CarSignID > 9)
			*pLPNo = 'A'+CarSignID-10;
		else
			*pLPNo = '0'+CarSignID;

		res = GrayImg_Free(&LPCharImg);
		if (0 == res)
			return 0;
	}

	return res;
}

RECO_API int CALLAGREEMENT SetReco()
{
	return 1;
}