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

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

Closed
drdlfy opened this issue Nov 9, 2017 · 6 comments
Closed

Comments

@drdlfy
Copy link

drdlfy commented Nov 9, 2017

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
Copy link
Author

drdlfy commented Nov 9, 2017

Thank you, I know where is wrong

@drdlfy drdlfy closed this as completed Nov 9, 2017
@lucasb-eyer
Copy link
Owner

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
Copy link
Author

drdlfy commented Nov 10, 2017

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
Copy link
Owner

Thank you for the clarification!

@ruchika61
Copy link

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
Copy link

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

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

4 participants