justadudewhohacks / justadudewhohacks/opencv4nodejs
Help Wanted: How to use Mat.matchTemplate correctly
- Dominant language
- C++
- Stars
- 5.1k
- Forks
- 826
- PR merge metrics
- No merged PRs in 30d
Description
*OpenCV version* (example 3.4.1): 4.3.0
*With OpenCV-contrib?* (extra modules): yes
*OS*: Windows 7 / 8 / 10? / MacOSX? / Ubuntu? Ubuntu 18.04 (Docker)
Hi,
I'm using code very similar to:
https://github.com/justadudewhohacks/opencv4nodejs/blob/master/examples/templateMatching.js
The only difference is that I'm using fastify on my server and I'm writing the output to disk and then reading it before sending it as the reply. I can attach the exact code if required but the rest is pretty much identical to the above link.
I'd like to use this tool to read in different UI states of games so that I can add more info to my streams, here's an example of a template I'm using:

I'm trying to identify the weapon the gamer has equipped, so I've loaded in the following template mask:

It looks like things are working to some extent, though the boundary box I'm outputting (using `drawRectangle`) is massive - because of the size of the mask? I don't know how to get opencv to show the correct placement/size.

But then I decided to test the same template for a different mask:

When I run the detection again, there's another hit in the picture (different place)

The second hit shouldn't have occurred as that gun doesn't exist in the original picture.
Can anyone help me understand what I'm doing wrong, I'm totally new to these tools but I'd love to achieve my original goal of: **Is this weapon equipped? - Y/N**
P.s. I'm not the guy in the actual picture, I just went onto Twitch to find someone playing 😛
Contributor guide
Research direction
Start with examples/templateMatching.js and the Mat.matchTemplate and drawRectangle usage described in the report. Reproduce both template cases with the supplied images and compare the match result and rectangle dimensions; done means the intended weapon is distinguished from the false hit and the output box has the expected size.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs
- Domain
- computer-vision
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100