Reputation: 3930
I have a 48x48 list of piexl values, which I want to write as a grayscale image file.
To do so, I'm converting the list to numpy array and use imwrite.
import cv2
from numpy import array
......
#pix is a 48x48 list containing pixel values
pix = array(pix)
cv2.imwrite('test.jpg',pix)
However, it returns the following error
Traceback (most recent call last):
File "face_detect.py", line 20, in <module>
cv2.imwrite('test.jpg',pix)
TypeError: img data type = 18 is not supported
It obviously has to do with datatype, but what should the second argument of imwrite be if not a numpy array?
Upvotes: 1
Views: 961
Reputation: 3930
I found out the problem, both to the post and my comment below it.
I read the values from a csv file where the numbers were separated by spaces. I used line.split() to break them into separate numbers, but actually I was still treating them as strings.
So all I had to do was to convert them to integers. I didn't need to normalize it either , 0~255 is right.
That was pretty dumb of mine, but in case anybody had the same problem.
Upvotes: 2