-
Notifications
You must be signed in to change notification settings - Fork 371
Linux
sundy edited this page Dec 29, 2018
·
4 revisions
sudo cp lib/libCore.so /usr/local/lib/ -fr
sudo cp lib/libDEye.so /usr/local/lib/ -fr
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
__DLLEXPORT int lodDEyeNet(DEyeNet* dEyeNet_p);
__DLLEXPORT int detect(const DEyeNet dEyeNet_p, cv::Mat& frame, std::vector<DEFECT>& defects);
#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;
}
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")
mkdir build
cd build
cmake .. && make
cp model.so model.map ./build
./demo
======size: 1======
hole // defect type
1 // defect label
641,619,50,41. // defect [x,y,w,h]