我是计算机视觉的初学者。我目前正在开发一个项目,以在 iOS 中使用 matchTemplate 查找两个图像之间的匹配。我面临的问题是找到一种方法来确定两个图像是否匹配,尽管 matchTemplate运行良好。我想采用结果矩阵的百分比,但我不知道如何也找不到方法。MinMaxLoc 也没有与我合作。如果有人可以帮助我或给我一个想法,我将非常感激,因为我现在处于绝望的境地。这是代码:`
UIImage* image1 = [UIImage imageNamed:@"1.png"]; UIImage* image2 = [UIImage imageNamed:@"Image002.png"];
// Convert UIImage* to cv::Mat
UIImageToMat(image1, MatImage1);
UIImageToMat(image2, MatImage2);
MatImage1.resize(100 , 180);
MatImage2.resize(100 , 180);
if (!MatImage1.empty())
{
// Convert the image to grayscale
//we can also use BGRA2GRAY : Blue , Green , Red and Alpha(Opacity)
cv::cvtColor(MatImage1, grayImage1, cv::COLOR_BGRA2GRAY );
cv::cvtColor(MatImage2, grayImage2, cv::COLOR_BGRA2GRAY);
}
/// Create the result matrix
int result_cols = grayImage1.cols ;
int result_rows = grayImage1.rows ;
result.create( result_cols, result_rows, CV_32FC1 );
/// Do the Matching and Normalize
matchTemplate( grayImage1 , grayImage2 , result , CV_TM_SQDIFF_NORMED);
//Normalize
normalize( result, result, 0, 100, cv::NORM_MINMAX, -1 );
//Threshold
cv::threshold(result , result , 30, 0, CV_THRESH_TOZERO);`