/// <summary> /// 通过图片文件识别车牌号 /// </summary> public PlateRecognitionResult Recognize(string path) { int nWidth = 0; int nHeight = 0; PlateRecognitionResult result = new PlateRecognitionResult(); try { if (_Inited) { TH_PlateResult[] pRes = new TH_PlateResult[3]; int RetNum = 1; byte[] pBuffer = LockUnlockBitsExample(path, out nHeight, out nWidth); TH_RECT rect = new TH_RECT(); rect.top = 0; rect.bottom = nHeight; rect.left = 0; rect.right = nWidth; int nResult = -1; lock (_Locker) { nResult = TH_RecogImage(pBuffer, nWidth, nHeight, pRes, ref RetNum, ref rect, ref c_defConfig); } if (nResult == 0) { result.CarPlate = PlateLicense(pRes[0].lic0, (short)pRes[0].lic1, (short)pRes[0].lic2, (short)pRes[0].lic3, (short)pRes[0].lic4);//调用车牌号码转换函数 } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(result); }
/// <summary> /// 通过图片文件识别车牌号 /// </summary> public PlateRecognitionResult Recognize(string path) { int nWidth = 0; int nHeight = 0; PlateRecognitionResult result = new PlateRecognitionResult(); try { if (_Inited) { TH_PlateResult[] pRes = new TH_PlateResult[3]; int RetNum = 1; byte[] pBuffer = LockUnlockBitsExample(path, out nHeight, out nWidth); TH_RECT rect = new TH_RECT(); rect.top = 0; rect.bottom = nHeight; rect.left = 0; rect.right = nWidth; int nResult = -1; lock (_Locker) { nResult = TH_RecogImage(pBuffer, nWidth, nHeight, pRes, ref RetNum, ref rect, ref c_defConfig); } if (nResult == 0) { //以下是就版本的结构体转换车牌,使用该结构体转换得到的车牌,如果车牌后包括“港”、“警”等汉字的,转换后会变成“?” //result.CarPlate = PlateLicense(pRes[0].lic0, pRes[0].lic1, pRes[0].lic2, pRes[0].lic3);//调用车牌号码转换函数 //车牌号码转换 Encoding gbkencoding = Encoding.GetEncoding("gbk"); byte[] unicodebuf = Encoding.Convert(gbkencoding, Encoding.Unicode, pRes[0].license); string carplate = Encoding.Unicode.GetString(unicodebuf, 0, unicodebuf.Length); result.CarPlate = carplate.Trim('\0');//去掉结尾的\0符 } } } catch (Exception ex) { Ralid.GeneralLibrary.ExceptionHandling.ExceptionPolicy.HandleException(ex); } return(result); }
[DllImport("TH_PLATEID.dll")] /// 识别车牌号码 static extern int TH_RecogImage(byte[] pbyBits, int nWidth, int nHeight, [In, Out] TH_PlateResult[] pResult, ref int nResultNum, ref TH_RECT prcRange, ref TH_PlateIDCfg pPlateConfig);