In [1]:
import cv2
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

In [2]:
org_img=cv2.imread('img/circles.png')                # read sample image

min = np.array([0,0,0],np.uint8)
max = np.array([0,0,255],np.uint8)                   # threshold min and max limits

hsv_img = cv2.cvtColor(org_img,cv2.COLOR_BGR2HSV)    # convert color space from BGR to HSV
mask    = cv2.inRange(hsv_img,min,max)               # apply the selected threshold
thr_img = cv2.bitwise_and(hsv_img,hsv_img,mask = mask)

cv2.imwrite('img/circles.jpg',thr_img);            # write the threshold image to disk


---------------------------------------------------------------------------
error                                     Traceback (most recent call last)
<ipython-input-2-0c98aba19c9b> in <module>()
      4 max = np.array([0,0,255],np.uint8)                   # threshold min and max limits
      5 
----> 6 hsv_img = cv2.cvtColor(org_img,cv2.COLOR_BGR2HSV)    # convert color space from BGR to HSV
      7 mask    = cv2.inRange(hsv_img,min,max)               # apply the selected threshold
      8 thr_img = cv2.bitwise_and(hsv_img,hsv_img,mask = mask)

error: /home/travis/miniconda/conda-bld/conda_1486587071158/work/opencv-3.1.0/modules/imgproc/src/color.cpp:7646: error: (-215) (scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F) in function ipp_cvtColor

In [26]:
print (org_img.shape)

plt.imshow(thr_img)
plt.title('Threshold Image')
plt.show()


(494, 576, 3)

In [ ]: