/// <summary> /// The method responsible for image calculations (among others the image similarity score calculations and time of mething calc. /// </summary> /// <param name="s_testImage"> The test image directory. </param> /// <param name="s_basicImage"> The basic library image directory. </param> /// <returns> Method returns a tuple, which contains score and matching time fields. </returns> KeyValuePair <long, double> ComputeImage(string s_testImage, string s_basicImage) { ErrInfLogger.LockInstance.InfoLog("Start of the ComputeImages"); long l_score; double l_matchTime; using (Mat m_modelImage = CvInvoke.Imread(s_basicImage, ImreadModes.Color)) { using (Mat m_observedImage = CvInvoke.Imread(s_testImage, ImreadModes.Color)) { Mat m_homography; VectorOfKeyPoint v_modelKeyPoints; VectorOfKeyPoint v_observedKeyPoints; using (VectorOfVectorOfDMatch v_matches = new VectorOfVectorOfDMatch()) { Mat m_mask; DrawMatches.FindMatch(m_modelImage, m_observedImage, out l_matchTime, out v_modelKeyPoints, out v_observedKeyPoints, v_matches, out m_mask, out m_homography, out l_score); string s_score = "The score obtained is " + l_score.ToString(); string s_matchTime = "The time to obtain score is " + l_matchTime.ToString() + " ms"; ErrInfLogger.LockInstance.ScoreLog(s_score); ErrInfLogger.LockInstance.MTimeLog(s_matchTime); } l_imgList.Add(new ImageParameters() { s_ImagePath = s_testImage.Remove(0, SettingsContainer.Instance.i_TestImageOffset), s_ImageBasicPath = s_basicImage.Remove(0, SettingsContainer.Instance.i_BasicImageOffset), l_Score = l_score, l_MatchTime = l_matchTime }); } } ErrInfLogger.LockInstance.InfoLog("End of the ComputeImages"); return(new KeyValuePair <long, double>(l_score, l_matchTime)); }
/// <summary> /// /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnMatch_Click(object sender, EventArgs e) { long matchTime; using (Mat modelImage = CvInvoke.Imread("Template.png", ImreadModes.Grayscale)) using (Mat observedImage = CvInvoke.Imread("1456141019_地理_p1.tif", ImreadModes.Grayscale)) { VectorOfKeyPoint vectorOfKeyPoint = new VectorOfKeyPoint(); VectorOfKeyPoint vectorOfKeyPointObserved = new VectorOfKeyPoint(); VectorOfVectorOfDMatch vectorOfDMatch = new VectorOfVectorOfDMatch(); MDMatch[][] mDMatch = vectorOfDMatch.ToArrayOfArray(); Mat mask = null; Mat homography = null; DrawMatches.FindMatch(modelImage, observedImage, out matchTime, out vectorOfKeyPoint, out vectorOfKeyPointObserved, vectorOfDMatch, out mask, out homography); } }