Ask Your Question

cvtColor doesn't take 3-channel images

asked 2018-06-27 04:50:56 -0500

vahni gravatar image

I have the following code:

img_plane_rgb = imread('baboon.jpg')
img_plane_rgb_sc = img_plane_rgb.astype(float)/255
cv2.cvtColor(img_plane_rgb, img_plane_hsi,cv2.COLOR_BGR2HSV)

The error that I get is

TypeError: only length-1 arrays can be converted to Python scalars

The documentation says that an image read using imread should be usable in cvtColor. Even if I pass img_plane_rgb[1,:,0] as an argument the error persists, even though it is now a 1D array.

What other modification needs to be done to use cvtColor?

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted

answered 2018-06-27 05:02:43 -0500

berak gravatar image

updated 2018-06-27 05:03:29 -0500

try a >>> help(cv2.cvtColor) and you get:

    cvtColor(src, code[, dst[, dstCn]]) -> dst
    .   @brief Converts an image from one color space to another.

so you have to use it like:

img_plane_hsi = cv2.cvtColor(img_plane_rgb, cv2.COLOR_BGR2HSV)
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

1 follower


Asked: 2018-06-27 04:50:28 -0500

Seen: 87 times

Last updated: Jun 27 '18