title: How to check and convert image data types in OpenCV using Python
body: <p>I'm using various methods in <code>OpenCV</code> to preprocess some images. I often get errors relating to the data type when passing objects been methods eg:</p>
  
  <pre><code>import cv2
  import numpy as np
  
  #import image and select ROI
  image1 = cv2.imread('image.png')
  roi_1 = cv2.selectROI(image1) # spacebar to confirm selection
  cv2.waitKey(0)
  cv2.destroyAllWindows()
  
  # preprocesssing
  imCrop_1 = image1[int(roi_1[1]):int(roi_1[1]+roi_1[3]), int(roi_1[0]):int(roi_1[0]+roi_1[2])]
  grey1 = cv2.cvtColor(imCrop_1, cv2.COLOR_RGB2GRAY)
  thresh, bw_1 = cv2.threshold(grey1, 200, 255, cv2.THRESH_OTSU)
  canny_edge1 = cv2.Canny(bw_1, 50, 100)
  
  #test=roi_1 # Doesn't work with error: /home/bprodz/opencv/modules/photo/src/denoising.cpp:182: error: (-5) Type of input image should be CV_8UC3 or CV_8UC4! in function fastNlMeansDenoisingColored
  #test = imCrop_1 # works
  #test = grey1 # doesn't work with error above
  #test = bw_1 # doesn't work with error above
  #test = canny_edge1 # doesn't work with error above
  
  dst = cv2.fastNlMeansDenoisingColored(test,None,10,10,7,21)
  
  # Check object types
  type(imCrop_1) # returns numpy.ndarray - would like to see ~ CV_8UC3 etc.
  type(grey1) # returns numpy.ndarray
  </code></pre>
  
  <p>Presently I just use trial and error, is a there a more methodical approach that I can use for checking and converting between different object types?</p>