I have a lot of csv files and I want to transform them into binary files, so I want to create a python script that can automate this task for me. My CSV files contain either 0 or 255.(every file has 80 row and 320 columns)
I wrote this code :
import numpy as np
import csv
csv_filename = '320x80_ImageTest_1_255.csv'
filename = "output.bin"
with open(csv_filename) as f:
reader = csv.reader(f, delimiter =';')
lst = list(reader)
array = np.array(lst)
with open ('new_binary.bin','wb') as FileToWrite:
for i in range(len(array)):
for j in range(len(array[0])):
FileToWrite.write(''.join(chr(int(array[i][j]))).encode())
The problem is the output file is like this : screen of the output file
But intead of this caracter i want ff which corresponds to 255 in hex, where am i doing something wrong? can someone help me?