Outils pour utilisateurs

Outils du site


diy:projets:qrdeciphering

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Prochaine révision
Révision précédente
diy:projets:qrdeciphering [2018/05/23 09:30] – créée ycaminadediy:projets:qrdeciphering [2018/05/23 13:56] (Version actuelle) – [Required Libraries] ycaminade
Ligne 1: Ligne 1:
-===== Introduction =====+====== Introduction ======
 The goal of this program is to detect and decipher one or several QR codes in a picture. The goal of this program is to detect and decipher one or several QR codes in a picture.
  
-===== Required Libraries ===== +====== Required Libraries ====== 
-In order to decipher QR codes, we will use the QRLight library, installed as follow:\\+In order to decipher QR codes, we will use the zbarlight library, installed (on Debian) as follows:\\
 ''apt-get install libzbar0 libzbar-dev''\\ ''apt-get install libzbar0 libzbar-dev''\\
 ''pip install zbarlight''\\ ''pip install zbarlight''\\
Ligne 30: Ligne 30:
 </code> </code>
  
-**Work in Progress...**+If the right argument was given, we can remote into the pi to take a picture. To do so, we use subprocess.Popen() to run the following command with the given ip:\\ 
 +''ssh -t pi@<ip> "raspistill -hf -vf -o <nom_fichier> --nopreview --timeout 10"''\\ 
 +To avoid conflict with an already existing picture, we put the date and time in the new picture's name. 
 + 
 +<code python> 
 + if (len(sys.argv) == 2 and isValidIPV4(sys.argv[1])): 
 +    filename = 'qrcodereader_' + datetime.datetime.now().strftime("%Y-%m-%d-%H:%M:%S") + '.jpg' 
 + 
 +    print("Taking picture..."
 +    command = ['ssh', '-t', 'pi@' + sys.argv[1], "raspistill -hf -vf -o " + filename + " --nopreview --timeout 10"] 
 +    x = Popen(command, stdout=PIPE, stderr=PIPE) 
 +    stderr = x.stderr.read() 
 +    print stderr 
 +</code> 
 + 
 +We then import the resulting image over ssh using the ''rsync'' command. 
 + 
 +<code python> 
 +    print("Importing..."
 +    command = ['rsync', '-avz', '--ignore-existing', '--remove-source-files', 'pi@' + sys.argv[1] + ':~/' + filename, '/home/silver/BE/' + filename] 
 +    x = Popen(command, stdout=PIPE, stderr=PIPE) 
 +    stderr = x.stderr.read() 
 +    print stderr 
 +</code> 
 + 
 +We now simply use zbarlight to decode any and all QR codes fully visible on the picture. We only need to open and load the image, before applying the scan_codes function. 
 + 
 +<code python> 
 +    file_path = './' + filename 
 +    with open(file_path, 'rb') as image_file: 
 +        image = Image.open(image_file) 
 +        image.load() 
 +     
 +    code = zbarlight.scan_codes('qrcode', image) 
 +    print('QR codes: %s' % code) 
 +</code> 
 + 
 +The program outputs a full list of all deciphered QR codes.
diy/projets/qrdeciphering.1527067825.txt.gz · Dernière modification : 2018/05/23 09:30 de ycaminade