Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>It doesn't seem like OpenCV handles alpha the way you want it to.</p> <p>You have two options:</p> <ol> <li>Write your own cross-correlation method that will use the alpha channel</li> <li>Transform your images so your alpha channel becomes irrelevant</li> </ol> <p>Since the first option is straightforward, I will explore the second option here. I'm going to re-use the sample code I provided to <a href="https://stackoverflow.com/questions/4720168/image-in-image-algorithm/4720228#4720228">a similar question</a> earlier. If you apply cross-correlation directly to your images, the background interferes with the template matching (in particular, light background parts). If you play around with color channels, you will find that matching in the blue channel gives the correct result. This depends on the image content and isn't a consistent way to solve the problem.</p> <p>Another option is to perform edge detection (e.g. <a href="http://en.wikipedia.org/wiki/Sobel_operator" rel="nofollow noreferrer">Sobel</a>) on the image and template, and perform cross-correlation then. Here are the edge detected images (I used the Sobel edge detector on the Luma channel in GIMP, and then some intensity stretching).</p> <p><img src="https://i.stack.imgur.com/P5uDs.png" alt="map"></p> <p><img src="https://i.stack.imgur.com/IVouP.png" alt="building"></p> <p>As you can see, the alpha channel here has become irrelevant, as most of the terrain has become zero intensity and will not contribute to the cross-correlation calculation. So now cross-correlation can be directly applied, giving the desired result:</p> <pre><code>misha@misha-desktop:~/Desktop/stackoverflow$ python cross-correlation.py map-blue.png building-maskz-blue.png (163, 244) </code></pre> <p>Finally, here's <a href="https://stackoverflow.com/questions/4569993/2d-subimage-detection-in-open-cv">another related question</a>.</p> <p>PS. What game is this?</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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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