Before you write any content to such file you need to open it and at the end to close it. Save an image to a file. I have this matrix cvmat projectedtrain which has 400x500 and wanna copy write save into array in text file.