改善 OCR 结果
Improve OCR result
我正在从事基于视频车牌检测的项目。
这是它的样子:
当我想在车牌上使用 OCR 时,我的问题就出现了。我在一些图片上对其进行了测试,效果非常好。这是一些例子:
但是当我把我检测到的盘子放上去的时候结果很糟糕:
所以我想问你是否有一些关于如何改进 OCR 结果的建议?
这是我如何获得二值图像的方法:
cv::Mat equalized;
cv::equalizeHist(gray, equalized);
cv::imshow("Hist. Eq.", equalized);
/* Bilateral filter helps to improve the segmentation process */
cv::Mat blur;
cv::bilateralFilter(equalized, blur, 9, 75, 75);
cv::imshow("Filter", blur);
/* Threshold to binarize the image */
cv::Mat thres;
cv::adaptiveThreshold(blur, thres, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 15, 2); //15, 2
cv::imshow("Threshold", thres);
也许还有一些过滤器?如果有帮助,我可以放更多代码。
我的第一个想法是让我的盘子变大一点。
以下是我如何使用我的矩形获取矢量:
std::vector< std::vector< cv::Point> > LP_contours;
cv::findContours(img_threshold, LP_contours, 0, 1);
std::vector<std::vector<cv::Point> > contours_poly(LP_contours.size());
for (int ii = 0; ii < LP_contours.size(); ii++)
if (LP_contours[ii].size() > 100 && contourArea(LP_contours[ii]) > 3000 && contourArea(LP_contours[ii]) < 10000)
{
cv::approxPolyDP(cv::Mat(LP_contours[ii]), contours_poly[ii], 3, true);
cv::Rect appRect(boundingRect(cv::Mat(contours_poly[ii])));
if (appRect.width > appRect.height && appRect.width>160 && appRect.width < 190 && appRect.height>40 && appRect.height < 60)
boundRect.push_back(appRect);
}
我想通过简单的代码改变 appRect 的大小:
appRect.height += 10;
appRect.width += 10;
但它不起作用。我是 openCV 的新手,我对这类员工有疑问。您有什么建议可以让矩形变大吗?
感谢您的宝贵时间和帮助。
这是一个简化的片段,您可以如何手动更改 boundRect 参数以在 openCV 中实现所需的 ROI:
int main()
{
cv::Mat image = cv::imread("car.jpg",0);
cv::Rect boundRect{ 200,164,140,25 };
cv::Mat cropped_image = image(boundRect);
cv::namedWindow("Image");
cv::imshow("Image", image);
cv::namedWindow("Original cropped Image");
cv::imshow("Original cropped Image", cropped_image);
cv::Rect new_boundRect = boundRect;
new_boundRect.x += 10;
new_boundRect.y += 2;
new_boundRect.width -= 10;
new_boundRect.height -= 10;
cv::Mat new_cropped_image = image(new_boundRect);
cv::namedWindow("New cropped Image");
cv::imshow("New cropped Image", new_cropped_image);
cv::waitKey();
return 0;
}
图片:
我正在从事基于视频车牌检测的项目。
这是它的样子:
当我想在车牌上使用 OCR 时,我的问题就出现了。我在一些图片上对其进行了测试,效果非常好。这是一些例子:
但是当我把我检测到的盘子放上去的时候结果很糟糕:
所以我想问你是否有一些关于如何改进 OCR 结果的建议?
这是我如何获得二值图像的方法:
cv::Mat equalized;
cv::equalizeHist(gray, equalized);
cv::imshow("Hist. Eq.", equalized);
/* Bilateral filter helps to improve the segmentation process */
cv::Mat blur;
cv::bilateralFilter(equalized, blur, 9, 75, 75);
cv::imshow("Filter", blur);
/* Threshold to binarize the image */
cv::Mat thres;
cv::adaptiveThreshold(blur, thres, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY, 15, 2); //15, 2
cv::imshow("Threshold", thres);
也许还有一些过滤器?如果有帮助,我可以放更多代码。
我的第一个想法是让我的盘子变大一点。
以下是我如何使用我的矩形获取矢量:
std::vector< std::vector< cv::Point> > LP_contours;
cv::findContours(img_threshold, LP_contours, 0, 1);
std::vector<std::vector<cv::Point> > contours_poly(LP_contours.size());
for (int ii = 0; ii < LP_contours.size(); ii++)
if (LP_contours[ii].size() > 100 && contourArea(LP_contours[ii]) > 3000 && contourArea(LP_contours[ii]) < 10000)
{
cv::approxPolyDP(cv::Mat(LP_contours[ii]), contours_poly[ii], 3, true);
cv::Rect appRect(boundingRect(cv::Mat(contours_poly[ii])));
if (appRect.width > appRect.height && appRect.width>160 && appRect.width < 190 && appRect.height>40 && appRect.height < 60)
boundRect.push_back(appRect);
}
我想通过简单的代码改变 appRect 的大小:
appRect.height += 10;
appRect.width += 10;
但它不起作用。我是 openCV 的新手,我对这类员工有疑问。您有什么建议可以让矩形变大吗?
感谢您的宝贵时间和帮助。
这是一个简化的片段,您可以如何手动更改 boundRect 参数以在 openCV 中实现所需的 ROI:
int main()
{
cv::Mat image = cv::imread("car.jpg",0);
cv::Rect boundRect{ 200,164,140,25 };
cv::Mat cropped_image = image(boundRect);
cv::namedWindow("Image");
cv::imshow("Image", image);
cv::namedWindow("Original cropped Image");
cv::imshow("Original cropped Image", cropped_image);
cv::Rect new_boundRect = boundRect;
new_boundRect.x += 10;
new_boundRect.y += 2;
new_boundRect.width -= 10;
new_boundRect.height -= 10;
cv::Mat new_cropped_image = image(new_boundRect);
cv::namedWindow("New cropped Image");
cv::imshow("New cropped Image", new_cropped_image);
cv::waitKey();
return 0;
}
图片: