liuruoze / EasyPR

(CGCSTCD'2017) An easy, flexible, and accurate plate recognition project for Chinese licenses in unconstrained situations. CGCSTCD = China Graduate Contest on Smart-city Technology and Creative Design
Apache License 2.0
6.36k stars 2.51k forks source link

debian下,自己的demo代码编译失败 #302

Closed ziyouchutuwenwu closed 5 years ago

ziyouchutuwenwu commented 5 years ago

** debian下,编译opencv 3.2成功,easypr的项目也成功跑起来了,但是自己建立demo项目,抄的说明文档内的几行代码,编译错误,具体如下

using namespace cv; using namespace std; using namespace easypr;

int main() { CPlateRecognize pr; pr.setResultShow(false); pr.setDetectType(PR_DETECT_CMSER);

String filepath = "./aa.jpg";

vector<CPlate> plateVec;
Mat src = imread(filepath);
int result = pr.plateRecognize(src, plateVec);

return 0;

}


CMakeLists.txt

cmake_minimum_required(VERSION 3.7) project(car_plate)

set(CMAKE_CXX_STANDARD 11)

add_executable(car_plate main.cpp)

find_package(OpenCV REQUIRED) include_directories("./easypr_sdk/include/" ${OpenCV_INCLUDE_DIRS}) link_directories("./easypr_sdk/lib" ${OpenCV_LIBRARY_DIRS}) link_libraries(libeasypr.a ${OpenCV_LIBS})


项目目录结构类似

├── CMakeLists.txt ├── easypr_sdk │   ├── include │   │   ├── easypr │   │   │   ├── api.hpp │   │   │   ├── config.h │   │   │   ├── core │   │   │   ├── train │   │   │   ├── util │   │   │   └── version.h │   │   └── easypr.h │   └── lib │   ├── libeasypr.a │   └── libthirdparty.a ├── main.cpp


编译错误代码

====================[ Build | all | Debug ]===================================== /home/mmc/downloads/clion/bin/cmake/linux/bin/cmake --build /home/mmc/downloads/car_plate --target all -- -j 1 Scanning dependencies of target car_plate [ 50%] Building CXX object CMakeFiles/car_plate.dir/main.cpp.o [100%] Linking CXX executable car_plate CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::api::plate_judge(char const, char const)’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:17:对‘cv::imread(cv::String const&, int)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:21:对‘easypr::PlateJudge::instance()’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:21:对‘easypr::PlateJudge::plateJudge(cv::Mat const&)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::api::plate_locate(char const, bool)’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:27:对‘cv::imread(cv::String const&, int)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:31:对‘easypr::CPlateLocate::CPlateLocate()’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:33:对‘easypr::CPlateLocate::setLifemode(bool)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:36:对‘easypr::CPlateLocate::plateLocate(cv::Mat, std::vector<cv::Mat, std::allocator >&, int)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::api::plate_recognize(char const, char const, char const, bool)’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:43:对‘cv::imread(cv::String const&, int)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:46:对‘easypr::CPlateRecognize::CPlateRecognize()’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:54:对‘easypr::CPlateRecognize::plateRecognize(cv::Mat const&, std::vector<easypr::CPlate, std::allocator >&, int)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:65:对‘cv::imwrite(cv::String const&, cv::_InputArray const&, std::vector<int, std::allocator > const&)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::api::get_plate_color(char const)’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:73:对‘cv::imread(cv::String const&, int)’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/api.hpp:77:对‘easypr::getPlateType(cv::Mat const&, bool)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::String::String(char const)’中: /usr/local/include/opencv2/core/cvstd.hpp:622:对‘cv::String::allocate(unsigned long)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::String::~String()’中: /usr/local/include/opencv2/core/cvstd.hpp:664:对‘cv::String::deallocate()’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::String::operator=(cv::String const&)’中: /usr/local/include/opencv2/core/cvstd.hpp:672:对‘cv::String::deallocate()’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::Mat::Mat(cv::Mat const&)’中: /usr/local/include/opencv2/core/mat.inl.hpp:421:对‘cv::Mat::copySize(cv::Mat const&)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::Mat::~Mat()’中: /usr/local/include/opencv2/core/mat.inl.hpp:592:对‘cv::fastFree(void*)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::Mat::operator=(cv::Mat const&)’中: /usr/local/include/opencv2/core/mat.inl.hpp:613:对‘cv::Mat::copySize(cv::Mat const&)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::Mat::release()’中: /usr/local/include/opencv2/core/mat.inl.hpp:704:对‘cv::Mat::deallocate()’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘cv::String::String(std::__cxx11::basic_string<char, std::char_traits, std::allocator > const&)’中: /usr/local/include/opencv2/core/cvstd.inl.hpp:81:对‘cv::String::allocate(unsigned long)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::CPlateDetect::setPDLifemode(bool)’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/core/plate_detect.h:42:对‘easypr::CPlateLocate::setLifemode(bool)’未定义的引用 CMakeFiles/car_plate.dir/main.cpp.o:在函数‘easypr::CPlateRecognize::~CPlateRecognize()’中: /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/core/plate_recognize.h:23:对‘easypr::CCharsRecognise::~CCharsRecognise()’未定义的引用 /home/mmc/downloads/car_plate/./easypr_sdk/include/easypr/core/plate_recognize.h:23:对‘easypr::CPlateDetect::~CPlateDetect()’未定义的引用 collect2: error: ld returned 1 exit status CMakeFiles/car_plate.dir/build.make:94: recipe for target 'car_plate' failed make[2]: [car_plate] Error 1 CMakeFiles/Makefile2:67: recipe for target 'CMakeFiles/car_plate.dir/all' failed make[1]: [CMakeFiles/car_plate.dir/all] Error 2 Makefile:83: recipe for target 'all' failed make: *** [all] Error 2


看结果像是库没找到,但是尝试修改cmakefile,总是不太对

**Please tell us about your environment:**

* **System:** Debian9

* **Compiler version/IDE:** gcc (Debian 6.3.0-18+deb9u1) 6.3.0 20170516

* **CMake version:** /home/mmc/downloads/clion/bin/cmake/linux/bin/cmake --version
cmake version 3.14.3

* **OpenCV version:** [3.2 ]
ziyouchutuwenwu commented 5 years ago

cmake是clion自带的,当然我手动用debian自带的cmake,结果也是一样的,系统的cmake版本是

cmake --version
cmake version 3.7.2

CMake suite maintained and supported by Kitware (kitware.com/cmake).
ziyouchutuwenwu commented 5 years ago

改成下面这样,解决了

cmake_minimum_required(VERSION 3.7)
project(car_plate)

set(CMAKE_CXX_STANDARD 11)

find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS "    version: ${OpenCV_VERSION}")
message(STATUS "    libraries: ${OpenCV_LIBS}")
message(STATUS "    include path: ${OpenCV_INCLUDE_DIRS}")

include_directories(${OpenCV_INCLUDE_DIRS} "./easypr_sdk/include/")

link_directories(./easypr_sdk/lib/ /usr/bin/lib)

# link_libraries用在add_executable之前,target_link_libraries用在add_executable之后
# link_libraries用来链接静态库,target_link_libraries用来链接倒入库,即按照header file + .lib + .dll方式隐式调用动态库的.lib库
#link_libraries(libeasypr.a libthirdparty.a ${OpenCV_LIBS})

add_executable(car_plate main.cpp)
target_link_libraries(car_plate ${OpenCV_LIBS} libeasypr.a libthirdparty.a)