Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenCV Error: Assertion failed ((lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() #55

Open
lucasjinreal opened this issue Jan 13, 2018 · 9 comments

Comments

@lucasjinreal
Copy link

I kick it quick start by using the trained model provide in model zoo, but there is an opencv error, really confusing:

OpenCV Error: Assertion failed ((lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == CV_8U || depth == CV_8S)) in LUT, file /home/jintian/opencv-3.1.0/modules/core/src/convert.cpp, line 5195
terminate called after throwing an instance of 'cv::Exception'
  what():  /home/jintian/opencv-3.1.0/modules/core/src/convert.cpp:5195: error: (-215) (lutcn == cn || lutcn == 1) && _lut.total() == 256 && _lut.isContinuous() && (depth == CV_8U || depth == CV_8S) in function LUT

[1]    2898 abort (core dumped)  ./test_segmentation prototxts/enet_deploy_final.prototxt   

Any possiable reason for this?

@hhhll
Copy link

hhhll commented Jan 30, 2018

@jinfagang Have you solved it ? I'm also confusing.

@ghost
Copy link

ghost commented Apr 16, 2018

I got same problem, has anyone solved it or figured out why this happened?

@wangshankun
Copy link

I got same problem .....
OpenCV Error: Assertion failed ((lutcn == cn || lutcn == 1) && lut.total() == 256 && lut.isContinuous() && (src.depth() == CV_8U || src.depth() == CV_8S)) in LUT, file /home/firefly/cnn/opencv-2.4.13/modules/core/src/convert.cpp, line 1215
Traceback (most recent call last):
File "./test_segmentation.py", line 69, in
cv2.LUT(prediction, label_colours_bgr, prediction_rgb)

@wangshankun
Copy link

@wzhouuu @jinfagang
for me,
--colour input img should be 1 channel? can using the default ENet/scripts/cityscapes19.png try

@duamu
Copy link

duamu commented Dec 19, 2018

I have met the same problem. And I have solved it. For me, the order of the last two input params is wrong. After exchanging them, the code is passed successfully.

@HuachunWang
Copy link

HuachunWang commented May 17, 2019

I met the same problem.
The codes is
def apply_custom_colormap(image_gray, cmap=None):
assert image_gray.dtype == np.uint8, 'must be np.uint8 image'
if image_gray.ndim == 3:
image_gray = image_gray.squeeze(-1)
# Initialize the matplotlib color map
sm = plt.cm.ScalarMappable(cmap=cmap)
# Obtain linear color range
color_range = sm.to_rgba(np.linspace(0., 1., 255))[:, 0:3] # color range RGBA => RGB
color_range = (color_range*255.0).astype(np.uint8) # [0,1] => [0,255]
# color_range = np.squeeze(np.dstack([color_range[:,2], color_range[:,1], color_range[:,0]]), 0) # RGB => BGR
# Apply colormap for each channel individually
channels = [cv2.LUT(image_gray, color_range[:, i]) for i in range(3)]
return np.dstack(channels)

Here, color_range = sm.to_rgba(np.linspace(0., 1., 255))[:, 0:3] is changed to
color_range = sm.to_rgba(np.linspace(0., 1., 256))[:, 0:3]
It work!

@Chuanguiy
Copy link

I have met this error yet. For me, the cv image was saved as float and value scope was (0.0, 255.0). After astype(np.uint8), it works.

@netizen136
Copy link

convert into .astype("uint8")

@Umraz-Hussain1
Copy link

the order of parameters is wrong kindly change it

to

dst = cv2.fastNlMeansDenoising(img, None, 30, 7, 21)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants