The code below will read byte array saved in a txt file, outputs the qr string and saves the qr image, like so
python readqr.py bytearray_in_text_file.txt- Save the python script below
python -m venv envsource env/bin/activatepip install pillow opencv-python- If all good, just use it like the example above.
import argparse
import io
import ast
from pathlib import Path
from PIL import Image
import cv2
import numpy as np
def main():
parser = argparse.ArgumentParser(description="Decode QR from byte array in txt file")
parser.add_argument("txtfile", help="Path to txt file containing byte array")
args = parser.parse_args()
txt_path = Path(args.txtfile)
with open(txt_path, "r") as f:
content = f.read().strip()
byte_array = ast.literal_eval(content)
byte_data = bytes((b + 256) % 256 for b in byte_array)
png_path = txt_path.with_suffix(".png")
image = Image.open(io.BytesIO(byte_data))
image.save(png_path)
print(f"Saved as {png_path}")
img_cv = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
detector = cv2.QRCodeDetector()
qr_data, _, _ = detector.detectAndDecode(img_cv)
if qr_data:
print("QR Payload:", qr_data)
else:
print("No QR code")
if __name__ == "__main__":
main()