Search code examples
javaopencvjavacv

How to use template matching to identify different size of objects in opencv/javacv?


I went through couple of template matching tutorials and I had noticed that most of the tutorials try to match the template which crop from original image. But I would like to know whether is it possible to identify similar objects with different widths and heights ?

In my project I have following type of image which I generated.

enter image description here

and I need to identify following components from it.

enter image description here

enter image description here

enter image description here

How can I archive this using opencv or javacv?? Is it possible to use template matching for this? Because this objects can be in different sizes so is it possible to use it? Please can some one give simple code example to identify this objects ?


Solution

  • I'm not sure that it helps you in real situation, but simple threshold did the trick on your input image:

    enter image description here

    Code:

    Mat src = imread("input.jpg"), tmp;
    cvtColor(src, tmp, CV_BGR2GRAY);
    threshold(tmp, tmp, 200, 255, THRESH_BINARY);