OpenCV Error: Assertion failed ((depth == CV_8U || depth == CV_32F)
<p>I know this question has been asked many times before but none of them addresses the problem below. I have two np arrays that are both uint8 but opencv seems to incorrectly think one is 32F. Why is that and how can I fix it in python if I want the match the two images as a template. </p>

<pre><code>    Out[1]: 
array([[  0,   0,   0, ...,   0,   0,   0],
       [  0,  23, 196, ..., 254, 254, 254],
       [  0, 197, 254, ..., 254, 254, 254],
       ..., 
       [  0, 254, 254, ..., 250, 249, 249],
       [  0, 254, 254, ..., 249, 249, 249],
       [  0, 254, 254, ..., 249, 248, 248]], dtype=uint8)


    Out[2]: 
array([[[213, 138,  69],
        [212, 137,  68],
        [212, 138,  66],
        ..., 
        [150,  71,   8],
        [150,  71,   8],
        [150,  71,   8]],
.....
       [[ 27,  22,  12],
        [ 27,  22,  12],
        [ 28,  22,  12],
        ..., 
        [ 17,  11,   1],
        [ 17,  11,   1],
        [ 17,  11,   1]]], dtype=uint8)
</code></pre>

<p>The error is caused when I try to match the templates: </p>

<pre><code>cv2.matchTemplate(img,template,method)
</code></pre>

<p>It may be worth noting that I create the two numpy arrays as follows:
The first one:</p>

<pre><code>img = cv2.cvtColor(np.array(Image.open('new_screenshot.png')), cv2.COLOR_BGR2RGB)
</code></pre>

<p>and the second one:</p>

<pre><code>template = cv2.imread('pics/sn/3d.png',0)
</code></pre>

<p>Yes I know, I could load both with cv2.imread and everything would be fine, but in my case this isn't possible because I need PIL in my exmple (for making screenshots <code>img = cv2.cvtColor(np.array(ImageGrab.grab()), cv2.COLOR_BGR2RGB)</code>) so I need a conversion from PIL to Opencv and I need to get the above example to work.</p>