1

I have a set of images that represent a character (letter 'O') handwritten in different ways. I want to match that with an image of handwritten text and draw a box around it. I came across using the Template matching algorithm, but that is not giving the output I expected. I have been trying various feature matching algorithms, and I am fairly new to Image Processing. I am doing this with OpenCV 3.4.9 and Java where I'm testing it on desktop and I later want to convert it into an app. Here is what is happening with 1 image of the letter 'O' and the sample handwritten text.:

EDIT: Had to repost the question, as my previous question was cancelled due to incorrect phrasing of question

The letter 'O' image that is handwritten that is needed for matching.

The handwritten text image that is the letter 'O' needs to be matched with.

The output I am getting where the box is drawn at the incorrect place in the image.

The expected output that I am supposed to get.

The code I have is as follows (based on article I found a while back):

import org.opencv.core.Core;
import org.opencv.core.Core.MinMaxLocResult;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

public class TemplateMatch {

  public static void main(String[] args) {

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    Mat source=null;
    Mat template=null;
    String filePath="./pics/";
    //Load image file
    source=Imgcodecs.imread(filePath+"HandText.jpg");
    template=Imgcodecs.imread(filePath+"o.png");

    Mat outputImage=new Mat();    
    int machMethod=Imgproc.TM_CCOEFF;
    //Template matching method
    Imgproc.matchTemplate(source, template, outputImage, machMethod);


    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(255, 255, 255));

    Imgcodecs.imwrite(filePath+"output.jpg", source);
    System.out.println("Completed.");
   }

}

Any help or advice will be highly appreciated as to which I can move forward to achieve this.

0 Answers0