1

我尝试将具有多行的 cv2 图像数组转换为单行一个数组!这是我的代码:

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

 for i in img :

   im.append(np.array(i))

 print (im)   

我有这个结果: [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]

但我需要一个线阵列: ['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........]

我做错了什么?!也许有一些基本功能可以从 cv2 数组转换为单个数组?

4

1 回答 1

1
newarray = np.hstack(img)
print (newarray) 
于 2017-08-25T22:57:35.297 回答