在 iOS 中检查图像中是否存在子图像 [英] Check presence of subimage in image in iOS

查看:29
本文介绍了在 iOS 中检查图像中是否存在子图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 张图片,分别是 smallImage 和 largeImage.现在,我想检查smallerImage 是否是largerImage 的一部分(或子图像).我不知道如何检查.我想在 iOS 中完成这一切.在搜索之后,我发现使用 openCV 库是用于此类东西的最佳库.但我不知道如何使用 openCV 库来执行我的任务.

I have 2 images, say smallerImage and largerImage. Now, I want to check that does smallerImage is part(or subimage) of largerImage or not. I am not getting how to check that. I want to so this whole stuff in iOS. After gogling, i got that using openCV library is best library to use for such a stuff. But i am not getting how to use openCV library to perform my task.

总之,我想知道,

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

1) What are the different techniques/methods/algorithms to find/check subimage in larger image

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

2) How to use openCV Library to perform (1).(i.e. how to use it to check subimage in larger image)

推荐答案

可以使用OpennCV模板匹配算法..

You can use OpennCV Template Matching algorithm..

请尝试一下..

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

download opencv2.framework from https://github.com/Fl0p/OpenCV-iOS

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

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

import files 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;
 }
}

这篇关于在 iOS 中检查图像中是否存在子图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆