Skip to content

Commit

Permalink
Merge pull request openalpr#878 from sarafalamaki/macos-catalina
Browse files Browse the repository at this point in the history
Updated code to use openCV v4 and gave the right flags to Clang
  • Loading branch information
matthill authored Apr 8, 2020
2 parents 6ead2fb + 3faa021 commit 3868953
Show file tree
Hide file tree
Showing 27 changed files with 99 additions and 92 deletions.
3 changes: 2 additions & 1 deletion doc/man/alpr.1
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ the library, the accuracy for these other countries can be increased.
Where:

\-c <country_code>, \-\-country <country_code>
Country code to identify (either us for USA or eu for Europe).
Country code to identify (either us for USA or eu for Europe). Can pass
multiple country codes separated by a comma. For example au,us,eu.
Default=us

\-\-config <config_file>
Expand Down
8 changes: 7 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,12 @@ SET (CPACK_PACKAGE_CONTACT "Matt Hill <[email protected]>")
SET (CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_ARCHITECTURE}")

SET (CPACK_COMPONENTS_ALL Libraries ApplicationData)

set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
set (CMAKE_CXX_STANDARD 11)
cmake_minimum_required(VERSION 3.1)
# Enable C++11
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
INCLUDE(CPack)

# ----------------------------------------------------------------------------
Expand All @@ -270,3 +275,4 @@ CONFIGURE_FILE(
@ONLY)

ADD_CUSTOM_TARGET(uninstall COMMAND ${CMAKE_COMMAND} -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")

2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int main( int argc, const char** argv )

cv::VideoCapture cap = cv::VideoCapture();
cap.open(filename);
cap.set(CV_CAP_PROP_POS_MSEC, seektoms);
cap.set(cv::CAP_PROP_POS_MSEC, seektoms);

while (cap.read(frame))
{
Expand Down
12 changes: 6 additions & 6 deletions src/misc_utilities/binarizefontsheet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ bool sort_lined_rectangles(Rect i, Rect j) {
void show_debug_image(vector<Rect> rectangles, Mat img)
{
Mat debugImg;
cvtColor(img, debugImg, CV_GRAY2BGR);
cvtColor(img, debugImg, COLOR_GRAY2BGR);
for (unsigned int i = 0; i < rectangles.size(); i++)
{
Rect mr = rectangles[i];
Expand Down Expand Up @@ -172,7 +172,7 @@ int main(int argc, char** argv) {

Config config("us");

cvtColor(frame, frame, CV_BGR2GRAY);
cvtColor(frame, frame, COLOR_BGR2GRAY);
vector<Mat> thresholds = produceThresholds(frame, &config);


Expand All @@ -186,7 +186,7 @@ int main(int argc, char** argv) {

vector<vector<Point> > speckle_contours;
vector<Vec4i> speckle_hierarchy;
findContours(speckle_copy, speckle_contours, speckle_hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(speckle_copy, speckle_contours, speckle_hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);
Mat testImg = Mat::zeros(thresholds[t].size(), thresholds[t].type());

for (unsigned int i = 0; i < speckle_contours.size(); i++)
Expand All @@ -195,8 +195,8 @@ int main(int argc, char** argv) {

if (speckleRect.area() < MIN_SPECKLE_AREA_PIXELS)
{
drawContours(thresholds[t], speckle_contours, i, Scalar(0,0,0), CV_FILLED);
drawContours(testImg, speckle_contours, i, Scalar(255,255,255), CV_FILLED);
drawContours(thresholds[t], speckle_contours, i, Scalar(0,0,0), FILLED);
drawContours(testImg, speckle_contours, i, Scalar(255,255,255), FILLED);
}
}
resize(testImg, testImg, Size(700, 1000));
Expand All @@ -220,7 +220,7 @@ int main(int argc, char** argv) {

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(blobby, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(blobby, contours, hierarchy, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

bitwise_not(thresholds[t], thresholds[t]);

Expand Down
6 changes: 3 additions & 3 deletions src/misc_utilities/calibrate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <cstdlib>
#include <cstdio>
#include <iostream>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/highgui/highgui_c.h>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/calib3d/calib3d.hpp>

Expand Down Expand Up @@ -230,7 +230,7 @@ void initialize_variables()

void create_window()
{
namedWindow(WINDOW_NAME, CV_WINDOW_AUTOSIZE | CV_WINDOW_KEEPRATIO | CV_GUI_EXPANDED);
namedWindow(WINDOW_NAME, WINDOW_AUTOSIZE | WINDOW_KEEPRATIO | WINDOW_GUI_EXPANDED);

value = round(-(rotationx * 20000.0) + 100);
createTrackbar( "X", WINDOW_NAME, &value, 200, XChange);
Expand Down Expand Up @@ -417,7 +417,7 @@ int main(int argc, char** argv) {

}

cvDestroyAllWindows();
destroyAllWindows();


return 0;
Expand Down
6 changes: 3 additions & 3 deletions src/misc_utilities/classifychars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ int main( int argc, const char** argv )
imshow ("Original", frame);

PipelineData pipeline_data(frame, Rect(0, 0, frame.cols, frame.rows), &config);
cvtColor(frame, frame, CV_BGR2GRAY);
cvtColor(frame, frame, COLOR_BGR2GRAY);
pipeline_data.crop_gray = Mat(frame, Rect(0, 0, frame.cols, frame.rows));
pipeline_data.thresholds = produceThresholds(pipeline_data.crop_gray, &config);

Expand Down Expand Up @@ -311,7 +311,7 @@ void showDashboard(vector<Mat> images, vector<bool> selectedImages, int selected
{
Mat imgCopy(images[i].size(), images[i].type());
images[i].copyTo(imgCopy);
cvtColor(imgCopy, imgCopy, CV_GRAY2BGR);
cvtColor(imgCopy, imgCopy, COLOR_GRAY2BGR);
if (i == selectedIndex)
{
rectangle(imgCopy, Point(1,1), Point(imgCopy.size().width - 1, imgCopy.size().height -1), Scalar(0, 255, 0), 1);
Expand Down Expand Up @@ -344,7 +344,7 @@ vector<string> showCharSelection(Mat image, vector<Rect> charRegions, string sta
{
Mat imgCopy(image.size(), image.type());
image.copyTo(imgCopy);
cvtColor(imgCopy, imgCopy, CV_GRAY2BGR);
cvtColor(imgCopy, imgCopy, COLOR_GRAY2BGR);

rectangle(imgCopy, charRegions[curCharIdx], Scalar(0, 255, 0), 1);

Expand Down
6 changes: 3 additions & 3 deletions src/misc_utilities/prepcharsfortraining.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ int main( int argc, const char** argv )
bitwise_not(charImgCopy, charImgCopy);

characterImg.copyTo(charImgCopy(Rect(X_OFFSET, Y_OFFSET, characterImg.cols, characterImg.rows)));
cvtColor(charImgCopy, charImgCopy, CV_BGR2GRAY);
cvtColor(charImgCopy, charImgCopy, COLOR_BGR2GRAY);
bitwise_not(charImgCopy, charImgCopy);

vector<vector<Point> > contours;

//imshow("copy", charImgCopy);
findContours(charImgCopy, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
findContours(charImgCopy, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

float minHeightPercent = 0.35;
int minHeight = (int) (((float) characterImg.rows) * minHeightPercent);
Expand Down Expand Up @@ -198,7 +198,7 @@ int main( int argc, const char** argv )

//cout << "Cropped: " << cropRect.x << ":" << cropRect.y << " -- " << cropRect.width << ":" << cropRect.height << endl;
Mat cropped(characterImg, cropRect);
cvtColor(cropped, cropped, CV_BGR2GRAY);
cvtColor(cropped, cropped, COLOR_BGR2GRAY);

Rect destinationRect(xPos, yPos, tallestRect.width, tallestRect.height);
//cout << "1" << endl;
Expand Down
2 changes: 1 addition & 1 deletion src/misc_utilities/tagplates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ int main( int argc, const char** argv )
frame.copyTo(tmpFrame);
rectangle(tmpFrame, Point(xPos1, yPos1), Point(xPos2, yPos2), Scalar(0, 0, 255), 2);

rectangle(tmpFrame, Point(xPos1, yPos1 - 35), Point(xPos1 + 175, yPos1 - 5), Scalar(255, 255, 255), CV_FILLED);
rectangle(tmpFrame, Point(xPos1, yPos1 - 35), Point(xPos1 + 175, yPos1 - 5), Scalar(255, 255, 255), FILLED);
putText(tmpFrame, curplatetag, Point(xPos1 + 2, yPos1 - 10), FONT_HERSHEY_PLAIN, 1.5, Scalar(100,50,0), 2);

imshow("Input image", tmpFrame);
Expand Down
2 changes: 1 addition & 1 deletion src/openalpr/alpr_impl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ namespace alpr
// Convert image to grayscale if required
Mat grayImg = img;
if (img.channels() > 2)
cvtColor( img, grayImg, CV_BGR2GRAY );
cvtColor( img, grayImg, COLOR_BGR2GRAY );

// Prewarp the image and ROIs if configured]
std::vector<cv::Rect> warpedRegionsOfInterest = regionsOfInterest;
Expand Down
10 changes: 5 additions & 5 deletions src/openalpr/colorfilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace alpr
cout << "ColorFilter: isGrayscale = " << grayscale << endl;

this->hsv = Mat(image.size(), image.type());
cvtColor( image, this->hsv, CV_BGR2HSV );
cvtColor( image, this->hsv, COLOR_BGR2HSV );
preprocessImage();

this->charMask = characterMask;
Expand Down Expand Up @@ -118,7 +118,7 @@ namespace alpr

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(erodedCharMask, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
findContours(erodedCharMask, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);

vector<float> hMeans, sMeans, vMeans;
vector<float> hStdDevs, sStdDevs, vStdDevs;
Expand All @@ -133,7 +133,7 @@ namespace alpr
drawContours(singleCharMask, contours,
i, // draw this contour
cv::Scalar(255,255,255), // in
CV_FILLED,
FILLED,
8,
hierarchy
);
Expand Down Expand Up @@ -355,7 +355,7 @@ namespace alpr
//displayImage(config, "COLOR filter Mask", colorMask);
debugImagesSet.push_back(addLabel(imgDebug, "Color filter Debug"));

cvtColor(imgDebugHueOnly, imgDebugHueOnly, CV_HSV2BGR);
cvtColor(imgDebugHueOnly, imgDebugHueOnly, COLOR_HSV2BGR);
debugImagesSet.push_back(addLabel(imgDebugHueOnly, "Color Filter Hue"));

equalizeHist(imgDistanceFromCenter, imgDistanceFromCenter);
Expand Down Expand Up @@ -401,4 +401,4 @@ namespace alpr
return bestPercentAgreementIndex;
}

}
}
6 changes: 3 additions & 3 deletions src/openalpr/detection/detector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace alpr

if (frame.channels() > 2)
{
cvtColor( frame, frame_gray, CV_BGR2GRAY );
cvtColor( frame, frame_gray, COLOR_BGR2GRAY );
}
else
{
Expand All @@ -85,7 +85,7 @@ namespace alpr
if (detector_mask.mask_loaded && config->debugDetector)
{
frame_gray.copyTo(mask_debug_img);
cvtColor(frame_gray, mask_debug_img, CV_GRAY2BGR);
cvtColor(frame_gray, mask_debug_img, COLOR_GRAY2BGR);
}

vector<PlateRegion> detectedRegions;
Expand Down Expand Up @@ -258,4 +258,4 @@ namespace alpr
return topLevelRegions;
}

}
}
2 changes: 1 addition & 1 deletion src/openalpr/detection/detectorcpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ namespace alpr
equalizeHist( frame, frame );

plate_cascade.detectMultiScale( frame, plates, config->detection_iteration_increase, config->detectionStrictness,
CV_HAAR_DO_CANNY_PRUNING,
CASCADE_DO_CANNY_PRUNING,
//0|CV_HAAR_SCALE_IMAGE,
min_plate_size, max_plate_size );

Expand Down
4 changes: 2 additions & 2 deletions src/openalpr/detection/detectormask.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace alpr

this->mask = orig_mask;
if (orig_mask.channels() > 2)
cvtColor( orig_mask, this->mask, CV_BGR2GRAY );
cvtColor( orig_mask, this->mask, COLOR_BGR2GRAY );
else
this->mask = orig_mask;

Expand Down Expand Up @@ -163,4 +163,4 @@ namespace alpr
return response;
}

}
}
20 changes: 10 additions & 10 deletions src/openalpr/detection/detectormorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace alpr {

Mat img_open, img_result;
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, MORPH_OPEN, element, cv::Point(-1, -1));

img_result = frame_gray - img_open;

Expand All @@ -68,7 +68,7 @@ namespace alpr {

//threshold image using otsu thresholding
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, THRESH_OTSU + THRESH_BINARY);

if (config->debugDetector && config->debugShowImages) {
imshow("Threshold Detector", img_threshold);
Expand All @@ -89,9 +89,9 @@ namespace alpr {
diamond.at<uchar>(0, 3) = 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, MORPH_OPEN, diamond, cv::Point(-1, -1));
Mat rectElement = getStructuringElement(cv::MORPH_RECT, Size(13, 4));
morphologyEx(img_open2, img_threshold, CV_MOP_CLOSE, rectElement, cv::Point(-1, -1));
morphologyEx(img_open2, img_threshold, MORPH_CLOSE, rectElement, cv::Point(-1, -1));

if (config->debugDetector && config->debugShowImages) {
imshow("Close", img_threshold);
Expand All @@ -102,8 +102,8 @@ namespace alpr {
vector< vector< Point> > contours;
findContours(img_threshold,
contours, // a vector of contours
CV_RETR_EXTERNAL, // retrieve the external contours
CV_CHAIN_APPROX_NONE); // all pixels of each contours
RETR_EXTERNAL, // retrieve the external contours
CHAIN_APPROX_NONE); // all pixels of each contours

//Start to iterate to each contour founded
vector<vector<Point> >::iterator itc = contours.begin();
Expand Down Expand Up @@ -159,13 +159,13 @@ namespace alpr {

findContours(img_crop_th,
plateBlobs, // a vector of contours
CV_RETR_LIST, // retrieve the contour list
CV_CHAIN_APPROX_NONE); // all pixels of each contours
RETR_LIST, // retrieve the contour list
CHAIN_APPROX_NONE); // all pixels of each contours

findContours(img_crop_th_inv,
plateBlobsInv, // a vector of contours
CV_RETR_LIST, // retrieve the contour list
CV_CHAIN_APPROX_NONE); // all pixels of each contours
RETR_LIST, // retrieve the contour list
CHAIN_APPROX_NONE); // all pixels of each contours

int numBlobs = plateBlobs.size();
int numBlobsInv = plateBlobsInv.size();
Expand Down
4 changes: 2 additions & 2 deletions src/openalpr/edges/edgefinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ namespace alpr
threshold(newCrop, thresholded_crop, 80, 255, cv::THRESH_OTSU);

vector<vector<Point> > contours;
findContours(thresholded_crop, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE );
findContours(thresholded_crop, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE );

float MIN_AREA = 0.05 * newCrop.cols * newCrop.rows;
for (unsigned int i = 0; i < contours.size(); i++)
Expand Down Expand Up @@ -343,4 +343,4 @@ namespace alpr
return contrast > pipeline_data->config->contrastDetectionThreshold;
}

}
}
12 changes: 6 additions & 6 deletions src/openalpr/edges/platecorners.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,18 +86,18 @@ namespace alpr

Mat imgCorners = Mat(inputImage.size(), inputImage.type());
inputImage.copyTo(imgCorners);
cvtColor(imgCorners, imgCorners, CV_GRAY2BGR);
cvtColor(imgCorners, imgCorners, COLOR_GRAY2BGR);

for (unsigned int linenum = 0; linenum < textLines.size(); linenum++)
{
for (int i = 0; i < 4; i++)
circle(imgCorners, textLines[linenum].textArea[i], 2, Scalar(0, 0, 0));
}

line(imgCorners, this->bestTop.p1, this->bestTop.p2, Scalar(255, 0, 0), 1, CV_AA);
line(imgCorners, this->bestRight.p1, this->bestRight.p2, Scalar(0, 0, 255), 1, CV_AA);
line(imgCorners, this->bestBottom.p1, this->bestBottom.p2, Scalar(0, 0, 255), 1, CV_AA);
line(imgCorners, this->bestLeft.p1, this->bestLeft.p2, Scalar(255, 0, 0), 1, CV_AA);
line(imgCorners, this->bestTop.p1, this->bestTop.p2, Scalar(255, 0, 0), 1, LINE_AA);
line(imgCorners, this->bestRight.p1, this->bestRight.p2, Scalar(0, 0, 255), 1, LINE_AA);
line(imgCorners, this->bestBottom.p1, this->bestBottom.p2, Scalar(0, 0, 255), 1, LINE_AA);
line(imgCorners, this->bestLeft.p1, this->bestLeft.p2, Scalar(255, 0, 0), 1, LINE_AA);

displayImage(pipelineData->config, "Winning top/bottom Boundaries", imgCorners);
}
Expand Down Expand Up @@ -337,7 +337,7 @@ namespace alpr
scoreKeeper.printDebugScores();
Mat debugImg(this->inputImage.size(), this->inputImage.type());
this->inputImage.copyTo(debugImg);
cvtColor(debugImg, debugImg, CV_GRAY2BGR);
cvtColor(debugImg, debugImg, COLOR_GRAY2BGR);
line(debugImg, top.p1, top.p2, Scalar(0,0,255), 2);
line(debugImg, bottom.p1, bottom.p2, Scalar(0,0,255), 2);
//drawAndWait(&debugImg);
Expand Down
Loading

0 comments on commit 3868953

Please sign in to comment.