Signature detection over a black line

Hi,
I’m fairly new to OpenCV and need some advice on the best pattern to follow to detect if a straight black line has some signature over.
I’ve tried using template matching but the amount of false positives/negatives It’s high.
Actually I’m matching the empty sign-zone with the images I have and if I find a match over a threshold I mark the document as unsigned.
Here is the relevant part:

String sourcefile="document.png";
String template ="unsigned.png";
Mat template = Imgcodecs.imread(templatefile);
Mat source      = Imgcodecs.imread(sourcefile);
int machMethod=Imgproc.TM_CCOEFF_NORMED;
Imgproc.matchTemplate(source, template, outputImage, machMethod);
        
//Localizing the best match with minMaxLoc
MinMaxLocResult mmr = Core.minMaxLoc(outputImage);
Point matchLoc=mmr.maxLoc;
//Draw rectangle on result image
Imgproc.rectangle(source, matchLoc, new Point(matchLoc.x + template.cols(),matchLoc.y + template.rows()), new Scalar(0, 255, 0),4);

boolean signed=true;
if(mmr.maxVal>=0.75) {
   	signed=false;
}

I’ve tried improving the algorithm using the Core.compare() functionality between the template and the rectangle defined by the best match, and then using Core.countNonZero() to have another threshold but I don’t get significative estimates of the equality:

Rect rect = new Rect((int)matchLoc.x,(int)matchLoc.y,template.cols(),template.rows());
Mat rectangle= source.submat(rect);
Mat mat = new Mat();
Mat templatetemp = template.clone();
Imgproc.cvtColor(templatetemp, templatetemp, Imgproc.COLOR_BGR2GRAY);
Imgproc.cvtColor(rectangle, rectangle, Imgproc.COLOR_BGR2GRAY);
Core.compare(rectangle, templatetemp, mat, Core.CMP_NE);
int equalsScore = Core.countNonZero(mat);
System.out.println(equalsScore);

Thanks in advance for any help/suggestion
Edit:code formatting