i am new ,and use MacOS Clion to develop C++ program , I have encountered no way to solve the problem, please help me ,Thanks! .h file :
namespace VLJudge {
class JudgeProcess {
public:
static JudgeProcess* instance();
void fileProcess(const std::string &file_path_, const std::string &folder_out,
const std::vector<std::string> &outs);
private:
static JudgeProcess* instance_;
bool verifySizes(const cv::Mat &mat, cv::Rect mr);
};
}
.cpp file :
#include "judge/judge_process.h"
#include "vl.h"
using namespace cv;
using namespace std;
using namespace VL;
namespace VLJudge {
const int DEFAULT_WIDTH_SIZE = 1000;
const int THRESHOLD_MAX_VALUE = 255;
const int DEFAULT_GAUSSIANBLUR_SIZE = 11;
const int THRESHOLD_BLOCK_SIZE = 25;
const int THRESHOLD_CONST_VALUE = 5;
const int DEFAULT_MORPH_SIZE_WIDTH = 15; // 17
const int DEFAULT_MORPH_SIZE_HEIGHT = 1; // 3
void JudgeProcess::fileProcess(const std::string &file_path_, const std::string &folder_out,
const std::vector<std::string> &outs) {
std::vector<std::string> files;
cv::Mat image, zoom, blur, gray, threshold, morphology;
image = cv::imread(file_path_, ImreadModes::IMREAD_COLOR);
Utils::resizeScale(image, zoom, DEFAULT_WIDTH_SIZE);
GaussianBlur(zoom, blur, Size(DEFAULT_GAUSSIANBLUR_SIZE, DEFAULT_GAUSSIANBLUR_SIZE), 0, 0);
cvtColor(blur, gray, CV_RGB2GRAY);
adaptiveThreshold(gray, threshold, THRESHOLD_MAX_VALUE, CV_ADAPTIVE_THRESH_MEAN_C, CV_THRESH_BINARY_INV,
THRESHOLD_BLOCK_SIZE, THRESHOLD_CONST_VALUE);
Mat element = cv::getStructuringElement(MORPH_ELLIPSE,
Size(DEFAULT_MORPH_SIZE_WIDTH, DEFAULT_MORPH_SIZE_HEIGHT));
morphologyEx(threshold, morphology, MORPH_CLOSE, element);
vector<vector<Point> > contours;
findContours(morphology, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
vector<Rect> outRects;
for (int i = 0; i < contours.size(); i++) {
Rect rect = cv::boundingRect(Mat(contours.at(i)));
if (verifySizes(zoom, rect)) {
outRects.push_back(rect);
cv::Mat tempImg;
zoom(outRects[i]).copyTo(tempImg);
string filename = folder_out + "/" + Utils::getFileName(file_path_) + "_" + Utils::int2str(i) + ".jpg";
files.push_back(filename);
imwrite(filename, tempImg);
}
}
}
bool JudgeProcess::verifySizes(const cv::Mat &mat, cv::Rect mr) {
if (1.0 * mr.y > 100 || 1.0 * mr.width * mr.height < 510.0f || mr.x == 0 || mr.y == 0) {
return false;
}
return true;
}
JudgeProcess* JudgeProcess::instance_ = nullptr;
JudgeProcess* JudgeProcess::instance() {
if (!instance_) {
instance_ = new JudgeProcess;
}
return instance_;
}
}
Call the Function code :
#include "vl.h"
#include "judge/judge_process.h"
using namespace std;
const string test_file_path = "../../resource/judge/origin/1_standard.png";
const string file_process = "../../resource/judge/origin/1_standard.png";
int main(int argc, char *argv[]) {
std::vector<std::string> filenames ;
VLJudge::JudgeProcess::instance()->fileProcess(test_file_path,file_process,filenames);
for (int i = 0; i < filenames.size(); ++i) {
string filename = filenames.at(i);
}
return 0;
}
and error log :
- /Applications/CLion.app/Contents/bin/cmake/bin/cmake --build /Users/liqiang /Library/Caches/CLion12/cmake/generated/6f5d7cd5/6f5d7cd5/Debug --target VehicleLicenseOCR -- -j 4 Scanning dependencies of target VehicleLicenseOCR [ 50%] Building CXX object CMakeFiles/VehicleLicenseOCR.dir/src/judge /main_judge.cpp.o [100%] Linking CXX executable VehicleLicenseOCR Undefined symbols for architecture x86_64: "VLJudge::JudgeProcess::fileProcess(std::__1::basic_string, std::__1::allocator > const&, std::__1::basic_string, std::__1::allocator > const&, std::__1::vector, std::__1::allocator >, std::__1::allocator, std::__1::allocator > > > const&)", referenced from: _main in main_judge.cpp.o "VLJudge::JudgeProcess::instance()", referenced from: _main in main_judge.cpp.o ld: symbol(s) not found for architecture x86_64 clang: error: linker command failed with exit code 1 (use -v to see invocation) make[3]: * [VehicleLicenseOCR] Error 1 make[2]: [CMakeFiles/VehicleLicenseOCR.dir/all] Error 2 make[1]: [CMakeFiles/VehicleLicenseOCR.dir/rule] Error 2 make: * [VehicleLicenseOCR] Error 2