2024-01-01 23:58:00 +00:00
|
|
|
import cv2
|
2024-12-23 03:13:45 +00:00
|
|
|
from argparse import ArgumentParser
|
2024-01-01 23:58:00 +00:00
|
|
|
|
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)
|
2024-01-01 23:58:00 +00:00
|
|
|
|
|
|
|
height, width = img.shape
|
|
|
|
vals = []
|
|
|
|
|
|
|
|
for i in range(height):
|
|
|
|
for j in range(width):
|
|
|
|
k = img[i, j]
|
|
|
|
vals.append(k)
|
|
|
|
|
2024-12-23 02:49:27 +00:00
|
|
|
print(f'{len(vals)} bytes')
|
|
|
|
|
2024-01-01 23:58:00 +00:00
|
|
|
with open(file_path, "wb") as file:
|
|
|
|
file.write(bytes(vals))
|