justadudewhohacks / justadudewhohacks/opencv4nodejs

Help Wanted: How to use Mat.matchTemplate correctly

Open
#713 0 comments 0 reactions 0 assignees View on GitHub
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:
![weapons-equipped](https://user-images.githubusercontent.com/353729/79766310-b8732480-831f-11ea-9f44-a9880f9cfc8a.png)

I'm trying to identify the weapon the gamer has equipped, so I've loaded in the following template mask:
![Item_Weapon_HK416_C](https://user-images.githubusercontent.com/353729/79766373-ce80e500-831f-11ea-9f40-b47307e65f84.png)

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.
![true-hit](https://user-images.githubusercontent.com/353729/79766581-1142bd00-8320-11ea-8387-97c6bab628ad.png)

But then I decided to test the same template for a different mask:
![Item_Weapon_VSS_C](https://user-images.githubusercontent.com/353729/79766602-19026180-8320-11ea-994c-b897fac8e312.png)

When I run the detection again, there's another hit in the picture (different place)
![false-hit](https://user-images.githubusercontent.com/353729/79766643-2881aa80-8320-11ea-994a-11d81bdcf03d.jpg)

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

Open the contributing 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.