如何在python中将图像转换为数组
我想将图像(.jpg)转换为二进制数组。因为我必须使用这个数组来操作保存在文件中的扰码器。我应该使用哪些库和函数?您应该查看如何在python中将图像转换为数组,python,arrays,image,numpy,scipy,Python,Arrays,Image,Numpy,Scipy,我想将图像(.jpg)转换为二进制数组。因为我必须使用这个数组来操作保存在文件中的扰码器。我应该使用哪些库和函数?您应该查看 您可以使用python库:PIL&numpy。单击此处了解有关python中图像处理的更多信息 import numpy import PIL img = PIL.Image.open("foo.jpg").convert("L") imgarr = numpy.array(img) 您可以使用此代码将图像转换为数组 查看此链接:评论中提到OP可能重复使用Pyth
您可以使用python库:PIL&numpy。单击此处了解有关python中图像处理的更多信息
import numpy
import PIL
img = PIL.Image.open("foo.jpg").convert("L")
imgarr = numpy.array(img)
- 您可以使用此代码将图像转换为数组
查看此链接:评论中提到OP可能重复使用Python3.6.4,因此PIL实际上不会帮助他,我猜他需要Python3替代品。@ZeBirdeh希望他能将这些信息合并到帖子中,因为目前为止,这个问题需要解决。ModuleNotFoundError:没有名为“cv2”的模块| |我不能使用cv2,没有导入它的选项。我有Python3.6.4,你应该先安装opencv模块,这样才能工作。
import numpy
import PIL
img = PIL.Image.open("foo.jpg").convert("L")
imgarr = numpy.array(img)
# Import the necessary libraries
from PIL import Image
from numpy import asarray
# load the image and convert into
# numpy array
img = Image.open('test.jpg')
arraydata = asarray(img)
# data
print(arraydata)