如何将 fastai 图像转换为 numpy 数组?

发布于 2025-01-12 18:41:51 字数 444 浏览 4 评论 0原文

我有一个 fastai 格式的图像:

type(im)

结果是:

fastai.vision.image.Image

但是,我需要使用 cv2 通过以下代码来操作图像

cv2.resize(im, (size,size), interpolation=interpolation)

im 的参数时code>在fastai图片格式下,出现错误: 类型错误:预期 Ptrfor argument '%s'

因此,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

嗼ふ静 2025-01-19 18:41:51

您可以使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文