lucasb-eyer / pydensecrf

Python wrapper to Philipp Krähenbühl's dense (fully connected) CRFs with gaussian edge potentials.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

drdlfy opened this issue · comments

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'

Thank you, I know where is wrong

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.

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.

Thank you for the clarification!

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'

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