mirror of
https://github.com/kerberos-io/openalpr-base.git
synced 2025-10-06 11:56:52 +08:00
Changed indents to be consistent
This commit is contained in:
@@ -22,36 +22,30 @@
|
|||||||
using namespace cv;
|
using namespace cv;
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
namespace alpr
|
namespace alpr {
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
DetectorMorph::DetectorMorph(Config* config) : Detector(config) {
|
DetectorMorph::DetectorMorph(Config* config) : Detector(config) {
|
||||||
|
|
||||||
this->loaded = true;
|
this->loaded = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
DetectorMorph::~DetectorMorph() {
|
DetectorMorph::~DetectorMorph() {
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<PlateRegion> DetectorMorph::detect(Mat frame, std::vector<cv::Rect> regionsOfInterest)
|
vector<PlateRegion> DetectorMorph::detect(Mat frame, std::vector<cv::Rect> regionsOfInterest) {
|
||||||
{
|
|
||||||
|
|
||||||
Mat frame_gray;
|
Mat frame_gray;
|
||||||
cvtColor(frame, frame_gray, CV_BGR2GRAY);
|
cvtColor(frame, frame_gray, CV_BGR2GRAY);
|
||||||
|
|
||||||
vector<PlateRegion> detectedRegions;
|
vector<PlateRegion> detectedRegions;
|
||||||
for (int i = 0; i < regionsOfInterest.size(); i++)
|
for (int i = 0; i < regionsOfInterest.size(); i++) {
|
||||||
{
|
|
||||||
Mat img_open, img_result;
|
Mat img_open, img_result;
|
||||||
Mat element = getStructuringElement(MORPH_RECT, Size(30, 4));
|
Mat element = getStructuringElement(MORPH_RECT, Size(30, 4));
|
||||||
morphologyEx(frame_gray, img_open, CV_MOP_OPEN, element, cv::Point(-1, -1));
|
morphologyEx(frame_gray, img_open, CV_MOP_OPEN, element, cv::Point(-1, -1));
|
||||||
|
|
||||||
img_result = frame_gray - img_open;
|
img_result = frame_gray - img_open;
|
||||||
|
|
||||||
if (config->debugDetector && config->debugShowImages)
|
if (config->debugDetector && config->debugShowImages) {
|
||||||
{
|
|
||||||
imshow("Opening", img_result);
|
imshow("Opening", img_result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +53,7 @@ namespace alpr
|
|||||||
Mat img_threshold, img_open2;
|
Mat img_threshold, img_open2;
|
||||||
threshold(img_result, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
|
threshold(img_result, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
|
||||||
|
|
||||||
if (config->debugDetector && config->debugShowImages)
|
if (config->debugDetector && config->debugShowImages) {
|
||||||
{
|
|
||||||
imshow("Threshold Detector", img_threshold);
|
imshow("Threshold Detector", img_threshold);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -69,8 +62,7 @@ namespace alpr
|
|||||||
Mat rectElement = getStructuringElement(cv::MORPH_RECT, Size(20, 4));
|
Mat rectElement = getStructuringElement(cv::MORPH_RECT, Size(20, 4));
|
||||||
morphologyEx(img_open2, img_threshold, CV_MOP_CLOSE, rectElement, cv::Point(-1, -1));
|
morphologyEx(img_open2, img_threshold, CV_MOP_CLOSE, rectElement, cv::Point(-1, -1));
|
||||||
|
|
||||||
if (config->debugDetector && config->debugShowImages)
|
if (config->debugDetector && config->debugShowImages) {
|
||||||
{
|
|
||||||
imshow("Close", img_threshold);
|
imshow("Close", img_threshold);
|
||||||
waitKey(0);
|
waitKey(0);
|
||||||
}
|
}
|
||||||
@@ -87,14 +79,12 @@ namespace alpr
|
|||||||
vector<RotatedRect> rects;
|
vector<RotatedRect> rects;
|
||||||
|
|
||||||
//Remove patch that are no inside limits of aspect ratio and area.
|
//Remove patch that are no inside limits of aspect ratio and area.
|
||||||
while (itc != contours.end())
|
while (itc != contours.end()) {
|
||||||
{
|
|
||||||
//Create bounding rect of object
|
//Create bounding rect of object
|
||||||
RotatedRect mr = minAreaRect(Mat(*itc));
|
RotatedRect mr = minAreaRect(Mat(*itc));
|
||||||
if (!CheckSizes(mr))
|
if (!CheckSizes(mr))
|
||||||
itc = contours.erase(itc);
|
itc = contours.erase(itc);
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
++itc;
|
++itc;
|
||||||
if (itc == contours.end()) continue;
|
if (itc == contours.end()) continue;
|
||||||
rects.push_back(mr);
|
rects.push_back(mr);
|
||||||
@@ -104,8 +94,7 @@ namespace alpr
|
|||||||
//Now prunning based on checking all candidate plates for a min/max number of blobs
|
//Now prunning based on checking all candidate plates for a min/max number of blobs
|
||||||
Mat img_crop, img_crop_b;
|
Mat img_crop, img_crop_b;
|
||||||
vector< vector< Point> > plateBlobs;
|
vector< vector< Point> > plateBlobs;
|
||||||
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;
|
||||||
|
|
||||||
@@ -137,8 +126,7 @@ namespace alpr
|
|||||||
return detectedRegions;
|
return detectedRegions;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DetectorMorph::CheckSizes(RotatedRect& mr)
|
bool DetectorMorph::CheckSizes(RotatedRect& mr) {
|
||||||
{
|
|
||||||
|
|
||||||
float error = 1.2;
|
float error = 1.2;
|
||||||
|
|
||||||
|
@@ -31,8 +31,7 @@
|
|||||||
|
|
||||||
#include "detector.h"
|
#include "detector.h"
|
||||||
|
|
||||||
namespace alpr
|
namespace alpr {
|
||||||
{
|
|
||||||
|
|
||||||
class DetectorMorph : public Detector {
|
class DetectorMorph : public Detector {
|
||||||
public:
|
public:
|
||||||
|
Reference in New Issue
Block a user