// load image for fast algorithm private void LoadMainImages(string entry) { var pageImageEntries = Directory.GetFiles(entry); Console.WriteLine("(Main Image)"); foreach (var e in pageImageEntries) { string fileName = Utils.GetFileNameInFullEntry(e); if (Utils.CheckIsPNG(e)) { _imageMat = new Mat(e); Console.WriteLine("Load file : " + e); Console.WriteLine("Matrix : " + _imageMat); } } if (_imageMat != null) { Mat imageGray = null; FastMatchSample.FastDescriptor(_imageMat, out _pageDescriptors, out _keypoints, out imageGray); } Console.WriteLine(); }
public int PageScore( int wndStartX, int wndStartY, out double dissimilarity, out double similarity, out string log, bool logging = true) { log = ""; if (_pageDescriptors == null) { dissimilarity = 2000000000.0f; similarity = 0.0f; return(0); } Bitmap printscreen; Utils.CaptureScreen(wndStartX + _fromX, wndStartY + _fromY, _width, _height, out printscreen); _currentMat = Utils.BitmapToMat(printscreen); MatOfFloat discriptors = null; FastMatchSample.FastDescriptor( _currentMat, out discriptors, out _currentKeypoints, out _currentGray); DMatch[][] matches; FastMatchSample.Match(discriptors, _pageDescriptors, 3, out matches); int score = FastMatchSample.Scoring(matches, out dissimilarity, out similarity); if (logging) { log += PageName + " score : " + score + " dissimilarity : " + dissimilarity + " keypoints : " + _currentKeypoints.Length + "\n"; } return(score); }
// load image for fast algorithm private void LoadMainImages(string entry) { var pageImageEntries = Directory.GetFiles(entry); Console.WriteLine("-------------------------- " + _pageName + " -----------------------------"); foreach (var e in pageImageEntries) { string fileName = Utils.GetFileNameInFullEntry(e); _imageMat = new Mat(e); Console.WriteLine("Load file : " + e); Console.WriteLine("Matrix : " + _imageMat); } if (_imageMat != null) { FastMatchSample.FastDescriptor(_imageMat, out _pageDescriptors, out _keypoints, out _imageGray); //FastMatchSample.SiftDescriptor(_imageMat, out _pageDescriptors, out _keypoints, out _imageGray); } Console.WriteLine("-------------------------------------------------------------------------"); }
private void ScoreAllMatchPages(Mat mat) { string mainLog = "--------------------------ScoreAllMatchPages-----------------------------\n"; string maxPageName = Globals.UnknownPage; double maxSimilarity = 0.0f; MatchPage maxPage = null; DateTime start = DateTime.Now; MatOfFloat descriptors = null; _keypoints = null; Mat gray = null; FastMatchSample.FastDescriptor(mat, out descriptors, out _keypoints, out gray); //FastMatchSample.SiftDescriptor(mat, out descriptors, out keypoints, out gray); double dissimilarity; double similarity; string log; if (_currentPageName == Globals.UnknownPage) { foreach (var p in _matchPages) { var page = p.Value; int score = page.PageScore(descriptors, out dissimilarity, out similarity, out log); if (_log) { mainLog += log; } similarity = page.AdditionalCalcSimilarity(mat, similarity); if (similarity > maxSimilarity) { maxSimilarity = similarity; maxPageName = p.Value.PageName; maxPage = page; } } } else { var rPages = _matchPages[_currentPageName].RelatedPages; foreach (var p in rPages) { if (!_matchPages.ContainsKey(p)) { Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!! no Page!!!!!!!!!!!!!!!!!!!!!! [" + p + "]"); continue; } var page = _matchPages[p]; int score = page.PageScore( descriptors, out dissimilarity, out similarity, out log); if (_log) { mainLog += log; } similarity = page.AdditionalCalcSimilarity(mat, similarity); if (similarity > maxSimilarity) { maxSimilarity = similarity; maxPageName = page.PageName; maxPage = page; } } } if (RenderImageProcess) { if (maxPage != null) { maxPage.RenderKeyPoints(); } Utils.RenderKeyPoints(Globals.ImShowCurrentPageName, mat, _keypoints); } else { Cv2.DestroyWindow(Globals.ImShowMaxMatchPageName); Cv2.DestroyWindow(Globals.ImShowCurrentPageName); } DateTime end = DateTime.Now; var time = (end - start).TotalMilliseconds; if (maxSimilarity > 250.0f) { ChangePage(maxPageName); } else { ChangePage(Globals.UnknownPage); } if (_log /*&& _prevPageName != _currentPageName*/) { mainLog += "\n[" + _currentPageName + "] maxSimilarity : " + maxSimilarity + " total time : " + time + "\n"; mainLog += "-------------------------------------------------------------------------\n\n"; Console.WriteLine(mainLog); } }