title: Why cv2.rectangle sometimes return np.ndarray, while sometimes cv2.UMat
body: <p>I'm currently working on visualizing some images and found this weired behaviour of opencv's cv2.rectangle:</p>
  
  <ul>
  <li><p>when input image is an np.ndarray, say arr, cv2.rectangle() returns an np.ndarray, and arr is drawn with a rectangle.</p></li>
  <li><p>when input image is some variant of arr, like arr[:, :, [2, 0, 1]], cv2.rectangle() returns a cv2.UMat, and no rectangle is drawn.</p></li>
  </ul>
  
  <p>My current environment is :</p>
  
  <ul>
  <li>Python 3.7</li>
  <li>Opencv 4.1</li>
  </ul>
  
  <p>Here are the codes:</p>
  
  <ol>
  <li>Firstly generates a random image.</li>
  </ol>
  
  <pre class="lang-py prettyprint-override"><code>import numpy as np
  import cv2
  import copy
  
  img = np.random.randint(0, 255, (100, 120, 3)).astype("uint8")
  </code></pre>
  
  <ol start="2">
  <li>Now add a rectangle</li>
  </ol>
  
  <pre class="lang-py prettyprint-override"><code>a = copy.deepcopy(img)
  ret = cv2.rectangle(a, (0, 0), (10, 10), color=(255, 255, 255), thickness=2)
  </code></pre>
  
  <ol start="3">
  <li><p>You'll find:</p>
  
  <ul>
  <li>ret is an np.ndarray</li>
  <li>visualization of ret and a show that one rectangle is drawn</li>
  </ul></li>
  <li><p>Try another way:</p></li>
  </ol>
  
  <pre class="lang-py prettyprint-override"><code>b = copy.deepcopy(img)
  c = b[:, :, [2, 1, 0]]
  ret = cv2.rectangle(c, (0, 0), (10, 10), color=(255, 255, 255), thickness=2)
  </code></pre>
  
  <ol start="5">
  <li><p>You'll find:</p>
  
  <ul>
  <li>ret is a cv2.UMat</li>
  <li>visualization of ret or c show that <strong>no rectangle is drawn</strong></li>
  </ul></li>
  </ol>
  
  <p>I'm really curious that is there anything wrong with my code? Or there is something hidden behind it?</p>