Re: az - Telefax/OCR Test

Liste des GroupesRevenir à s crypt 
Sujet : Re: az - Telefax/OCR Test
De : pollux (at) *nospam* tilde.club (Stefan Claas)
Groupes : sci.crypt
Date : 02. May 2024, 15:10:49
Autres entêtes
Organisation : i2pn2 (i2pn.org)
Message-ID : <v106ta$2sj59$1@i2pn2.org>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
Stefan Claas wrote:

Herbert Kleebauer wrote:
 
On 01.05.2024 10:29, Stefan Claas wrote:
 
I decoded the image and had one error in the certutil file
(one byte missing in one line at the end). The video was
also a certutil file, but with to many errors, so it wrote
a bad .mp4, which I could not decode.
 
How did you manage to precisely insert 12 QR-Codes nicely on
an A4 page?
 
Some time ago I wrote a batch to make a paper backup
from a 13 kByte binary file (so it will make only two
pages with 12 QR codes each). The input file is hard
coded (t.jpg in this case). qrencode.exe I downloaded
somewhere from the internet and convert.exe is the
universal picture tool from https://imagemagick.org .
split.exe just splits the input file in small chunks
to be encoded in single QR code (source at the end of
this post). To get the binary back from the paper print,
you have just to start a text editor and scan all the
QR codes with a Bluetooth QR code scanner (which works
like an external Bluetooth keyboard). Then execute the
generated batch file to generate the binary.
 
[...]
 
Thanks a lot or your help, much appreciated!

While I still cannot decode the video, I have now my own
solution.

Here is the Python3 code:

import qrcode
import os
import argparse
import shutil
from pyzbar.pyzbar import decode
from PIL import Image
import base64

parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', help='File to convert to/from QR codes')
parser.add_argument('-e', '--encode', help='Directory to save QR codes', default=None)
parser.add_argument('-d', '--decode', help='Directory to load QR codes from', default=None)
args = parser.parse_args()

def file_to_qrcodes(file_path, directory):
    with open(file_path, 'rb') as f:
        counter = 0
        while True:
            data = f.read(1024)  # Read in chunks of 1024 bytes
            if not data:
                break
            encoded_data = base64.b64encode(data)
            qr = qrcode.QRCode(
                version=1,
                error_correction=qrcode.constants.ERROR_CORRECT_L,
                box_size=10,
                border=4,
            )
            qr.add_data(encoded_data)
            qr.make(fit=True)
            img = qr.make_image(fill_color="black", back_color="white")
            img.save(os.path.join(directory, f'qr{counter}.png'))
            counter += 1

def qrcodes_to_file(directory, output_file):
    files = sorted([f for f in os.listdir(directory) if f.startswith('qr') and f.endswith('.png')],
                   key=lambda x: int(x[2:-4]))
    with open(output_file, 'wb') as f:
        for file in files:
            decoded_objects = decode(Image.open(os.path.join(directory, file)))
            if decoded_objects:
                encoded_data = decoded_objects[0].data
                data = base64.b64decode(encoded_data)
                f.write(data)

if args.file and (args.encode or args.decode):
    if args.encode:
        if not os.path.exists(args.encode):
            os.makedirs(args.encode)
        file_to_qrcodes(args.file, args.encode)
    if args.decode:
        if os.path.exists(args.decode):
            qrcodes_to_file(args.decode, args.file)

and two bash scripts, for making a movie and for extracing the frames.

#!/bin/bash
#mm - make move from .png files
FOLDERNAME="$1"

cat $(find $FOLDERNAME -maxdepth 1 -name "*.png" | sort -V) | ffmpeg -framerate 25 -i - output.mp4

#!/bin/bash
#ef - extracts QR-Codes from an .mp4 file in a folder

FOLDERFILENAME="$1"
DIRNAME=$(dirname "$FOLDERFILENAME")
BASENAME=$(basename "$FOLDERFILENAME" .mp4)

ffmpeg -i "$FOLDERFILENAME" -start_number 0 "$DIRNAME/qr%d.png"

--
Regards
Stefan





Date Sujet#  Auteur
25 Apr 24 * Re: base26 Encoder/Decoder22Stefan Claas
25 Apr 24 `* Re: base26 Encoder/Decoder21Stefan Claas
25 Apr 24  +* Re: base26 Encoder/Decoder3Stefan Claas
26 Apr 24  i`* Re: base26 Encoder/Decoder2Stefan Claas
26 Apr 24  i `- Re: base26 Encoder/Decoder1Stefan Claas
27 Apr 24  `* Re: base26 Encoder/Decoder17Stefan Claas
28 Apr 24   `* Re: base26 Encoder/Decoder16Stefan Claas
28 Apr 24    +- Re: base26 Encoder/Decoder1Stefan Claas
28 Apr 24    `* Re: base26 Encoder/Decoder14Herbert Kleebauer
28 Apr 24     `* Re: base26 Encoder/Decoder13Stefan Claas
28 Apr 24      +- Re: base26 Encoder/Decoder1Stefan Claas
28 Apr 24      `* Re: base26 Encoder/Decoder11Herbert Kleebauer
28 Apr 24       +- Re: base26 Encoder/Decoder1Stefan Claas
28 Apr 24       `* Re: base26 Encoder/Decoder9Stefan Claas
29 Apr 24        `* Re: base26 Encoder/Decoder8Stefan Claas
30 Apr 24         `* Re: az - Telefax/OCR Test (was: base26 Encoder/Decoder)7Stefan Claas
30 Apr 24          `* Re: az - Telefax/OCR Test6Herbert Kleebauer
1 May 24           `* Re: az - Telefax/OCR Test5Stefan Claas
1 May 24            `* Re: az - Telefax/OCR Test4Herbert Kleebauer
2 May 24             `* Re: az - Telefax/OCR Test3Stefan Claas
4 May 24              `* Re: az - Telefax/OCR Test2Stefan Claas
4 May 24               `- Re: az - Telefax/OCR Test1Stefan Claas

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal