Qt 车牌识别 (EasyPR)
生活随笔
收集整理的这篇文章主要介绍了
Qt 车牌识别 (EasyPR)
小编觉得挺不错的,现在分享给大家,帮大家做个参考.
EasyPR
- 下载
- 直接把源码加到.pri文件中
- 安装/直接解压 opencv-3.2.0-vc14.exe
- 使用
- 最终效果
- Qt 车牌识别 (HyperLPR)
开发环境:win10 + Qt5.12.1 + vs2015_x64
下载
EasyPR源码下载链接:https://github.com/liuruoze/EasyPR
笔者下载的v1.6版本 (这个库最后维护是2018年好像)
因为没有训练绿牌,所以无法识别,需要自己训练,它提供了训练函数
如何添加绿牌:https://blog.csdn.net/h593245631/article/details/107185418
直接把源码加到.pri文件中
安装/直接解压 opencv-3.2.0-vc14.exe
下载:https://nchc.dl.sourceforge.net/project/opencvlibrary/opencv-win/3.2.0/opencv-3.2.0-vc14.exe
使用
void EasyPRThread::run() {setResult(0);switch (threadType()) {case 0://initinit();break;case 1:{QImage image;QString tag;extractFacialFeatures(getFilePath(),image,tag);setImage(image);setTag(tag);}break;case 2:{easypr::SvmTrain svm("tmp/train/svm", "tmp/train/svm.xml");svm.train();}break;case 3:{easypr::AnnTrain ann("tmp/train/ann", "tmp/train/ann.xml");ann.train();}break;case 4:{int sameCount = 0;int errorCount = 0;for(int i=0; i<_filePaths.size(); ++i){QImage image;QString tag;extractFacialFeatures(_filePaths.at(i),image,tag);setImage(image);setTag(tag);QFileInfo fileInfo(_filePaths.at(i));if(fileInfo.completeBaseName() == tag){++sameCount;}else{++errorCount;}}QString str = QString("%1:%2 %3:%4 %5:%6 %7:%8").arg(QStringLiteral("共")).arg(_filePaths.size()).arg(QStringLiteral("正确")).arg(sameCount).arg(QStringLiteral("错误")).arg(errorCount).arg(QStringLiteral("识别率")).arg(sameCount*1.0/_filePaths.size());SCDebug<<str;emit sigTextEdit(str);}break;default:break;} } bool EasyPRThread::extractFacialFeatures(const QString &filePath,QImage &image,QString &tag) {image.load(filePath);int result = 0;// cv::Mat src = imread(filePath.toLocal8Bit().toStdString());// // 切割车牌图片// vector<CPlate> resultVec;// CPlateDetect pd;// pd.setPDLifemode(true);// result = pd.plateDetect(src, resultVec);// size_t num = resultVec.size();// SCDebug<<"result:"<<result<<num;// for (size_t j = 0; j < num; j++) {// CPlate resultMat = resultVec[j];// std::string license = resultMat.getPlateStr();// QString lice1 = QString::fromLocal8Bit(license.c_str());// SCDebug<<"j:"<<lice1;// imshow("plate_detect", resultMat.getPlateMat());// waitKey(0);// }CPlateRecognize pr;//CMER代表文字定位方法,SOBEL和COLOR分别代表边缘和颜色定位方法。可以通过"|"符号结合// pr.setDetectType(PR_DETECT_SOBEL);// pr.setDetectType(PR_DETECT_CMSER);// pr.setDetectType(PR_DETECT_COLOR);// pr.setDetectType(PR_DETECT_CMSER | PR_DETECT_COLOR);pr.setDetectType(PR_DETECT_COLOR | PR_DETECT_SOBEL | PR_DETECT_CMSER);//开启生活模式,这个属性在定位方法为SOBEL时可以发挥作用,能增大搜索范围,提高鲁棒性。pr.setLifemode(true);// //设置EasyPR最多查找多少个车牌。当一副图中有大于n个车牌时,EasyPR最终只会输出可能性最高的n个。pr.setMaxPlates(1);std::vector<CPlate>plateVec;cv::Mat src = imread(filePath.toLocal8Bit().toStdString());pr.setResultShow(false);result = pr.plateRecognize(src,plateVec);SCDebug<<"result:"<<result<<plateVec.size();// pr.getResultShow();QPainter painter(&image);for(int i=0; i<plateVec.size(); ++i){CPlate plate = plateVec.at(i);//plateMat代表车牌图像,rrect代表车牌的可旋转矩形位置,license代表车牌字符串,例如“蓝牌:苏EUK722”。// Mat plateMat = plate.getPlateMat();RotatedRect rrect = plate.getPlatePos();painter.setPen(QPen(Qt::magenta, 2, Qt::DashDotLine));painter.drawRect(rrect.boundingRect().x,rrect.boundingRect().y,rrect.boundingRect().width,rrect.boundingRect().height);std::string license = plate.getPlateStr();QString lice1 = QString::fromLocal8Bit(license.data());lice1 = getLicensePlateType(lice1,tag);qDebug()<<i<<"revStr:"<<lice1;emit sigTextEdit(lice1);}return true; }最终效果
测试它源码中自带的 general_test 文件夹中的车牌图片识别率只有:0.47(47%)
Qt 车牌识别 (HyperLPR)
https://blog.csdn.net/u012020854/article/details/111202952
总结
以上是生活随笔为你收集整理的Qt 车牌识别 (EasyPR)的全部内容,希望文章能够帮你解决所遇到的问题。
- 上一篇: 构建iOS风格移动Web应用程序的8款开
- 下一篇: jrtplib使用注意事项