如何将 fastai 图像转换为 numpy 数组?
我有一个 fastai 格式的图像:
type(im)
结果是:
fastai.vision.image.Image
但是,我需要使用 cv2 通过以下代码来操作图像
cv2.resize(im, (size,size), interpolation=interpolation)
当 im 的参数时code>在fastai图片格式下,出现错误:
类型错误:预期 Ptr
因此,fastai 图像应转换为 np.array 格式。我该怎么做呢?
我使用的是fastai v1.0.61,这是Google Colab的默认设置。
I have an image in fastai format:
type(im)
the result is:
fastai.vision.image.Image
However, I need to use cv2 to manipulate the image by the following code
cv2.resize(im, (size,size), interpolation=interpolation)
When argument of im
was under fastai image format, an error occured:TypeError: Expected Ptr<cv::UMat> for argument '%s'
Therefore, the fastai image should be converted to np.array format. How can I do it?
I am using fastai v1.0.61, which is the default setting of Google's Colab.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用numpy.array(z),(其中z类型为fastai.torch_core.TensorImage),您将获得所需图像的numpy数组。希望这对您有帮助。
You can use numpy.array(z), (where z type is fastai.torch_core.TensorImage), you will get the numpy array for the required image. Hope this is helpful for you.