Note that there are some explanatory texts on larger screens.

plurals
  1. POAlpha-dependent template matching
    primarykey
    data
    text
    <p>I'm using OpenCV with CUDA / CUBLAS / CUFFT support to perform some very basic template matching on grayscale screenshots to extract some text, meaning I can assume the following:</p> <p>I do know the exact size, color and rotation of the raw sprites I'm trying to match, i.e., I have access to the textures that were used in the observed program's rendering process.</p> <p>However, since the sprites are partially transparent, normal template matching via <code>cv::(gpu::)matchTemplate</code> (using normed cross-correlation) does not work properly, as deviations in transparent regions have too much of a negative influence on the overall correlation.</p> <p>Basically these examples summarize pretty well what I'm trying to achieve:</p> <p>Given the template to be matched and its alpha mask:</p> <p><img src="https://i.stack.imgur.com/rLL4J.png" alt="Sprite template to be matched."><img src="https://i.stack.imgur.com/tsgZn.png" alt="Template alpha mask."></p> <p>I'd like a high to near 100% match on images like these (arbitrary background, random stuff in transparent regions, partially occluded):</p> <p><img src="https://i.stack.imgur.com/Ck1vA.png" alt="Sprite on white background."><img src="https://i.stack.imgur.com/0oXlh.png" alt="Sprite on black background"><img src="https://i.stack.imgur.com/Y7dby.png" alt="Arbitrary background + transparent region partially occluded."><img src="https://i.stack.imgur.com/LmpHc.png" alt="Partially occluded."></p> <p>However, images like these should only yield a very low percentage (wrong color, entirely black): <img src="https://i.stack.imgur.com/0tFsG.png" alt="enter image description here"><img src="https://i.stack.imgur.com/EZwYf.png" alt="enter image description here"></p> <p>Currently I'm using <a href="https://stackoverflow.com/questions/4761940/opencv-template-matching-and-transparency" title="edge detection">edge detection</a> to get some decent matches (Canny + cross-correlation) but as you can see, depending on the background, edges may or may not be present in the image, which produces unreliable results and generally matches very "edgy" areas.</p> <p>I've done some math to come up with an alpha-dependent normed cross-correlation (basically pre-multiplying the alpha mask to both the template and the image) which works fine on paper but is nearly impossible to implement with good performance. And yes, performance is indeed an issue, as multiple sprites (~10) have to be matched in near real-time (~10 FPS) to keep up with the program's speed.</p> <p>I'm sort of running out of ideas here. Are there any standard approaches to this? Any ideas or suggestions?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload