Guest User

Untitled

a guest
Apr 24th, 2015
289
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void run(String inFile, String templateFile, String outFile, int match_method) {
  2. System.out.println("\nRunning Template Matching");
  3.  
  4.  
  5.  
  6.  
  7. Mat img = Highgui.imread(inFile);
  8. Mat templ = Highgui.imread(templateFile);
  9.  
  10. // / Create the result matrix
  11. int result_cols = img.cols() - templ.cols() + 1;
  12. int result_rows = img.rows() - templ.rows() + 1;
  13. Mat result = new Mat(result_rows, result_cols, CvType.CV_32FC1);
  14.  
  15. // / Do the Matching and Normalize
  16. Imgproc.matchTemplate(img, templ, result, match_method);
  17. Core.normalize(result, result, 0, 1, Core.NORM_MINMAX, -1, new Mat());
  18.  
  19. Point matchLoc;
  20. Point maxLoc;
  21. Point minLoc;
  22.  
  23. MinMaxLocResult mmr;
  24.  
  25. boolean iterate = true;
  26. while(iterate){
  27.  
  28. // / Localizing the best match with minMaxLoc
  29. mmr = Core.minMaxLoc(result);
  30. matchLoc = mmr.maxLoc;
  31.  
  32.  
  33. if(mmr.maxVal < 0.8)
  34. {
  35. iterate = false;
  36. }
  37.  
  38.  
  39.  
  40. // / Show me what you got
  41. Core.rectangle(img, matchLoc, new Point(matchLoc.x + templ.cols(),
  42. matchLoc.y + templ.rows()), new Scalar(0, 255, 0));
  43.  
  44. }
  45.  
  46. // Save the visualized detection.
  47. System.out.println("Writing "+ outFile);
  48. Highgui.imwrite(outFile, img);
  49.  
  50. }
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×