Skip to content
sundy edited this page Dec 29, 2018 · 4 revisions

Linux Platform

1. move library to /usr/local/lib/

  sudo cp lib/libCore.so /usr/local/lib/ -fr
  sudo cp lib/libDEye.so /usr/local/lib/ -fr

2. OpenCV configure

   tar -xvf opencv4.0 -C /path/to  
   vim ~/.bashrc
   // add the content to .bashrc
   export OpenCV_DIR=/path/to/opencv4.0
   export OpenCV_INCLUDE_DIRS=/path/to/include/opencv4
   export OpenCV_LIBS=/path/to/opencv4.0/lib

3. Develop your application according to demo.cpp

3.1 Interface

__DLLEXPORT int lodDEyeNet(DEyeNet* dEyeNet_p);
__DLLEXPORT int detect(const DEyeNet dEyeNet_p, cv::Mat& frame, std::vector<DEFECT>& defects);

3.2 Application

#include "DEye.h"
#include <iostream>

int main(int argc, char** argv){
// 1. load DEye model.
DEyeNet dEyeNet_p;
int ret = lodDEyeNet(&dEyeNet_p);
if(ret == -1){
    std::cout << "load DEye model failed!"<< std::endl;
    return -1;
}

// 2. read image(loop read image)
cv::Mat inMat = cv::imread("demo.png",cv::IMREAD_UNCHANGED);
if(inMat.empty()){
    std::cout<<"Image read failed or not found!"<<std::endl;
    return -1;
}

// 3. do detection
std::vector<DEFECT> defects;
ret = detect(dEyeNet_p, inMat, defects);
if(ret != -1){
    int size = ret;
    std::cout<<"======size: " << size <<"======"<< std::endl;
    for(auto def: defects){
        std::cout<<def.type<<std::endl;
        std::cout<<def.score<<std::endl;
        std::cout<<def.defectRect.x<<","<<def.defectRect.y<<","<<def.defectRect.width<<","<<def.defectRect.height<<std::endl;
        cv::Point tl, br;
        tl =  cv::Point(def.defectRect.x, def.defectRect.y);
        br =  cv::Point(def.defectRect.x + def.defectRect.width, def.defectRect.y +  def.defectRect.height);
        cv::rectangle(inMat, tl, br, cv::Scalar(0, 255, 255), 1);
        std::string scoreString = std::to_string(def.score).substr(0, 5);
        std::string caption = def.type + " (" + scoreString + ")";
        cv::Point textCorner = cv::Point(tl.x, tl.y + 12 * 0.9);
        cv::putText(inMat, caption, textCorner, cv::FONT_HERSHEY_SIMPLEX, 0.4, cv::Scalar(255, 0, 0));
    }
    cv::imwrite("result.png",inMat);
}
 return 1;

}

4. CMakeLists.txt

cmake_minimum_required(VERSION 3.7)
project(demo)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-O3 -std=c++11 -pthread -fopenmp -DNDEBUG")

set(SOURCE_FILES_OO demo.cpp DEye.h)
add_executable(demo ${SOURCE_FILES_OO})

# OpenCV libs
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
target_link_libraries(demo ${OpenCV_LIBS})
target_link_libraries(demo "/usr/local/lib/libCore.so")
target_link_libraries(demo "/usr/local/lib/libDEye.so")

5. compile

mkdir build
cd build
cmake .. && make

6. run

cp model.so model.map ./build
./demo

7. output

======size: 1======
hole               // defect type
1                  // defect label
641,619,50,41.     // defect [x,y,w,h]