TheRutubeify
TheRutubeify

Reputation: 666

python cv2 array to numpy

I try to convert cv2 image array with multi lines, to single line one array! Here is my code:

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]

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........]

What I'm doing wrong ?! Maybe there is some basic functions to convert from cv2 array to single array ?

Upvotes: 2

Views: 1351

Answers (1)

TheRutubeify
TheRutubeify

Reputation: 666

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

Upvotes: 1

Related Questions