opencv - Multi-channels LUT opencv2 python assert error -


i trying use cv2 lut image transfer in python. lut needs has same number of channels image. can't solve 1 error:

image1transfered = cv2.lut(image1, lut) cv2.error: /build/buildd/opencv-2.3.1/modules/core/src/convert.cpp:1037: error: (-215) (lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.iscontinuous() && (src.depth() == cv_8u || src.depth() == cv_8s) in function lut

here python code, believe can split image multiple single channels , apply lut respectively. waste of resource.

    #!/usr/bin/python     import sys     import cv2     import numpy np      image1 = cv2.imread("../pic1.jpg", 1)     # apply table     lut = np.arange(255, -1, -1, dtype = image1.dtype )     lut = np.column_stack((lut, lut, lut))     image1converted = cv2.lut(image1, lut)  # <-- fails 

thank time.

you using np.column_stack() create 3-channel image, not right function. have use either np.dstack() or cv2.merge(). works fine.

eg:

in [3]: x array([[0, 1, 2],        [3, 4, 5],        [6, 7, 8]])  in [5]: np.column_stack((x,x,x)) array([[0, 1, 2, 0, 1, 2, 0, 1, 2],        [3, 4, 5, 3, 4, 5, 3, 4, 5],        [6, 7, 8, 6, 7, 8, 6, 7, 8]])  in [6]: np.dstack((x,x,x)) array([[[0, 0, 0],         [1, 1, 1],         [2, 2, 2]],         [[3, 3, 3],         [4, 4, 4],         [5, 5, 5]],         [[6, 6, 6],         [7, 7, 7],         [8, 8, 8]]])  in [11]: cv2.merge((x,x,x)) array([[[0, 0, 0],         [1, 1, 1],         [2, 2, 2]],         [[3, 3, 3],         [4, 4, 4],         [5, 5, 5]],         [[6, 6, 6],         [7, 7, 7],         [8, 8, 8]]], dtype=int32) 

Comments

Post a Comment

Popular posts from this blog

android - java.net.UnknownHostException(Unable to resolve host “URL”: No address associated with hostname) -

jquery - How can I dynamically add a browser tab? -

keyboard - C++ GetAsyncKeyState alternative -