Fixed opencv dependency library bug

master
tunm 2 years ago
parent 7d0d1f6d37
commit 0ce5566171

@ -1,14 +1,17 @@
cmake_minimum_required(VERSION 3.10.2)
cmake_minimum_required(VERSION 3.14)
project(HyperLPR3-Source)
set(CMAKE_CXX_STANDARD 11)
set(LIBRARY_NAME hyperlpr3)
option( LINUX_FETCH_MNN "Fetch and build MNN from git" ON )
option( LINUX_USE_3RDPARTY_OPENCV "Linux platform using pre-compiled OpenCV library from 3rdparty_hyper_inspire_op" OFF)
option( BUILD_SHARE "Build shared libs" ON )
option( BUILD_SAMPLES "Build samples demo" OFF )
option( BUILD_TEST "Build unit-test exec" OFF )
set(PATH_3RDPARTY ${CMAKE_CURRENT_SOURCE_DIR}/3rdparty_hyper_inspire_op)
# find all cpp file
@ -84,12 +87,36 @@ else ()
else()
set(PLAT linux)
endif ()
# Fetch MNN from git if the option is enabled
if (LINUX_FETCH_MNN)
# Include FetchContent module
include(FetchContent)
# Fetch MNN
message("Downloading MNN from https://github.com/alibaba/MNN.git, this may take a while.")
FetchContent_Declare(
mnn
GIT_REPOSITORY https://github.com/alibaba/MNN.git
GIT_TAG 2.2.0
)
set(MNN_BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
set(MNN_BUILD_TOOLS OFF CACHE BOOL "" FORCE)
FetchContent_MakeAvailable(mnn)
set(MNN_INCLUDE_DIRS ${mnn_SOURCE_DIR}/include)
set(MNN_LIBS ${mnn_BINARY_DIR})
else()
# MNN Third party dependence
set(MNN_INCLUDE_DIRS ${PATH_3RDPARTY}/MNN-2.2.0/${PLAT}/include)
set(MNN_LIBS ${PATH_3RDPARTY}/MNN-2.2.0/${PLAT}/lib)
# OpenCV Third party dependence
endif()
if(LINUX_USE_3RDPARTY_OPENCV)
# OpenCV Third party dependence static
set(OpenCV_DIR ${PATH_3RDPARTY}/opencv-4.5.1/${PLAT}/lib/cmake/opencv4)
set(OpenCV_STATIC_INCLUDE_DIR ${PATH_3RDPARTY}/opencv-4.5.1/${PLAT}/include/opencv4)
endif()
find_package(OpenCV REQUIRED)
endif()
@ -126,8 +153,6 @@ if (NOT ANDROID)
message([Test]Open Benchmark Test)
add_definitions(-DENABLE_BENCHMARK_TEST)
endif ()
# # catch2
include_directories(${PATH_3RDPARTY}/catch2)
file(GLOB_RECURSE TEST_C_CPP_FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/test/*.cpp)
add_executable(UnitTest ${TEST_C_CPP_FILES} ${SRC_C_CPP_FILES} ${CAPI_CC_FILES})
target_link_libraries(UnitTest ${OpenCV_LIBS} ${LINK_THIRD_LIBS})
@ -146,22 +171,17 @@ endif()
set(CMAKE_INSTALL_PREFIX ${PROJECT_BINARY_DIR}/install/hyperlpr3)
message(CMAKE_INSTALL_PREFIX=${CMAKE_INSTALL_PREFIX})
install(DIRECTORY resource DESTINATION ./)
if (APPLE)
install(FILES ${MNN_LIBS}/libMNN.dylib DESTINATION ./lib)
else()
install(FILES ${MNN_LIBS}/libMNN.so DESTINATION ./lib)
endif ()
# Add HyperLPR3-related files and directories to the installation list
install(TARGETS ${LIBRARY_NAME} DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/c_api/hyper_lpr_sdk.h DESTINATION ${CMAKE_INSTALL_PREFIX}/include)
# Install resource file
install(DIRECTORY resource DESTINATION ${CMAKE_INSTALL_PREFIX})
# Install Resource files You can also install sample programs if they are available
if (BUILD_SAMPLES)
install(TARGETS ContextSample DESTINATION ./bin)
install(TARGETS CAPISample DESTINATION ./bin)
install(TARGETS SplitDetSample DESTINATION ./bin)
endif()
if (BUILD_SHARE)
install(TARGETS ${LIBRARY_NAME} DESTINATION ./lib)
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cpp/c_api/hyper_lpr_sdk.h DESTINATION ./include)
endif ()
if (BUILD_TEST)
install(TARGETS UnitTest DESTINATION test)
install(TARGETS ContextSample DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS CAPISample DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install(TARGETS SplitDetSample DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
endif()

@ -0,0 +1,2 @@
hyperlpr3/
build/

@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.10.2)
cmake_minimum_required(VERSION 3.14)
project(HyperLPR3-LinuxDemo)
set(CMAKE_CXX_STANDARD 11)
@ -10,12 +10,11 @@ else()
set(PLAT linux)
endif ()
# use opencv
set(OpenCV_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../3rdparty_hyper_inspire_op/opencv-4.5.1/${PLAT}/lib/cmake/opencv4)
# You need to link to the opencv library
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
# use hyperlpr3 sdk
# You need to compile hyperlpr3 library to use it
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/hyperlpr3/include)
link_directories(${CMAKE_CURRENT_SOURCE_DIR}/hyperlpr3/lib)

@ -1 +0,0 @@
../build/linux/install/hyperlpr3

@ -141,6 +141,7 @@ Compiling C/C++ projects requires the use of third-party dependency libraries. A
### Linux/Mac Shared Library Compilation
- Need to place or link dependencies in the project root (same level as CMakeLists.txt)
- We recommend you to compile OpenCV yourself and install it into the system. This can help reduce compilation errors caused by version mismatches and compiler issues with system dependencies. However, you can also try using the pre-compiled OpenCV static library we provide for compilation. To do this, you need to enable the **LINUX_USE_3RDPARTY_OPENCV** switch.
```bash
# execute the script
@ -156,7 +157,7 @@ Copy the files you need into your project
### Linux/Mac Compiling the Demo
- You need to complete the compilation action of the previous stepAnd ensure that the compilation is successful and the compiled file is placed in the root directory: **build/linux/install/hyperlpr3**
- You need to complete the previous compilation step and ensure it's successful. The compiled files will be located in the root directory: **build/linux/install/hyperlpr3**. You will need to manually copy them to the current directory.
- Go to the **Prj-Linux** folder
```bash
# go to Prj-linux

@ -144,6 +144,7 @@ A此项目来源于作者早期的研究和调试代码代码缺少一定
### Linux/Mac动态链接库编译
- 需要将依赖库放置或链接在项目根目录下(与CMakeLists.txt同级)
- 在编译Linux相关平台时我们推荐您自行编译opencv并安装至系统中这样可以降低因为系统中一些依赖版本和编译器原因导致的编译错误当然你也可以优先尝试使用我们提供的opencv静态库进行编译需要您把LINUX_USE_3RDPARTY_OPENCV开关打开
```bash
# 执行编译脚本
@ -159,7 +160,7 @@ sh command/build_release_linux_share.sh
### Linux/Mac编译Demo
- 需要完成上一步的编译动作,并保证编译成功且编译完成后的物料放置于根目录下的**build/linux/install/hyperlpr3**路径中
- 需要完成上一步的编译动作,并保证编译成功且编译完成后的物料放置于根目录下的**build/linux/install/hyperlpr3**路径中,需要将其拷贝或链接到当前目录
- 需要从根目录中进入到子工程**Prj-Linux**文件夹中进行操作
```bash
# 进入到子工程demo

@ -130,7 +130,7 @@ InferenceHelper* InferenceHelper::Create(const InferenceHelper::HelperType helpe
#endif
#ifdef INFERENCE_HELPER_ENABLE_MNN
case kMnn:
PRINT("Use MNN\n");
// PRINT("Use MNN\n");
p = new InferenceHelperMnn();
break;
#endif

@ -109,9 +109,7 @@ void DetArch::Detection(const cv::Mat &bgr, bool is_resize, float scale) {
cv::Mat resized_img;
cv::resize(bgr, resized_img, cv::Size(w, h));
cv::copyMakeBorder(resized_img, pad, 0, hpad, 0, wpad, cv::BORDER_CONSTANT, cv::Scalar(127.5, 127.5, 127.5));
// cv::imwrite("i.jpg", pad);
// cv::imshow("pad_border", pad);
// cv::waitKey(0);
} else {
pad = bgr;
}

File diff suppressed because it is too large Load Diff

@ -4,7 +4,7 @@
#pragma once
#ifndef ZEPHYRLPR_TEST_SETTINGS_H
#define ZEPHYRLPR_TEST_SETTINGS_H
#include <catch2/catch.hpp>
#include "catch2/catch.hpp"
#include <iostream>
using namespace Catch::Detail;

Loading…
Cancel
Save