how to set the threshold for matchtemplate result in cpp?

asked 2019-02-12 02:50:07 -0600

updated 2019-02-12 05:07:32 -0600

Hi, I want to set the threshold for the matchtemplate result,

In this python tutorial link, you can check the last example.

It is a easy job in python, you can use np.where( im > threshold), to get it done. Which also shown in the example code,

But I don't know how to make in cpp.

Seems no numpy tool in cpp.

I check the stack overflow link

And use the syntax Mat >threshold but seems not work. I use the image watch extension in Vi sual Studio, and get the totally white result.

image description.

So how to make the threshold for the result in cpp.

---update---

Thanks for all the reply.

I already make it.

I wrote a post to answer this question but don't why is gone after I click the "answer" button...

Make it brief, I want to use threshold to filter the matchtemplate result in cpp. All code is here, the key points are : * normalize( result, result, 0, 1, NORM_MINMAX, -1, Mat() ); so the result can be thresholded by the value in the range(0~1) which is more convenient.

  • Mat threshold_im = result > 0.9 // filter the points which is matched.

  • findNonZero(threshold_im, locations); //// find the matched points

Really unfamiliar with the post syntax... bad format sorry...

I upload the code, if any one use it. Maybe just me need it :D code link

edit retag flag offensive close merge delete

Comments

your post is puzzle. Can you post your code here ? What's the problem with > ?

    RNG rng(12345);
    Mat xx(4, 4, CV_32FC1);
    rng.fill(xx, RNG::UNIFORM, 0, 1.0);
    Mat mask = xx > 0.5;
    cout << xx << "\n";
    cout << mask<<"\n";



[0.65891916, 0.30409056, 0.72526598, 0.64147365;
 0.73484641, 0.9258911, 0.4439666, 0.89688575;
 0.67402214, 0.65468955, 0.72392988, 0.63825119;
 0.40503168, 0.28632703, 0.32454264, 0.049986243]
[255,   0, 255, 255;
 255, 255,   0, 255;
 255, 255, 255, 255;
   0,   0,   0,   0]
LBerger gravatar imageLBerger ( 2019-02-12 03:01:22 -0600 )edit

https://docs.opencv.org/master/de/da9...

@woshichuanqilz -- and please, NO screenshots of code here. ;(

berak gravatar imageberak ( 2019-02-12 03:35:25 -0600 )edit

if you want to threshold on a probability of a match, you MUST NOT normalize it (the max will be always 1)

berak gravatar imageberak ( 2019-02-12 05:56:37 -0600 )edit