mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 06:46:53 +08:00
Update detectormorph.cpp
cosmetic fixes
This commit is contained in:
@@ -77,18 +77,18 @@ namespace alpr {
|
|||||||
|
|
||||||
Mat diamond(5, 5, CV_8U, cv::Scalar(1));
|
Mat diamond(5, 5, CV_8U, cv::Scalar(1));
|
||||||
|
|
||||||
diamond.at<uchar>(0, 0) = 0;
|
diamond.at<uchar>(0, 0) = 0;
|
||||||
diamond.at<uchar>(0, 1) = 0;
|
diamond.at<uchar>(0, 1) = 0;
|
||||||
diamond.at<uchar>(1, 0) = 0;
|
diamond.at<uchar>(1, 0) = 0;
|
||||||
diamond.at<uchar>(4, 4) = 0;
|
diamond.at<uchar>(4, 4) = 0;
|
||||||
diamond.at<uchar>(3, 4) = 0;
|
diamond.at<uchar>(3, 4) = 0;
|
||||||
diamond.at<uchar>(4, 3) = 0;
|
diamond.at<uchar>(4, 3) = 0;
|
||||||
diamond.at<uchar>(4, 0) = 0;
|
diamond.at<uchar>(4, 0) = 0;
|
||||||
diamond.at<uchar>(4, 1) = 0;
|
diamond.at<uchar>(4, 1) = 0;
|
||||||
diamond.at<uchar>(3, 0) = 0;
|
diamond.at<uchar>(3, 0) = 0;
|
||||||
diamond.at<uchar>(0, 4) = 0;
|
diamond.at<uchar>(0, 4) = 0;
|
||||||
diamond.at<uchar>(0, 3) = 0;
|
diamond.at<uchar>(0, 3) = 0;
|
||||||
diamond.at<uchar>(1, 4) = 0;
|
diamond.at<uchar>(1, 4) = 0;
|
||||||
|
|
||||||
morphologyEx(img_threshold, img_open2, CV_MOP_OPEN, diamond, cv::Point(-1, -1));
|
morphologyEx(img_threshold, img_open2, CV_MOP_OPEN, diamond, cv::Point(-1, -1));
|
||||||
Mat rectElement = getStructuringElement(cv::MORPH_RECT, Size(13, 4));
|
Mat rectElement = getStructuringElement(cv::MORPH_RECT, Size(13, 4));
|
||||||
@@ -129,67 +129,65 @@ namespace alpr {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//Now prunning based on checking all candidate plates for a min/max number of blobsc
|
//Now prunning based on checking all candidate plates for a min/max number of blobsc
|
||||||
Mat img_crop, img_crop_b, img_crop_th, img_crop_th_inv;
|
Mat img_crop, img_crop_b, img_crop_th, img_crop_th_inv;
|
||||||
vector< vector< Point> > plateBlobs;
|
vector< vector< Point> > plateBlobs;
|
||||||
vector< vector< Point> > plateBlobsInv;
|
vector< vector< Point> > plateBlobsInv;
|
||||||
double thresholds[] = { 10, 40, 80, 120, 160, 200, 240 };
|
double thresholds[] = { 10, 40, 80, 120, 160, 200, 240 };
|
||||||
const int num_thresholds = 7;
|
const int num_thresholds = 7;
|
||||||
int numValidChars = 0;
|
int numValidChars = 0;
|
||||||
Mat rotated;
|
Mat rotated;
|
||||||
for (int i = 0; i < rects.size(); i++) {
|
for (int i = 0; i < rects.size(); i++) {
|
||||||
RotatedRect PlateRect = rects[i];
|
RotatedRect PlateRect = rects[i];
|
||||||
Size rect_size = PlateRect.size;
|
Size rect_size = PlateRect.size;
|
||||||
|
|
||||||
// get the rotation matrix
|
// get the rotation matrix
|
||||||
Mat M = getRotationMatrix2D(PlateRect.center, PlateRect.angle, 1.0);
|
Mat M = getRotationMatrix2D(PlateRect.center, PlateRect.angle, 1.0);
|
||||||
// perform the affine transformation
|
// perform the affine transformation
|
||||||
warpAffine(frame_gray_cp, rotated, M, frame_gray_cp.size(), INTER_CUBIC);
|
warpAffine(frame_gray_cp, rotated, M, frame_gray_cp.size(), INTER_CUBIC);
|
||||||
//Crop area around candidate plate
|
//Crop area around candidate plate
|
||||||
getRectSubPix(rotated, rect_size, PlateRect.center, img_crop);
|
getRectSubPix(rotated, rect_size, PlateRect.center, img_crop);
|
||||||
|
|
||||||
if (config->debugDetector && config->debugShowImages) {
|
if (config->debugDetector && config->debugShowImages) {
|
||||||
imshow("Tilt Correction", img_crop);
|
imshow("Tilt Correction", img_crop);
|
||||||
waitKey(0);
|
waitKey(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int z = 0; z < num_thresholds; z++)
|
for (int z = 0; z < num_thresholds; z++) {
|
||||||
{
|
|
||||||
|
|
||||||
cv::threshold(img_crop, img_crop_th, thresholds[z], 255, cv::THRESH_BINARY);
|
cv::threshold(img_crop, img_crop_th, thresholds[z], 255, cv::THRESH_BINARY);
|
||||||
cv::threshold(img_crop, img_crop_th_inv, thresholds[z], 255, cv::THRESH_BINARY_INV);
|
cv::threshold(img_crop, img_crop_th_inv, thresholds[z], 255, cv::THRESH_BINARY_INV);
|
||||||
|
|
||||||
findContours(img_crop_th,
|
findContours(img_crop_th,
|
||||||
plateBlobs, // a vector of contours
|
plateBlobs, // a vector of contours
|
||||||
CV_RETR_LIST, // retrieve the contour list
|
CV_RETR_LIST, // retrieve the contour list
|
||||||
CV_CHAIN_APPROX_NONE); // all pixels of each contours
|
CV_CHAIN_APPROX_NONE); // all pixels of each contours
|
||||||
|
|
||||||
findContours(img_crop_th_inv,
|
findContours(img_crop_th_inv,
|
||||||
plateBlobsInv, // a vector of contours
|
plateBlobsInv, // a vector of contours
|
||||||
CV_RETR_LIST, // retrieve the contour list
|
CV_RETR_LIST, // retrieve the contour list
|
||||||
CV_CHAIN_APPROX_NONE); // all pixels of each contours
|
CV_CHAIN_APPROX_NONE); // all pixels of each contours
|
||||||
|
|
||||||
int numBlobs = plateBlobs.size();
|
int numBlobs = plateBlobs.size();
|
||||||
int numBlobsInv = plateBlobsInv.size();
|
int numBlobsInv = plateBlobsInv.size();
|
||||||
|
|
||||||
float idealAspect = config->charWidthMM / config->charHeightMM;
|
float idealAspect = config->charWidthMM / config->charHeightMM;
|
||||||
for (int j = 0; j < numBlobs; j++) {
|
for (int j = 0; j < numBlobs; j++) {
|
||||||
cv::Rect r0 = cv::boundingRect(cv::Mat(plateBlobs[j]));
|
cv::Rect r0 = cv::boundingRect(cv::Mat(plateBlobs[j]));
|
||||||
|
|
||||||
if (ValidateCharAspect(r0, idealAspect))
|
if (ValidateCharAspect(r0, idealAspect))
|
||||||
numValidChars++;
|
numValidChars++;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int j = 0; j < numBlobsInv; j++)
|
for (int j = 0; j < numBlobsInv; j++) {
|
||||||
{
|
cv::Rect r0 = cv::boundingRect(cv::Mat(plateBlobsInv[j]));
|
||||||
cv::Rect r0 = cv::boundingRect(cv::Mat(plateBlobsInv[j]));
|
if (ValidateCharAspect(r0, idealAspect))
|
||||||
if (ValidateCharAspect(r0, idealAspect))
|
numValidChars++;
|
||||||
numValidChars++;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
//If too much or too lcittle might not be a true plate
|
//If too much or too lcittle might not be a true plate
|
||||||
//if (numBlobs < 3 || numBlobs > 50) continue;
|
//if (numBlobs < 3 || numBlobs > 50) continue;
|
||||||
if (numValidChars < 4 || numValidChars > 50) continue;
|
if (numValidChars < 4 || numValidChars > 50) continue;
|
||||||
|
|
||||||
PlateRegion PlateReg;
|
PlateRegion PlateReg;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user