L
lanxy
Unregistered / Unconfirmed
GUEST, unregistred user!
#include "windows.h"<br>#include <conio.h><br>#include <time.h><br>#include <stdio.h><br>enum { ESC = 0x1B }; <br><br>/* 车牌识别模块库函数 */<br>typedef BOOL (__stdcall * CISDllInitFun)(void);<br>typedef void (__stdcall * CISDllReleaseFun)(void);<br>typedef BOOL (__stdcall * CISProcessFrameFun)(char*, int, int, int, int, char*);<br><br>/* 图像读取模块库函数 */<br>typedef BOOL (__stdcall * CISLoadImageFun)(LPSTR);<br>typedef void (__stdcall * CISGetImageFun)(char**, int*, int*, int*, int*);<br>typedef void (__stdcall * CISImageDllReleaseFun)(void);<br><br>int main(int argc, char* argv[])<br>{<br><br><br>// 是否退出循环<br>BOOL bQuit = FALSE;<br>// 起始时间<br>clock_t start;<br>start = clock();<br>// 终止时间<br>clock_t stop;<br>stop = clock();<br>// 时间差<br>double timeSpan;<br>// 累计循环数<br>int ci = 20; // for calc frame rate<br>// 最大累计数<br>double cmax = (double)ci;<br><br><br>/*------------------------------------------------------------<br>*----------------- 图 像 读 取 部 分 ------------------------<br>*-----------------------------------------------------------*/<br><br>// 图像数据指针<br>char* imageData = NULL;<br>// 图像宽度<br>int width = 0;<br>// 图像高度<br>int height = 0;<br>// 图像深度<br>int depth = 0;<br>// 图像通道数<br>int channels = 0;<br>// 图像是否读取<br>BOOL bImageLoaded = FALSE;<br><br>// 图像读取动态链接库句柄<br>HINSTANCE hImageDll; <br><br>// 图像读取函数<br>CISLoadImageFun CISLoadImage;<br>// 图像参数获取函数<br>CISGetImageFun CISGetImage;<br>// 图像读取动态链接库释放函数<br>CISImageDllReleaseFun CISImageDllRelease;<br><br>// 载入图像读取模块<br>hImageDll = LoadLibrary("D://MyCom//CISImageDll//Release//CISImage.dll"<br><br>// 如果载入成功<br>if (hImageDll != NULL)<br>{<br><br><br>// 获得图像读取函数入口<br>CISLoadImage = (CISLoadImageFun)GetProcAddress(hImageDll,"CISLoadImage"<br>// 获得图像参数获取函数入口<br>CISGetImage = (CISGetImageFun)GetProcAddress(hImageDll,"CISGetImage"<br>// 获得图像读取动态链接库释放函数入口<br>CISImageDllRelease = (CISImageDllReleaseFun)GetProcAddress(hImageDll,"CISImageDllRelease"<br><br>// 读取图像文件<br>bImageLoaded = CISLoadImage("512x384.jpg"<br>//bImageLoaded = CISLoadImage("1024x768.jpg"<br>// 720x288 为半场图像, 相应地需要修改 PlateConfigure.ini 中的参数<br>//bImageLoaded = CISLoadImage("720x288.jpg"<br><br>// 如果成功<br>if (bImageLoaded)<br>{<br><br><br>// 获得图像参数<br>CISGetImage(&imageData, &width, &height, &depth, &channels);<br><br><br>}<br><br><br>}<br>else<br>{<br><br><br>printf("The CISImage.dll can't be loaded, please check the path and name /n"<br>return 0;<br><br><br>} <br><br>/*------------------------------------------------------------<br>*----------------- 车 牌 识 别 模 块 载 入 -------------------<br>*-----------------------------------------------------------*/<br><br>// 车牌识别动态链接库句柄<br>HINSTANCE hPlateDll; <br><br>// 车牌识别模块初始化函数<br>CISDllInitFun CISDllInit;<br>// 车牌识别模块释放函数<br>CISDllReleaseFun CISDllRelease;<br>// 车牌识别模块图像处理函数<br>CISProcessFrameFun CISProcessFrame;<br><br>// 载入车牌识别模块<br>hPlateDll = LoadLibrary("D://MyCom//CubicPlateDll//Release//CubicPlate.dll"<br>// 如果载入不成功<br>if (hPlateDll == NULL)<br>{<br><br><br>printf("The CubicPlate.dll can't be loaded, please check the path and name /n"<br>return 0;<br><br><br>}<br><br>// 存放车牌识别字符<br>char pPlateChars[8];<br>// 是否发现车牌<br>BOOL bFindPlate = FALSE;<br>// 获得识别模块初始化函数入口<br>CISDllInit = (CISDllInitFun)GetProcAddress(hPlateDll,"CISDllInit" <br>// 获得识别模块释放函数入口<br>CISDllRelease = (CISDllReleaseFun)GetProcAddress(hPlateDll,"CISDllRelease" <br>// 获得识别模块图像处理函数入口<br>CISProcessFrame = (CISProcessFrameFun)GetProcAddress(hPlateDll,"CISProcessFrame" <br><br>// 如果车牌识别模块载入且图像已经读取,开始测试<br>if (hPlateDll != NULL && bImageLoaded)<br>{<br><br><br>// 识别模块初始化<br>BOOL bIniDll = CISDllInit();<br><br><br>/*---------------------------------------------------<br>*------------- 循 环 处 理 部 分 ----------------------<br>*--------------------------------------------------*/<br><br>// 如果不退出<br>while( !bQuit)<br>{<br><br><br>// 如果有键盘输入<br>if( _kbhit() )//Non-blocking<br>{<br><br><br>// 得到键盘字符 <br>char inputChar = _getch();<br><br>// 如果为ESC键<br>if(inputChar == ESC)<br>{ <br><br><br>// 退出<br>bQuit = true;<br><br><br>}<br><br><br>}<br><br>// 处理此帧图像<br>bFindPlate = CISProcessFrame(imageData, width, height, depth, channels, pPlateChars);<br><br>// 显示识别结果并计算处理速度(帧率和每帧处理时间)<br>// 由cmax的设置决定每隔多少循环输出结果<br>if (ci == (int)cmax)<br>{<br><br><br>// 如果发现车牌<br>if (bFindPlate)<br>{<br><br><br>// 输出识别结果<br>printf("%s /n",pPlateChars);<br><br><br>}<br><br>// 截至时间(以处理器时钟计)<br>stop = clock();<br>// (stop - start)/CLK_TCK 从处理器时间转换为实际秒数<br>timeSpan = double(stop - start)/CLK_TCK; <br>// 并显示处理速度(帧率和每帧处理时间)<br>printf("Performance: %4.1f fps : %2.12f spf/n", 1.0/( timeSpan / cmax), timeSpan / cmax);<br><br>// 开始时间(以处理器时钟计)<br>start = clock();<br>ci = 0;<br><br><br>}<br>ci++; <br><br><br>}<br>/*------------------- 循 环 处 理 结 束 ---------------------*/<br><br><br>}<br><br><br>// 释放车牌识别模块<br>CISDllRelease();<br>// 释放图像读取模块<br>CISImageDllRelease();<br>// 释放车牌识别模块句柄<br>FreeLibrary(hPlateDll);<br>// 释放图像读取模块句柄<br>FreeLibrary(hImageDll);<br><br><br>return 0;<br><br>}