I am trying to modify the TemplateMatching example. with example images. If the template is in the image, we are good. But if it is not, it is still showing a rectangle. Can I modify a threashold or get a score, or a flag (isFound) to know if the template was found?
Sure, we can make a decision based on maxVal, for example.
When I print MaxVal, in both the matching and non-matching cases, the results are the same:
org.bytedeco.javacpp.DoublePointer[address=0x0,position=0,limit=0,capacity=0,deallocator=null]
How to make decision then?
Try to pass a non-null pointer...
Mat sourceGrey = new Mat(sourceColor.size(), CV_8UC1);
cvtColor(sourceColor, sourceGrey, COLOR_BGR2GRAY);
// load in template in grey
Mat template = imread(split, IMREAD_GRAYSCALE);// int = 0
// Size for the result image
Size size = new Size(sourceGrey.cols() - template.cols() + 1, sourceGrey.rows() - template.rows() + 1);
Mat result = new Mat(size, CV_32FC1);
matchTemplate(sourceGrey, template, result, TM_CCORR_NORMED);
DoublePointer minVal = new DoublePointer();
DoublePointer maxVal = new DoublePointer();
Point min = new Point();
Point max = new Point();
minMaxLoc(result, minVal, maxVal, min, max, null);
=====================================
minVal maxVal return null
@o21x Try this:
DoublePointer minVal = new DoublePointer(1);
DoublePointer maxVal = new DoublePointer(1);
Point min = new Point(1);
Point max = new Point(1);
minMaxLoc(result, minVal, maxVal, min, max, null);
@saudet thanks buddy! it works!
minMaxLoc says pass null if not use , comment should be edit ^_^
The problem isn't with the call to minMaxLoc(), it's with the code that comes after that.