Ok. Long story short.
My camera has a method which takes a photo and this is what it returns:
[160, 120, 3, 10, 1287848024, 96181, 'super long image string']
I am able to decode the string and save it as image right after I call the method like this:
for i in range(0, 10):
image = camProxy.getImageRemote(nameId)
imageWidth = image[0]
imageHeight = image[1]
imageByteArray = image[6]
im = Image.fromstring("YCbCr",(imageWidth,imageHeight),imageByteArray)
fileName = str(time.time())+".jpg"
im.save(fileName, "JPEG")
This works nicely and I can open the saved images.
However, if I just save the string into a txt file and later I want to load it and save as image like this:
f = open("rawImage.txt", "r")
data = f.readline()
f.close()
# save as image
im = Image.frombuffer("YCbCr",(160,120),data)
im.save("test.jpg", "JPEG")
What I get is almost completely green image.
Here is an example string which I keep having problems with:
http://richardknop.com/rawImage.txt
Here is a complete output of the getImageRemote() method of the camera for that image:
http://richardknop.com/log.txt
Anybody got ideas what could be wrong? Is this some issue related to encoding? All files are saved as ASCII but I have tried saving them all as UTF-8 as well.
EDIT:
How I have written the image to file? I just redirected the output of the script:
python script.py > output.txt
And in the script I had:
print imageByteArray