Ask Your Question

jas's profile - activity

2020-01-06 08:31:33 -0600 received badge  Popular Question (source)
2017-07-11 14:08:24 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

For the Update 3, Supposing i would like to utilise the template matching method's CCOEFF_NORMED/CCORR_NORMED. I would be utilising the maxVal. If it's a proper match then maxVal is 1.0 and 0.0 if it's not a good match. Should there be any other changes that i should be making when trying to find the next match or drawing the rectangle?

2017-07-11 04:43:11 -0600 commented answer Can template matching be used to identify the exact image on the screen if the image is present multiple times on the screen?{ Opencv Java}

@pklab, could you share your investigation details on the issue you have mentioned above?

2017-07-11 00:24:31 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

Just to get a bit more clarity, in case I need to identify only the "exact" matches, is this the only way? "Despite of above code works (on 1channel images) it is really inefficient. The way templateMatch/CV_TM_SQDIFF is much faster and general. "

2017-07-09 13:23:55 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

I'm using opencv version 3.1.0 which has the Imgproc.rectangle methods:

1) (Mat img, Point pt1, Point pt2,Scalar color,int thickness, int lineType, int shift)

2) (Mat img, Point pt1, Point pt2,Scalar color,int thickness)

3) (Mat img, Point pt1, Point pt2,Scalar color)

I'm unable to utilise your solution because of this.

2017-07-08 13:22:29 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

@pklab I'm sorry I didn't check the dissimilarity of the image in the first place. My bad!

2017-07-07 04:57:14 -0600 answered a question Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

I'm unable to figure out a proper threshold value(this is an experimental value) in order to get the co-ordinates of images on the screen multiple times. So I can't use template match/TM_SQDIFF. I guess i'll have to stick with the approach you have given.

Having said that I’m facing another issue. Consider this as my template image and source image respectively. Template Source

With your approach I’m able to identify the images on the right. That is top-right has an index 1 and bottom-right has an index 2.

The image on the left is a bit different from the others. (Was able to see the difference only when I zoomed in to 800%)!! (Highlighted the differences)

Difference

Ideally, i should be able to identify all the 3 images. Is there a way in which I can identify the image on the left as well with the current approach? I would like to know if there's some way where in we can avoid the differences before we do the matching.

UPDATE:

Tried your suggestion .Unable to get the co-ordinates of other similar images on the screen. (Also tried other Thresholding methods TRUNC,BINARY). Able to get the co-ordinates for the top-right image.

Imgproc.matchTemplate(sourceGrayed, templateGrayed, resultMatrix, Imgproc.TM_SQDIFF_NORMED);
        // Core.normalize(resultMatrix, resultMatrix, 0, 1, Core.NORM_MINMAX,
        // -1);
        Imgproc.threshold(resultMatrix, resultMatrix, 0, 1, Imgproc.THRESH_TOZERO);

        while (true) {
            MinMaxLocResult mmr = Core.minMaxLoc(resultMatrix);
            Point matchLoc;
            matchLoc = mmr.minLoc;
            if (mmr.minVal <= 1.0) {
                Imgproc.rectangle(templateGrayed, matchLoc,
                        new Point(matchLoc.x + sourceGrayed.cols(), matchLoc.y + sourceGrayed.rows()),
                        new Scalar(0, 255, 0));
                Imgproc.rectangle(resultMatrix, matchLoc,
                        new Point(matchLoc.x + sourceGrayed.cols(), matchLoc.y + sourceGrayed.rows()),
                        new Scalar(0, 255, 0), -1);

                mmrList.add(mmr);
2017-07-07 01:37:18 -0600 received badge  Enthusiast
2017-07-06 01:12:08 -0600 marked best answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

I gather that template matching only gives us the "best possible location of the image" and not the location of the exact image.

2017-07-06 01:12:06 -0600 received badge  Supporter (source)
2017-07-05 16:38:38 -0600 commented answer Can template matching be used to identify the exact image on the screen if the image is present multiple times on the screen?{ Opencv Java}

@berak. your code works fine! There was an issue with my image. The image on the left had very minor difference with the one i'm comparing to.(Had to zoom in to 800% !!). Sorry for the inconvenience caused.

2017-07-05 16:34:48 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

This works!!

2017-07-05 06:11:27 -0600 commented answer Can template matching be used to identify the exact image on the screen if the image is present multiple times on the screen?{ Opencv Java}

@berak is there some tweak i can do to identify the 3rd image also?

2017-07-04 16:01:29 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

Sorry, my bad. I have made the change. Still, i'm getting the final size as 274510!!(definetly wrong!)(nx=485,ny=566). Where as the target image is present only thrice in the screen. The exact match is not at 0,0.

I forgot to mention in my previous comment, i have converted my Matrices to greyscale in order to avoid this error. OpenCV Error: Assertion failed ((cn == 1 && (_mask.empty() || _mask.type() == CV_8U)) || (cn > 1 && _mask.empty() && !minIdx && !maxIdx)) in cv::minMaxIdx, file C:\builds\master_PackSlaveAddon-win32-vc12-static\opencv\modules\core\src\stat.cpp (Occurs at Core.minMaxLoc(delta) )

2017-07-04 12:50:04 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

I have tried using the method you have suggested. However, minmaxLoc doesn't return me valid values. (minLoc,maxLoc,minVal,maxVal all return 0.0). Is there something i'm doing wrong/missing?

     for (int x = 0; x < nx; x++) { 
for (int y = 0; y < ny; y++) {
                    Mat Ir = templateGrayed.submat(R);
                    Core.absdiff(templateGrayed, Ir, delta);
                    MinMaxLocResult co = Core.minMaxLoc(delta);
                    // max==0 means delta == 0 means exact match
                    if (co.maxVal == 0) {
                        match = co.maxLoc;
                        System.out.print("Exact found at ");
                        System.out.print(match);
                        System.out.print("\n");
                        matches.add(match);
                    }           }       }       return matches.size();
2017-07-04 08:35:37 -0600 commented answer Can template matching be used to identify the exact image on the screen if the image is present multiple times on the screen?{ Opencv Java}

I'm getting the mmr.minVal as 0 when i use the TM_SQDIFF matching method. I'm able to get the co-ordinates of the template using the minLoc.

The issue i'm facing with the code i have mentioned above is that i'm able to identify the images which differ only on the y co-ordinates. I'm unable to identify the object on the left.

link text

I have tried this.

2017-07-04 07:21:24 -0600 commented answer Is template matching the best approach to go about when finding the "Exact" image on the screen multiple times?

I'm trying to this in java, facing an issue at this point

Core.absdiff(T, I(R), delta);

I(R) is not supported in java as such. Can you help me out?