我正在使用倒角匹配来匹配模板和参考图像。我正在使用OpenCV'r chamermatching()方法。我得到了匹配的分数,但我怎样才能得到这些信件?换句话说,对应于每个成本,我如何获得模板点参考图像点对应?提前谢谢!
我使用以下代码:
int main( int argc, const char** argv )
{
Mat img = imread(argv[1], 0);
Mat tpl = imread(argv[2], 0);
GaussianBlur(img, img, cv::Size(3, 3), 4.0);
GaussianBlur(tpl, tpl, cv::Size(3, 3), 4.0);
imshow("Image", img);
imshow("Template", tpl);
if (img.empty() || tpl.empty())
{
cout << "Could not read image files";
return -1;
}
Mat cimg;
cvtColor(img, cimg, COLOR_GRAY2BGR);
// if the image and the template are not edge maps but normal grayscale images,
// you might want to uncomment the lines below to produce 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;
}
cout << results.size() << endl;
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);
float total_cost = 0.0;
for(int i=0;i<costs.size();i++)
total_cost += costs[i];
cout << total_cost << "\n";
waitKey();
return 0;
}