我正在做一个基于车牌识别的学校项目。我正在简单的电影上测试它:一辆车,静态相机等。
如下所示:
我的第一步是在这个框架上找到一辆车(我认为这将有助于更多的“困难”视频):
然后我搜索车牌号。这是我的代码:
std::vector<cv::Rect> boundRect;
cv::Mat img_gray, img_sobel, img_threshold, element;
cvtColor(detectedMats[i], img_gray, CV_BGR2GRAY);
cv::Sobel(img_gray, img_sobel, CV_8U, 1, 0, 3, 1, 0, cv::BORDER_DEFAULT);
cv::threshold(img_sobel, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
element = getStructuringElement(cv::MORPH_RECT, cv::Size(30, 30));
//element = getStructuringElement(cv::MORPH_RECT, cv::Size(17, 3) );
cv::morphologyEx(img_threshold, img_threshold, CV_MOP_CLOSE, element);
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) //można się pobawić parametrami
{
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)
boundRect.push_back(appRect);
}
你可以在第二张图片上看到结果。
然后尝试得到较好的检测板轮廓。我做了几步。
也许你对如何提高成绩有一些想法?我试着改变了一些参数,但效果还是不太好。
谢谢你的帮助
所以看起来不错,但是当我尝试运行示例时,VS没有看到库:
解决:
变化
.\vcpkg install tesseract:x64-windows-static
转到
.\vcpkg install tesseract:x64-windows
而且效果很好。
发布于 2018-08-21 14:35:07
使用tesseract OCR检测文本。成功安装tesseract之后,在附加依赖项中添加tesseract305.lib和liptonica-1.74.4.lib。使用以下代码(来自教程):
#include "stdafx.h"
#include "winsock2.h"
#include <tesseract/baseapi.h>
#include <leptonica/allheaders.h>
#pragma comment(lib, "ws2_32.lib")
int main()
{
char *outText;
tesseract::TessBaseAPI *api = new tesseract::TessBaseAPI();
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api->Init(NULL, "eng")) {
fprintf(stderr, "Could not initialize tesseract.\n");
exit(1);
}
// Open input image with leptonica library
Pix *image = pixRead("test.tif");
api->SetImage(image);
// Get OCR result
outText = api->GetUTF8Text();
printf("OCR output:\n%s", outText);
// Destroy used object and release memory
api->End();
delete[] outText;
pixDestroy(&image);
return 0;
}
https://stackoverflow.com/questions/51933928
复制相似问题