python - 将 Mat 对象转换为标准 12x12 矩阵
问题描述
我将每个字符作为不同大小的 Mat 对象。一些示例图像是,
我正在尝试使用 PIL 将它们转换为图像,然后转换为标准的 12x12 矩阵,该矩阵将被展平为 144 列一维数组。经过建议,我使用的代码如下
#roi is a Mat Object
images = cv2.resize(roi,(12,12))
myImage = Image.fromarray(images)
withoutReshape = np.array(myImage.getdata()) #Corresponding output attached
print(withoutReshape)
withReshape = np.array(myImage.getdata()).reshape(myImage.size[0], myImage.size[1], 3)
print(withReshape) #Corresponding output attached
找不到使用的意义reshape
。另外,使用后如何将矩阵展平为数组resize
解决方案
您对ndarray.resize
图像大小调整功能感到困惑。这不是它的工作原理。Numpy 不知道您的数组是图像,并且只会调整数组的大小而不关心内容。
您应该改用 OpenCVresize
函数。
images = cv2.resize(images, (12, 12))
此外,在从 PIL 数据创建数组后,您需要将images
数组重塑为图像尺寸。看看这个问题,看看它是如何完成的。
推荐阅读
- excel - 如何使用 2 张纸和多个条件使用 For Next 循环返回单元格值 - VBA
- .net - 针对自定义站点的在线购物插件的建议
- docker - l2 cni插件与l3插件有什么区别?
- wpf - 禁用时更改 RadioButton 文本的不透明度
- apache-kafka-streams - Kafka Streams DSL 谓词流分离
- api - Laravel 5.7:API 请求与否?
- python - 与使用 Anaconda Prompt 运行相比,从 Visual Studio 启动 Python 文件的工作方式不同
- kdb - 使用递归求解 q 中的 Euler 18
- mysql - SQL Query group by,有最小值,不选择最小值?
- machine-learning - 在矩阵分解中设置电影评分限制