简体   繁体   English

python cv2 数组到 numpy

[英]python cv2 array to numpy

I try to convert cv2 image array with multi lines, to single line one array: Here is my code我尝试将多行的 cv2 图像数组转换为单行数组:这是我的代码

im =[]
img = cv2.imread('.jpg',0)

 for i in img :

   im.append(np.array(i))

 print (im)   

I have this result: [array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255], dtype=uint8), array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]我有这个结果: [array([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 , 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255 , 255, 255, 255, 255], dtype=uint8), 数组([ 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]

But I need one line array: ['0', '0', '0', '255', '255', '255', '255', '254', '255', '255', '253', '255', '254', '255', '254', '255', '254', '254', '255', '255', '255', '255', '255', '255', '255', '255', '253', '253........]但我需要一个线阵列: ['0', '0', '0', '255', '255', '255', '255', '254', '255', '255', '253 ','255','254','255','254','255','254','254','255','255','255','255','255', '255', '255', '255', '253', '253........]

What I'm doing wrong??我做错了什么?? Maybe there is some basic functions to convert from cv2 array to single array也许有一些基本功能可以从 cv2 数组转换为单个数组

newarray = np.hstack(img)
print (newarray) 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM