Coder Social home page Coder Social logo

lwzhaojun / opencv_matching Goto Github PK

View Code? Open in Web Editor NEW

This project forked from acai66/opencv_matching

0.0 0.0 0.0 4.47 MB

A template matching library based on OpenCV, supporting rotation matching, cross-platform usage, C++, and Python. 基于opencv的模板匹配库,支持旋转匹配,支持跨平台、c++调用、python调用

License: BSD 2-Clause "Simplified" License

C++ 87.83% Python 6.27% CMake 5.89%

opencv_matching's Introduction

模板匹配

demo1

demo2

改进

  1. 封装为更易用的库
  2. 跨平台适配

计划

  • 优化代码结构
  • 支持python

编译

clone代码

git克隆时同步克隆子模块

git clone --recurse-submodules https://github.com/acai66/opencv_matching.git

编译代码

Windows

使用各种编译cmake的方法(vs2022、vs2019、vs2017、或cmake-gui)编译即可,演示使用vs2022编译,其余工具供参考。

编译演示视频:B站链接

Linux

演示Ubuntu 22.04下编译,其他发行版类似

  1. 安装依赖和编译工具
sudo apt-get update
sudo apt-get install libopencv-dev build-essential cmake
  1. 终端进入到项目根目录,创建build文件夹
cd opencv_matching
mkdir build
cd build
  1. cmake构建
cmake  -DCMAKE_INSTALL_PREFIX=./install ..
  1. make编译
make
  1. 安装
make install

成功后会在 build 目录下生成 install 文件夹,里面包含编译好的库(lib)和头文件(include), 以及 demo 可执行文件(bin).

目录结构如下:

install
├── bin
│   └── demo
├── include
│   ├── matcher.h
│   └── templatematching.h
└── lib
    ├── libtemplatematching.so
    └── libtemplatematching_ctype.so

install/bin 下运行 demo 时,需要确保 libtemplatematching.so 在运行目录下,或者将 libtemplatematching.so 放到系统库目录下。

cd install/bin/
cp ../lib/libtemplatematching.so ./
./demo

注意事项

  • 作者机器上不同项目使用的opencv版本不同,所以没有把opencv添加到系统环境变量中,opencv放进了3rdParty文件夹下,目录结构参考如下:

    windows_opencv_path

  • 如需修改opencv路径,可能需要修改如下信息,具体参考 CMakeLists.txtmatcher/CMakeLists.txt 文件:

    CMakeLists.txt

    if(CMAKE_HOST_SYSTEM_NAME MATCHES "Windows")
      set(OpenCV_DIR ${PROJECT_SOURCE_DIR}/3rdParty/opencv)
    endif()

    matcher/CMakeLists.txt

    if(WIN32)
    install(FILES 
      ${PROJECT_SOURCE_DIR}/3rdParty/opencv/x64/vc16/bin/opencv_world490.dll
      TYPE BIN 
      DESTINATION ${CMAKE_INSTALL_BINDIR})
    else()

使用

将编译的库集成到其他项目中

编译完成后,可以在安装目录下找到 templatematching.dlltemplatematching_ctype.dll

C++

c++编译时只需要引入头文件即可,dll是在运行时加载的,只需要 templatematching.dll,详细调用参考 demo.cpp

python

python使用时需要将 templatematching.dlltemplatematching_ctype.dll 放进运行目录,演示代码参考 py_demo.py

opencv_matching's People

Contributors

acai66 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.