Reputation: 61
I'm trying to convert an image from RGB to HSV color space, here's a segment of my code:
import cv2
import numpy as np
import imutils
lower = np.array([0, 48, 80], dtype= "uint8")
upper = np.array([20, 255, 255], dtype= "uint8")
img = cv2.imread('3.JPG', 0)
img = imutils.resize(img, width = 400)
cv2.waitKey(1)
converted = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
new_skinMask = cv2.inRange(converted, lower, upper)
but I'm getting an error on:
converted = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
the error is:
OpenCV Error: Assertion failed ((scn == 3 || scn == 4) && (depth == CV_8U || depth == CV_32F)) in cv::cvtColor
can anybody help me with this?
Upvotes: 2
Views: 1772
Reputation: 1632
Last parameter in
img = cv2.imread('3.JPG', 0)
stands for flags
, and 0
is equal to CV_LOAD_IMAGE_GRAYSCALE
(or IMREAD_GRAYSCALE
). That's why you get the assertion about the number of channels.
If you want to load the image in color either:
IMREAD_COLOR
flag, or CV_LOAD_IMAGE_COLOR
(or IMREAD_COLOR
). Consider the doc for more detail.
Upvotes: 3