繁体   English   中英

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

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

我正在尝试编译以下代码来计算倒角距离。 但是我在编译时遇到以下错误。 我在 64 位 ubuntu 18.04 上使用 opencv-3.2。

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

Synaptic 包管理器说 libopencv-contrib-dev 和 libopencv-contrib-3.2 分别安装在 /usr/include/opencv2 和 /usr/lib/x86_64-linux-gnu。 我检查了 contrib.hpp 但在这些位置没有找到名为 contrib 的文件或文件夹。

倒角距离计算代码如下:

#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;
}

我的问题是:如何添加正确的标题并使上述倒角距离代码在 opencv 3.2 中工作?

看起来 contrib 模块在 OpenCV 3.2 中不可用。 这个模块在 OpenCV 4.0 中被移除,不再是库的一部分。如果你想在你的代码中使用 Chamfer 匹配算法,你可以尝试使用 imgproc 模块中的 matchShapes 函数。 此函数可用于比较两个轮廓的形状并返回它们相似性的度量

 #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