TimoSaemann / ENet

ENet: A Deep Neural Network Architecture for Real-Time Semantic Segmentation
584 stars 275 forks source link

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

Open lucasjinreal opened 6 years ago

lucasjinreal commented 6 years ago

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 commented 6 years ago

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

ghost commented 6 years ago

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

wangshankun commented 6 years ago

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, predictionrgb)

wangshankun commented 6 years ago

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

duamu commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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 commented 4 years ago

convert into .astype("uint8")

Umraz-Hussain1 commented 3 years ago

the order of parameters is wrong kindly change it

to

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