You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
EasyPR/src/core/plate_detect.cpp

120 lines
3.3 KiB

#include "easypr/core/plate_detect.h"
#include "easypr/util/util.h"
11 years ago
namespace easypr {
10 years ago
CPlateDetect::CPlateDetect() {
m_plateLocate = new CPlateLocate();
// Ĭ<><C4AC>EasyPR<50><52>һ<EFBFBD><D2BB>ͼ<EFBFBD>ж<EFBFBD>λ<EFBFBD><CEBB><EFBFBD><EFBFBD>3<EFBFBD><33><EFBFBD><EFBFBD>
11 years ago
m_maxPlates = 3;
}
CPlateDetect::~CPlateDetect() { SAFE_RELEASE(m_plateLocate); }
int CPlateDetect::plateDetect(Mat src, std::vector<CPlate> &resultVec, int type,
bool showDetectArea, int index) {
std::vector<CPlate> color_Plates;
std::vector<CPlate> sobel_Plates;
std::vector<CPlate> all_result_Plates;
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ɫ<EFBFBD><C9AB><EFBFBD><EFBFBD><EFBFBD>ҵ<EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD>ϣ<EFBFBD><CFA3><EFBFBD><EFBFBD><EFBFBD>n<EFBFBD><6E><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><C4B3>ƣ<EFBFBD><C6A3>Ͳ<EFBFBD><CDB2>ٽ<EFBFBD><D9BD><EFBFBD>Sobel<65><6C><EFBFBD><EFBFBD><EFBFBD>ˡ<EFBFBD>
const int color_find_max = m_maxPlates;
if ( !type || type & PR_DETECT_SOBEL)
{
m_plateLocate->plateSobelLocate(src, sobel_Plates, index);
std::vector<CPlate>& sobel_result_Plates = sobel_Plates;
for (size_t i = 0; i < sobel_result_Plates.size(); i++)
{
CPlate plate = sobel_result_Plates[i];
plate.setPlateLocateType(SOBEL);
all_result_Plates.push_back(plate);
}
}
if ( !type || type & PR_DETECT_COLOR)
{
m_plateLocate->plateColorLocate(src, color_Plates, index);
std::vector<CPlate>& color_result_Plates = color_Plates;
10 years ago
for (size_t i = 0; i < color_result_Plates.size(); i++)
{
CPlate plate = color_result_Plates[i];
plate.setPlateLocateType(COLOR);
all_result_Plates.push_back(plate);
}
}
// ʹ<>÷Ǽ<C3B7><C7BC><EFBFBD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>жϳ<D0B6><CFB3><EFBFBD>
PlateJudge::instance()->plateJudgeUsingNMS(all_result_Plates, resultVec);
return 0;
}
int CPlateDetect::showResult(const Mat &result) {
namedWindow("EasyPR", CV_WINDOW_AUTOSIZE);
const int RESULTWIDTH = 640; // 640 930
const int RESULTHEIGHT = 540; // 540 710
Mat img_window;
img_window.create(RESULTHEIGHT, RESULTWIDTH, CV_8UC3);
int nRows = result.rows;
int nCols = result.cols;
Mat result_resize;
if (nCols <= img_window.cols && nRows <= img_window.rows) {
result_resize = result;
}
else if (nCols > img_window.cols && nRows <= img_window.rows) {
float scale = float(img_window.cols) / float(nCols);
resize(result, result_resize, Size(), scale, scale, CV_INTER_AREA);
}
else if (nCols <= img_window.cols && nRows > img_window.rows) {
float scale = float(img_window.rows) / float(nRows);
resize(result, result_resize, Size(), scale, scale, CV_INTER_AREA);
}
else if (nCols > img_window.cols && nRows > img_window.rows) {
Mat result_middle;
float scale = float(img_window.cols) / float(nCols);
resize(result, result_middle, Size(), scale, scale, CV_INTER_AREA);
if (result_middle.rows > img_window.rows) {
float scale = float(img_window.rows) / float(result_middle.rows);
resize(result_middle, result_resize, Size(), scale, scale, CV_INTER_AREA);
}
else {
result_resize = result_middle;
}
}
else {
result_resize = result;
}
Mat imageRoi = img_window(Rect((RESULTWIDTH - result_resize.cols) / 2,
(RESULTHEIGHT - result_resize.rows) / 2,
result_resize.cols, result_resize.rows));
addWeighted(imageRoi, 0, result_resize, 1, 0, imageRoi);
imshow("EasyPR", img_window);
waitKey();
destroyWindow("EasyPR");
return 0;
}
}