如何将RGB图像转换为numpy数组? [英] how to convert an RGB image to numpy array?

查看:1559
本文介绍了如何将RGB图像转换为numpy数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张RGB图像。我想将它转换为numpy数组。我做了以下

I have an RGB image. I want to convert it to numpy array. I did the following

im = cv.LoadImage("abc.tiff")
a = numpy.asarray(im)

它会创建一个没有形状的数组。我假设它是iplimage对象。

it creates an array with no shape. I assume it is iplimage object.

怎么做?

谢谢

推荐答案

你可以使用更新的OpenCV python接口(如果我没弄错,它可以从OpenCV 2.2开始使用)。它原生使用numpy数组:

You can use newer OpenCV python interface (if I'm not mistaken it is available since OpenCV 2.2). It natively uses numpy arrays:

import cv2
im = cv2.imread("abc.tiff")
print type(im)

结果:

<type 'numpy.ndarray'>

这篇关于如何将RGB图像转换为numpy数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆