0

Hello I have been trying to import an image from desktop to the jupyter notebook using opencv. I am getting the following error message at the end Image data of dtype object cannot be converted to float . My code is as follows:

import cv2 as cv
import matplotlib.pyplot as plt
im = cv.imread("dog.jpg")
im_1 = cv.cvtColor(im,cv.COLOR_BGR2RGB)

error Traceback (most recent call last) in ----> 1 im_1 = cv.cvtColor(im,cv.COLOR_BGR2RGB)

error: OpenCV(4.5.3) C:\Users\runneradmin\AppData\Local\Temp\pip-req-build-_xlv4eex\opencv\modules\imgproc\src\color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cv::cvtColor'

 plt.imshow(im)

~\Anaconda3\lib\site-packages\matplotlib\pyplot.py in imshow(X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, data, **kwargs) 2907
filternorm=filternorm, filterrad=filterrad, resample=resample, 2908 url=url, **({"data": data} if data is not None else {}), -> 2909 **kwargs) 2910 sci(__ret) 2911 return __ret

~\Anaconda3\lib\site-packages\matplotlib_init_.py in inner(ax, data, *args, **kwargs) 1359 def inner(ax, *args, data=None, **kwargs): 1360 if data is None: -> 1361 return func(ax, *map(sanitize_sequence, args), **kwargs) 1362 1363 bound = new_sig.bind(ax, *args, **kwargs)

~\Anaconda3\lib\site-packages\matplotlib\axes_axes.py in imshow(self, X, cmap, norm, aspect, interpolation, alpha, vmin, vmax, origin, extent, filternorm, filterrad, resample, url, **kwargs) 5607
resample=resample, **kwargs) 5608 -> 5609 im.set_data(X) 5610 im.set_alpha(alpha) 5611 if im.get_clip_path() is None:

~\Anaconda3\lib\site-packages\matplotlib\image.py in set_data(self, A) 699 not np.can_cast(self._A.dtype, float, "same_kind")): 700 raise TypeError("Image data of dtype {} cannot be converted to " --> 701 "float".format(self._A.dtype)) 702 703 if self._A.ndim == 3 and self._A.shape[-1] == 1:

TypeError: Image data of dtype object cannot be converted to float

Please if someone could help. Thanks in advance

1 Answer 1

1

So yes I finally found out the answer was that I didn't specify the correct file path in cv.imread() instead of cv.imread("dogs.jpg") I would have written full path (C:/......) etc

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.