lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.
MIT License
1.94k stars 413 forks source link

ValueError: Buffer dtype mismatch, expected 'unsigned char' but got 'double' #49

Closed drdlfy closed 6 years ago

drdlfy commented 6 years ago

Hello, when I execute this sentence will be incorrect, please help me to solve it, thank you very much:

d.addPairwiseBilateral(sxy=sxy_bilateral, compat=compat_bilateral, kernel=kernel_bilateral, normalization=normalisation_bilateral, srgb=srgb_bilateral, rgbim=img[0])

ValueError: Buffer dtype mismatch, expected 'unsigned char' but got 'double'

drdlfy commented 6 years ago

Thank you, I know where is wrong

lucasb-eyer commented 6 years ago

Hi @drdlfy, as you have found the mistake, could you please tell us what it was? In that way, other people making the same mistake and googling for it in the future will see this issue and can follow your solution. Also, maybe I can catch the mistake in the code and make the error message clearer.

drdlfy commented 6 years ago

Ok, @lucasb-eyer the code is not wrong, it is my use of the error. Image data format should be an unsigned integer can. Thank you very much.

lucasb-eyer commented 6 years ago

Thank you for the clarification!

ruchika61 commented 3 years ago

Hi kindly help i am also facing the same problem

File "C:/Users/dell/Desktop/Semantic-Shapes-master/singleimage.py", line 88, in roi_mask = crf(roi_pred.squeeze(), roi)

File "C:\Users\dell\Desktop\Semantic-Shapes-master\utils.py", line 106, in crf normalization=dcrf.NORMALIZE_SYMMETRIC)

File "pydensecrf\densecrf.pyx", line 126, in pydensecrf.densecrf.DenseCRF2D.addPairwiseBilateral

ValueError: Buffer dtype mismatch, expected 'unsigned char' but got 'float'

OllyFawcett commented 3 years ago

Just had the same issue and managed to figure out the problem. So the problem is that the image data is in float32 format or float64 or something like that and you need it in uint8 format. To get to the right format you need something like that

img = np.uint8(255 * img)

Hope this works for you