Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support for opencv 4.5.0 #333

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ if (CMAKE_SYSTEM_NAME MATCHES "Darwin")
endif ()

# OpenVC3 required
find_package(OpenCV 3.2.0 REQUIRED)
find_package(OpenCV 4.5.0 REQUIRED)

# where to find header files
include_directories(.)
Expand Down
10 changes: 5 additions & 5 deletions include/easypr/config.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef EASYPR_CONFIG_H_
#define EASYPR_CONFIG_H_

#define CV_VERSION_THREE_ZERO
#define CV_VERSION_TWO

namespace easypr {

Expand Down Expand Up @@ -133,14 +133,14 @@ private:\
// Load model. compatitable withe 3.0, 3.1 and 3.2
#ifdef CV_VERSION_THREE_TWO
#define LOAD_SVM_MODEL(model, path) \
model = ml::SVM::load(path);
model = Algorithm::load<SVM>(path);
#define LOAD_ANN_MODEL(model, path) \
model = ml::ANN_MLP::load(path);
model = Algorithm::load<ANN_MLP>(path);
#else
#define LOAD_SVM_MODEL(model, path) \
model = ml::SVM::load<ml::SVM>(path);
model = Algorithm::load<ml::SVM>(path);
#define LOAD_ANN_MODEL(model, path) \
model = ml::ANN_MLP::load<ml::ANN_MLP>(path);
model = Algorithm::load<ml::ANN_MLP>(path);
#endif

}
Expand Down
1 change: 1 addition & 0 deletions src/core/core_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "easypr/config.h"
#include "easypr/core/params.h"
#include "thirdparty/mser/mser2.hpp"
#include <opencv2/highgui/highgui_c.h>
#include <ctime>

namespace easypr {
Expand Down
18 changes: 9 additions & 9 deletions src/core/feature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ Mat getHistogram(Mat in) {

void getHistogramFeatures(const Mat& image, Mat& features) {
Mat grayImage;
cvtColor(image, grayImage, CV_RGB2GRAY);
cvtColor(image, grayImage, COLOR_RGB2GRAY);

//grayImage = histeq(grayImage);

Mat img_threshold;
threshold(grayImage, img_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
threshold(grayImage, img_threshold, 0, 255, cv::THRESH_OTSU + cv::THRESH_BINARY);
//Mat img_threshold = grayImage.clone();
//spatial_ostu(img_threshold, 8, 2, getPlateType(image, false));

Expand All @@ -50,7 +50,7 @@ void getColorFeatures(const Mat& src, Mat& features) {
Mat src_hsv;

//grayImage = histeq(grayImage);
cvtColor(src, src_hsv, CV_BGR2HSV);
cvtColor(src, src_hsv, COLOR_BGR2HSV);
int channels = src_hsv.channels();
int nRows = src_hsv.rows;

Expand Down Expand Up @@ -108,7 +108,7 @@ void getSIFTFeatures(const Mat& image, Mat& features) {
//HOG Features
void getHOGFeatures(const Mat& image, Mat& features) {
//HOG descripter
HOGDescriptor hog(cvSize(128, 64), cvSize(16, 16), cvSize(8, 8), cvSize(8, 8), 3); //these parameters work well
HOGDescriptor hog(cv::Size(128, 64), cv::Size(16, 16), cv::Size(8, 8), cv::Size(8, 8), 3); //these parameters work well
std::vector<float> descriptor;

// resize input image to (128,64) for compute
Expand All @@ -133,7 +133,7 @@ void getHSVHistFeatures(const Mat& image, Mat& features) {
void getLBPFeatures(const Mat& image, Mat& features) {

Mat grayImage;
cvtColor(image, grayImage, CV_RGB2GRAY);
cvtColor(image, grayImage, COLOR_RGB2GRAY);

Mat lbpimage;
lbpimage = libfacerec::olbp(grayImage);
Expand Down Expand Up @@ -377,7 +377,7 @@ void getGrayPlusProject(const Mat& grayChar, Mat& features)
}
SHOW_IMAGE(grayChar, 0);
Mat binaryChar;
threshold(grayChar, binaryChar, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
threshold(grayChar, binaryChar, 0, 255, cv::THRESH_OTSU + cv::THRESH_BINARY);
SHOW_IMAGE(binaryChar, 0);
Mat projectFeature = charProjectFeatures(binaryChar, 32);

Expand Down Expand Up @@ -442,20 +442,20 @@ void getGrayPlusLBP(const Mat& grayChar, Mat& features)

void getLBPplusHistFeatures(const Mat& image, Mat& features) {
Mat grayImage;
cvtColor(image, grayImage, CV_RGB2GRAY);
cvtColor(image, grayImage, COLOR_RGB2GRAY);

Mat lbpimage;
lbpimage = libfacerec::olbp(grayImage);
Mat lbp_hist = libfacerec::spatial_histogram(lbpimage, 64, 8, 4);
//features = lbp_hist.reshape(1, 1);

Mat greyImage;
cvtColor(image, greyImage, CV_RGB2GRAY);
cvtColor(image, greyImage, COLOR_RGB2GRAY);

//grayImage = histeq(grayImage);
Mat img_threshold;
threshold(greyImage, img_threshold, 0, 255,
CV_THRESH_OTSU + CV_THRESH_BINARY);
cv::THRESH_OTSU + cv::THRESH_BINARY);
Mat histomFeatures = getHistogram(img_threshold);

hconcat(lbp_hist.reshape(1, 1), histomFeatures.reshape(1, 1), features);
Expand Down
15 changes: 8 additions & 7 deletions src/core/plate_locate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include "easypr/core/core_func.h"
#include "easypr/util/util.h"
#include "easypr/core/params.h"
#include<opencv2/imgproc/types_c.h>

using namespace std;

Expand Down Expand Up @@ -120,7 +121,7 @@ int CPlateLocate::colorSearch(const Mat &src, const Color r, Mat &out,

Mat src_threshold;
threshold(match_grey, src_threshold, 0, 255,
CV_THRESH_OTSU + CV_THRESH_BINARY);
cv::THRESH_OTSU + cv::THRESH_BINARY);

Mat element = getStructuringElement(
MORPH_RECT, Size(color_morph_width, color_morph_height));
Expand Down Expand Up @@ -313,7 +314,7 @@ int CPlateLocate::sobelOper(const Mat &in, Mat &out, int blurSize, int morphW,

Mat mat_gray;
if (mat_blur.channels() == 3)
cvtColor(mat_blur, mat_gray, CV_RGB2GRAY);
cvtColor(mat_blur, mat_gray, COLOR_RGB2GRAY);
else
mat_gray = mat_blur;

Expand All @@ -333,7 +334,7 @@ int CPlateLocate::sobelOper(const Mat &in, Mat &out, int blurSize, int morphW,

Mat mat_threshold;
double otsu_thresh_val =
threshold(grad, mat_threshold, 0, 255, CV_THRESH_OTSU + CV_THRESH_BINARY);
threshold(grad, mat_threshold, 0, 255, cv::THRESH_OTSU + cv::THRESH_BINARY);


Mat element = getStructuringElement(MORPH_RECT, Size(morphW, morphH));
Expand All @@ -346,7 +347,7 @@ int CPlateLocate::sobelOper(const Mat &in, Mat &out, int blurSize, int morphW,

void deleteNotArea(Mat &inmat, Color color = UNKNOWN) {
Mat input_grey;
cvtColor(inmat, input_grey, CV_BGR2GRAY);
cvtColor(inmat, input_grey, COLOR_BGR2GRAY);

int w = inmat.cols;
int h = inmat.rows;
Expand All @@ -368,7 +369,7 @@ void deleteNotArea(Mat &inmat, Color color = UNKNOWN) {
Mat tmp = input_grey(Rect_<double>(w * 0.15, h * 0.15, w * 0.7, h * 0.7));
int threadHoldV = ThresholdOtsu(tmp);

threshold(input_grey, img_threshold, threadHoldV, 255, CV_THRESH_BINARY);
threshold(input_grey, img_threshold, threadHoldV, 255, cv::THRESH_BINARY);
// threshold(input_grey, img_threshold, 5, 255, CV_THRESH_OTSU +
// CV_THRESH_BINARY);

Expand All @@ -380,15 +381,15 @@ void deleteNotArea(Mat &inmat, Color color = UNKNOWN) {
int threadHoldV = ThresholdOtsu(tmp);

threshold(input_grey, img_threshold, threadHoldV, 255,
CV_THRESH_BINARY_INV);
cv::THRESH_BINARY_INV);

utils::imwrite("resources/image/tmp/inputgray2.jpg", img_threshold);

// threshold(input_grey, img_threshold, 10, 255, CV_THRESH_OTSU +
// CV_THRESH_BINARY_INV);
} else
threshold(input_grey, img_threshold, 10, 255,
CV_THRESH_OTSU + CV_THRESH_BINARY);
cv::THRESH_OTSU + cv::THRESH_BINARY);

//img_threshold = input_grey.clone();
//spatial_ostu(img_threshold, 8, 2, plateType);
Expand Down
2 changes: 1 addition & 1 deletion src/train/annCh_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace easypr {
ann_->setLayerSizes(layers);
ann_->setActivationFunction(cv::ml::ANN_MLP::SIGMOID_SYM, 1, 1);
ann_->setTrainMethod(cv::ml::ANN_MLP::TrainingMethods::BACKPROP);
ann_->setTermCriteria(cvTermCriteria(CV_TERMCRIT_ITER, 30000, 0.0001));
ann_->setTermCriteria(TermCriteria(cv::TermCriteria::MAX_ITER, 30000, 0.0001));
ann_->setBackpropWeightScale(0.1);
ann_->setBackpropMomentumScale(0.1);

Expand Down
2 changes: 1 addition & 1 deletion src/train/ann_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void AnnTrain::train() {
ann_->setLayerSizes(layers);
ann_->setActivationFunction(cv::ml::ANN_MLP::SIGMOID_SYM, 1, 1);
ann_->setTrainMethod(cv::ml::ANN_MLP::TrainingMethods::BACKPROP);
ann_->setTermCriteria(cvTermCriteria(CV_TERMCRIT_ITER, 30000, 0.0001));
ann_->setTermCriteria(TermCriteria(cv::TermCriteria::MAX_ITER, 30000, 0.0001));
ann_->setBackpropWeightScale(0.1);
ann_->setBackpropMomentumScale(0.1);

Expand Down
2 changes: 1 addition & 1 deletion src/train/svm_train.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ void SvmTrain::train() {
svm_->setC(1);
svm_->setNu(0.1);
svm_->setP(0.1);
svm_->setTermCriteria(cvTermCriteria(CV_TERMCRIT_ITER, 20000, 0.0001));
svm_->setTermCriteria(TermCriteria(cv::TermCriteria::MAX_ITER, 20000, 0.0001));

this->prepare();

Expand Down
2 changes: 1 addition & 1 deletion thirdparty/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.1.0)
project(thirdparty)

# OpenVC3 required
find_package(OpenCV 3.1.0 REQUIRED)
find_package(OpenCV 4.5.0 REQUIRED)

# where to find header files
include_directories(${OpenCV_INCLUDE_DIRS})
Expand Down
18 changes: 9 additions & 9 deletions thirdparty/LBP/helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ bool libfacerec::isSymmetric(InputArray src, double eps) {
Mat libfacerec::argsort(InputArray _src, bool ascending) {
Mat src = _src.getMat();
if (src.rows != 1 && src.cols != 1) {
CV_Error(CV_StsBadArg, "cv::argsort only sorts 1D matrices.");
CV_Error(Error::StsBadArg, "cv::argsort only sorts 1D matrices.");
}
int flags = CV_SORT_EVERY_ROW+(ascending ? CV_SORT_ASCENDING : CV_SORT_DESCENDING);
int flags = cv::SORT_EVERY_ROW+(ascending ? cv::SORT_ASCENDING : cv::SORT_DESCENDING);
Mat sorted_indices;
cv::sortIdx(src.reshape(1,1),sorted_indices,flags);
return sorted_indices;
Expand Down Expand Up @@ -142,7 +142,7 @@ Mat libfacerec::histc(InputArray _src, int minVal, int maxVal, bool normed) {
return histc_(src, minVal, maxVal, normed);
break;
default:
CV_Error(CV_StsUnmatchedFormats, "This type is not implemented yet."); break;
CV_Error(cv::Error::StsUnmatchedFormats, "This type is not implemented yet."); break;
}
return Mat();
}
Expand All @@ -154,7 +154,7 @@ Mat libfacerec::histc(InputArray _src, int minVal, int maxVal, bool normed) {
void libfacerec::sortMatrixColumnsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
if(_indices.getMat().type() != CV_32SC1) {
string error_message = format("cv::sortRowsByIndices only works on integer indices! Expected: %d. Given: %d.", CV_32SC1, _indices.getMat().type());
CV_Error(CV_StsBadArg, error_message);
CV_Error(Error::StsBadArg , error_message);
}
Mat src = _src.getMat();
vector<int> indices = _indices.getMat();
Expand All @@ -179,7 +179,7 @@ Mat libfacerec::sortMatrixColumnsByIndices(InputArray src, InputArray indices) {
void libfacerec::sortMatrixRowsByIndices(InputArray _src, InputArray _indices, OutputArray _dst) {
if(_indices.getMat().type() != CV_32SC1) {
string error_message = format("cv::sortRowsByIndices only works on integer indices! Expected: %d. Given: %d.", CV_32SC1, _indices.getMat().type());
CV_Error(CV_StsBadArg, error_message);
CV_Error(Error::StsBadArg, error_message);
}
Mat src = _src.getMat();
vector<int> indices = _indices.getMat();
Expand All @@ -204,7 +204,7 @@ Mat libfacerec::sortMatrixRowsByIndices(InputArray src, InputArray indices) {
Mat libfacerec::asRowMatrix(InputArrayOfArrays src, int rtype, double alpha, double beta) {
// make sure the input data is a vector of matrices or vector of vector
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
CV_Error(CV_StsBadArg, "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).");
CV_Error(Error::StsBadArg , "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).");
}
// number of samples
size_t n = src.total();
Expand All @@ -220,7 +220,7 @@ Mat libfacerec::asRowMatrix(InputArrayOfArrays src, int rtype, double alpha, dou
// make sure data can be reshaped, throw exception if not!
if(src.getMat(i).total() != d) {
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total());
CV_Error(CV_StsBadArg, error_message);
CV_Error(Error::StsBadArg , error_message);
}
// get a hold of the current row
Mat xi = data.row(i);
Expand All @@ -240,7 +240,7 @@ Mat libfacerec::asRowMatrix(InputArrayOfArrays src, int rtype, double alpha, dou
Mat libfacerec::asColumnMatrix(InputArrayOfArrays src, int rtype, double alpha, double beta) {
// make sure the input data is a vector of matrices or vector of vector
if(src.kind() != _InputArray::STD_VECTOR_MAT && src.kind() != _InputArray::STD_VECTOR_VECTOR) {
CV_Error(CV_StsBadArg, "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).");
CV_Error(Error::StsBadArg , "The data is expected as InputArray::STD_VECTOR_MAT (a std::vector<Mat>) or _InputArray::STD_VECTOR_VECTOR (a std::vector< vector<...> >).");
}
int n = (int) src.total();
// return empty matrix if no data given
Expand All @@ -255,7 +255,7 @@ Mat libfacerec::asColumnMatrix(InputArrayOfArrays src, int rtype, double alpha,
// make sure data can be reshaped, throw exception if not!
if(src.getMat(i).total() != d) {
string error_message = format("Wrong number of elements in matrix #%d! Expected %d was %d.", i, d, src.getMat(i).total());
CV_Error(CV_StsBadArg, error_message);
CV_Error(Error::StsBadArg , error_message);
}
// get a hold of the current row
Mat yi = data.col(i);
Expand Down