content/encode.py

25 lines
505 B
Python
Raw Normal View History

import cv2
2024-12-23 03:13:45 +00:00
from argparse import ArgumentParser
2024-12-23 03:13:45 +00:00
parser = ArgumentParser()
parser.add_argument('input', help='Input image')
parser.add_argument('output', help='Output bin')
args = parser.parse_args()
file_path = args.output
img = cv2.imread(args.input, cv2.IMREAD_GRAYSCALE)
height, width = img.shape
vals = []
for i in range(height):
for j in range(width):
k = img[i, j]
vals.append(k)
print(f'{len(vals)} bytes')
with open(file_path, "wb") as file:
file.write(bytes(vals))