private static int bestMatchNum(IplImage source, IplImage[] temp_num, double threshold) { CvSize size = new CvSize( source.GetROI().Width - temp_num[0].Width + 1, source.GetROI().Height - temp_num[0].Height + 1); // 0から9の一致度 double[] max_list = new double[10]; // 0-9の画像とマッチング Parallel.For(0, 10, i => { IplImage result = new IplImage(size, BitDepth.F32, 1); source.MatchTemplate(temp_num[i], result, MatchTemplateMethod.CCoeffNormed); double min; CvPoint min_point, max_point; result.MinMaxLoc(out min, out max_list[i], out min_point, out max_point); }); // 一致度が最大のものを探す double best = 0.0; int best_index = -1; for (int i = 0; i < 10; i++) { double tmp = max_list[i]; if (tmp > best) { best = tmp; best_index = i; } } // しきい値以下の精度であれば切り捨て if (best < threshold) return -1; return best_index; }