在iOS中检查子图像是否存在于图像中

我有两张图片,分别称为smallerImage和largerImage。现在,我想检查smallerImage是否是largerImage的一部分(或子图像)。我不知道如何进行检查。我想在iOS中完成这项工作。经过谷歌搜索,我发现使用openCV库是处理此类任务的最佳选择。但我不知道如何使用openCV库来完成我的任务。

简而言之,我想了解,

1) 查找/检查大图像中子图像的不同技术/方法/算法

2) 如何使用openCV库来执行(1)。(即如何使用它来检查大图像中的子图像)


回答:

你可以使用OpenCV的模板匹配算法…

请尝试一下…

https://github.com/Fl0p/OpenCV-iOS下载opencv2.framework

https://github.com/aptogo/OpenCVForiPhone/tree/master/OpenCVClient下载UIImage+OpenCV

导入文件opencv2/nonfree/nonfree.hpp, opencv2/highgui/highgui.hpp, opencv2/calib3d/calib3d.hpp, UIImage+OpenCV.h

使用以下函数进行图像匹配。

-(BOOL) matchImages:(UIImage*)largerImage Image2:(UIImage*)subImage{ cv::Mat tempMat1 = [largerImage CVMat]; cv::Mat tempMat2 = [subImage CVMat]; cv::Mat result; int match_method = CV_TM_SQDIFF_NORMED; //cv::cvtColor(tempMat1, debug, CV_GRAY2BGR); //cv::cvtColor(tempMat1, tempMat1, cv::COLOR_RGB2GRAY); //cv::cvtColor(tempMat2, tempMat2, cv::COLOR_RGB2GRAY); int result_cols =  tempMat1.cols - tempMat2.cols + 1; int result_rows = tempMat1.rows - tempMat2.rows + 1; result.create( result_cols, result_rows, CV_32FC1 ); /// Do the Matching and Normalize cv::matchTemplate( tempMat1,tempMat2 ,result,match_method); double minVal; double maxVal; cv::Point minLoc, maxLoc, matchLoc; cv::minMaxLoc(result, &minVal, &maxVal, &minLoc, &maxLoc, cv::Mat() ); if( match_method == CV_TM_SQDIFF || match_method == CV_TM_SQDIFF_NORMED ) matchLoc = minLoc; else matchLoc = maxLoc;//NSLog(@"%d %d",tempMat1.cols,tempMat1.rows);NSLog(@"%f %f",minVal,maxVal); if (minVal < 0.25) {     NSLog(@"success");     //cv::rectangle(tempMat1,matchLoc,cv::Point(matchLoc.x + tempMat2.cols , matchLoc.y + tempMat2.rows),CV_RGB(255,0,0),3);     //UIImage *resImage = [[UIImage alloc] initWithCVMat:tempMat1];     //UIImageView * imageview = [[UIImageView alloc] initWithImage:resImage];     //[imageview setFrame:CGRectMake(0, 0, resImage.size.width, resImage.size.height)];     //[self.view addSubview:imageview];     return YES; } else {    return NO; }}

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注