【发布时间】:2014-01-29 16:29:37
【问题描述】:
我想从图像的像素颜色中获取一个简单的 python 列表,输出列表应该是一维排序的:
output = [B1,G1,R1,B2,G2,R2,B3,G3,R3....]
获取图片数据:
import cv2
image = cv2.imread('a.png')
image
array([[[ 0, 0, 255],
[ 0, 0, 255],
[ 0, 0, 255]],
[[ 0, 255, 0],
[ 0, 255, 0],
[ 0, 255, 0]],
[[255, 0, 0],
[255, 0, 0],
[255, 0, 0]]], dtype=uint8)
f = image.flatten()
f
[array([ 0, 0, 255, 0, 0, 255, 0, 0, 255, 0, 255, 0, 0,
255, 0, 0, 255, 0, 255, 0, 0, 255, 0, 0, 255, 0,
0], dtype=uint8)]
有没有办法获得:
f = [0,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,255,0,0,255,0,0,255,0,0]
【问题讨论】:
-
f = f[0],这行得通吗?
-
也许:list(f) 或 f =f.tolist()
标签: python list opencv converter nested-lists