LoginSignup
4
3

More than 5 years have passed since last update.

指定の画像に別の画像が含まれるか検出

Posted at

指定した画像内に別の画像が含まれているかどうかを検出する関数。

一致率が90%以上なら真を返す

detectImage
// 指定画像が高確率で検知できているかを検出
bool detectImage(IplImage *img,char* imageName){
  double min_val, max_val;
  CvPoint min_loc, max_loc;
  IplImage *templateImage,*dstImage;
  CvSize dst_size;

  templateImage = cvLoadImage (imageName, CV_LOAD_IMAGE_COLOR);

  dst_size = cvSize (img->width - templateImage->width + 1, img->height - templateImage->height + 1);

  dstImage = cvCreateImage (dst_size, IPL_DEPTH_32F, 1);
  cvMatchTemplate (img, templateImage, dstImage, CV_TM_CCOEFF_NORMED);
  cvMinMaxLoc (dstImage, &min_val, &max_val, &min_loc, &max_loc, NULL);

  return (max_val>0.9);
}
4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3