简体   繁体   English

opencv倒角距离C++代码缺少头文件

[英]opencv chamfer distance C++ code missing header file

I am trying the compile the following code to compute the chamfer distance.我正在尝试编译以下代码来计算倒角距离。 However I get the following error while compiling it.但是我在编译时遇到以下错误。 I am using opencv-3.2 on ubuntu 18.04, 64 bit.我在 64 位 ubuntu 18.04 上使用 opencv-3.2。

fatal error: opencv2/contrib/contrib.hpp: No such file or directory

Synaptic package manager says that libopencv-contrib-dev and libopencv-contrib-3.2 are installed at /usr/include/opencv2 and /usr/lib/x86_64-linux-gnu respectively. Synaptic 包管理器说 libopencv-contrib-dev 和 libopencv-contrib-3.2 分别安装在 /usr/include/opencv2 和 /usr/lib/x86_64-linux-gnu。 I checked for contrib.hpp but found no file or folder named contrib in these locations.我检查了 contrib.hpp 但在这些位置没有找到名为 contrib 的文件或文件夹。

The code for the chamfer distance computation is as below:倒角距离计算代码如下:

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"
#include <iostream>

using namespace cv;
using namespace std;

int main( int argc, const char** argv )
{
    Mat img = imread(argv[1], 0);
    Mat tpl = imread(argv[2], 0);

    Mat cimg;
    cvtColor(img, cimg, CV_GRAY2BGR);

    vector<vector<Point> > results;
    vector<float> costs;
    int best = chamerMatching( img, tpl, results, costs );

    return 0;
}

My question is: How to add the correct headers and get the above chamfer distance code working in opencv 3.2?我的问题是:如何添加正确的标题并使上述倒角距离代码在 opencv 3.2 中工作?

It looks like the contrib module is not available in OpenCV 3.2.看起来 contrib 模块在 OpenCV 3.2 中不可用。 This module was removed in OpenCV 4.0 and is no longer part of the library.If you want to use the Chamfer matching algorithm in your code, you can try using the matchShapes function from the imgproc module instead.这个模块在 OpenCV 4.0 中被移除,不再是库的一部分。如果你想在你的代码中使用 Chamfer 匹配算法,你可以尝试使用 imgproc 模块中的 matchShapes 函数。 This function can be used to compare the shapes of two contours and return a measure of their similarity此函数可用于比较两个轮廓的形状并返回它们相似性的度量

 #include "opencv2/imgproc/imgproc.hpp" #include "opencv2/highgui/highgui.hpp" #include <iostream> using namespace cv; using namespace std; int main( int argc, const char** argv ) { Mat img = imread(argv[1], 0); Mat tpl = imread(argv[2], 0); // Find the contours of the images vector<vector<Point> > img_contours; vector<vector<Point> > tpl_contours; findContours(img, img_contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); findContours(tpl, tpl_contours, RETR_EXTERNAL, CHAIN_APPROX_NONE); // Compute the Chamfer distance between the contours double chamfer = matchShapes(img_contours[0], tpl_contours[0], CHAMFER_DIST_L2, 0); cout << "Chamfer distance: " << chamfer << endl; return 0; }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM