Qt 车牌识别 (HyperLPR)
void EasyPRThread::run()
{
setResult(0);
switch (threadType()) {
case 0://init
init();
break;
case 1:
{
QImage image;
QString tag;
extractFacialFeatures(getFilePath(),image,tag);
setImage(image);
setTag(tag);
}
break;
case 2:
{
}
break;
case 3:
{
}
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)
{
cv::Mat frame = cv::imread(filePath.toLocal8Bit().toStdString());
std::vector<pr::PlateInfo> res = _pipelinePR->RunPiplineAsImage(frame,pr::SEGMENTATION_FREE_METHOD);
int count = 0;
for(auto st:res) {
if(st.confidence > _threshold) {
++count;
cv::Rect region = st.getPlateRect();
cv::rectangle(frame,cv::Point(region.x,region.y),cv::Point(region.x+region.width,region.y+region.height),cv::Scalar(255,255,0),2);
tag = QString::fromLocal8Bit(st.getPlateName().data());
// int type = ();
// SCDebug<<"type:"<<type;
// QString tempStr = QString("%1:%2").arg(getLicensePlateType(())).arg(tag);
emit sigTextEdit(tag);
}
SCDebug<<":"<<st.confidence;
}
// SCDebug<<"count:"<<count;
image = QImage((const unsigned char*)(frame.data), frame.cols, frame.rows, frame.step, QImage::Format_RGB888).rgbSwapped();
return true;
}