opencv自带match_to_many_images没有result输出

发布网友 发布时间:2022-04-22 05:23

我来回答

2个回答

热心网友 时间:2024-02-06 10:09

OpenCV封装了很多各种各样的匹配函数,如果想简单一点解决你的问题,你可以试试用chamerMatching函数。这个是C++程序,OpenCV2.0.0之后的版本应该都有(没有查,手头上只有2.4.4和2.4.6,都是有的)。顺便附上简单的代码,你可以试试。

#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/contrib/contrib.hpp"

#include <iostream>

using namespace cv;
using namespace std;

void help()
{

cout << "\nThis program demonstrates Chamfer matching -- computing a distance between an \n"
"edge template and a query edge image.\n"
"Usage: \n"
"./chamfer <image edge map> <template edge map>,"
" By default the inputs are logo_in_clutter.png logo.png\n";
}

const char* keys =
{
"{1| |logo_in_clutter.png|image edge map }"
"{2| |logo.png |template edge map}"
};

int main( int argc, const char** argv )
{

help();
CommandLineParser parser(argc, argv, keys);

string image = parser.get<string>("1");
string templ = parser.get<string>("2");
Mat img = imread(image.c_str(), 0);
Mat tpl = imread(templ.c_str(), 0);

if (img.empty() || tpl.empty())
{
cout << "Could not read image file " << image << " or " << templ << "." << endl;
return -1;
}
Mat cimg;
cvtColor(img, cimg, CV_GRAY2BGR);

// if the image and the template are not edge maps but normal grayscale images,
// you might want to uncomment the lines below to proce the maps. You can also
// run Sobel instead of Canny.

// Canny(img, img, 5, 50, 3);
// Canny(tpl, tpl, 5, 50, 3);

vector<vector<Point> > results;
vector<float> costs;
int best = chamerMatching( img, tpl, results, costs );
if( best < 0 )
{
cout << "matching not found" << endl;
return -1;
}

size_t i, n = results[best].size();
for( i = 0; i < n; i++ )
{
Point pt = results[best][i];
if( pt.inside(Rect(0, 0, cimg.cols, cimg.rows)) )
cimg.at<Vec3b>(pt) = Vec3b(0, 255, 0);
}

imshow("result", cimg);

waitKey();

return 0;
}

热心网友 时间:2024-02-06 10:10

在程序最后面加一个waitkey(0);试一试。你的结果是输出在控制台?追问不是,我用的是opencv自带的一个例程,应该是输出一个result的图片吧,只是运行后没有有输出图片,在控制台出现了图片里的东西

追答你截图控制台我看看。你用的那个例程,我试试,我电脑又opencv249

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com