1
0
mirror of https://gitlab.os-k.eu/neox/CNIRevelator.git synced 2023-08-25 14:03:10 +02:00

Compare commits

..

13 Commits

13 changed files with 269 additions and 73 deletions

View File

@ -1,5 +1,5 @@
# CNIRevelator # CNIRevelator
| ![FSF Logo](https://www.os-k.eu/GPLLOGO.PNG) | This program is free software, released under the terms of the [GNU GPL](COPYING) version 3 or later as published by the Free Software Foundation | | ![FSF Logo](https://www.os-k.eu/GPLLOGO.png) | This program is free software, released under the terms of the [GNU GPL](COPYING) version 3 or later as published by the Free Software Foundation |
|----------------------------------------------|----------------------------------------------------------------------| |----------------------------------------------|----------------------------------------------------------------------|
### Analyzer for MRZ Codes on identity cards, passports and others for Windows. ### Analyzer for MRZ Codes on identity cards, passports and others for Windows.

View File

@ -1,2 +1,2 @@
# ver|url|checksum, and | as separator, one version per || # ver|url|checksum, and | as separator, one version per ||
3.1.5|https://github.com/neox95/CNIRevelator/releases/download/3.1.5/CNIRevelator.zip|9efa41460dbe9375f15db8572b9f8d8e43c94a02|| 3.1.6|https://github.com/neox95/CNIRevelator/releases/download/3.1.6/CNIRevelator.zip|8977e1f335d08419be68133fe229ead453279b7f||

View File

@ -36,7 +36,7 @@ import logger # logger.py
import globs # globs.py import globs # globs.py
import github # github.py import github # github.py
def crashCNIR(shutdown=True): def crashCNIR(shutdown=True, option="", isVoluntary=False):
""" """
very last solution very last solution
""" """
@ -47,7 +47,14 @@ def crashCNIR(shutdown=True):
logfile = logger.logCur logfile = logger.logCur
logfile.printerr("FATAL ERROR : see traceback below.\n{}".format(traceback.format_exc())) logfile.printerr("FATAL ERROR : see traceback below.\n{}".format(traceback.format_exc()))
showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["CNIRevelator crashed because a fatal error occured. View log for more infos and please open an issue on Github"]) if not isVoluntary:
showerror(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["CNIRevelator crashed because a fatal error occured. View log for more infos and please open an issue on Github"] + "\n\n{}\n{}".format(option, traceback.format_exc()))
# Force new update
try:
os.remove(globs.CNIRLastUpdate)
except:
pass
res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to report this bug ?"]) res = askquestion(lang.all[globs.CNIRlang]["CNIRevelator Fatal Eror"], lang.all[globs.CNIRlang]["Would you like to report this bug ?"])
if res == "yes": if res == "yes":
@ -60,7 +67,7 @@ def crashCNIR(shutdown=True):
logfile.printerr("Can't read the log file.") logfile.printerr("Can't read the log file.")
# send it # send it
success = github.reportBug(traceback.format_exc(), data) success = github.reportBug(traceback.format_exc(), data, isVoluntary)
if not success: if not success:
logfile.printerr("Can't send to Github.") logfile.printerr("Can't send to Github.")

View File

@ -81,10 +81,11 @@ class newcredentials:
self.trying += 1 self.trying += 1
try: try:
sessionAnswer = session.get('https://www.google.com') sessionAnswer = session.get('http://www.google.com')
except Exception as e: except Exception as e:
logfile.printdbg('Network Error : ' + str(e)) logfile.printdbg('Network Error : ' + str(e))
sessionAnswer = '' self.login = "nointernet"
return
logfile.printdbg("Session Answer : " + str(sessionAnswer)) logfile.printdbg("Session Answer : " + str(sessionAnswer))
@ -94,11 +95,6 @@ class newcredentials:
self.valid = True self.valid = True
return return
if str(sessionAnswer) != '<Response [407]>' and self.trying > 2:
# because sometimes the proxy does not return an error (especially if we do not provide either credentials)
logfile.printerr('Network Error, or need a proxy !')
return
if self.trying > 4: if self.trying > 4:
logfile.printerr('Invalid credentials : access denied, a maximum of 3 trials have been raised !') logfile.printerr('Invalid credentials : access denied, a maximum of 3 trials have been raised !')
return return

View File

@ -60,7 +60,7 @@ class AESCipher(object):
def _unpad(s): def _unpad(s):
return s[:-ord(s[len(s) - 1:])] return s[:-ord(s[len(s) - 1:])]
def reportBug(reason="",log=""): def reportBug(reason="",log="", isVoluntary=False):
logfile = logger.logCur logfile = logger.logCur
@ -70,11 +70,108 @@ def reportBug(reason="",log=""):
session = credentials.sessionHandler session = credentials.sessionHandler
payload = {'title':"CNIRevelator Bug Report", 'body':"**An error has been reported by a CNIRevelator instance.**\n\n**Here is the full reason of this issue:**\n{}\n\n**The full log is here:** {}".format(reason, log), "assignees":["neox95"], "labels":["bug", "AUTO"]} if not isVoluntary:
payload = {
'title':"CNIRevelator App Bug Report",
'body': (
"**An error has been reported by a CNIRevelator instance.**\n\n"
"**Global informations:**\n"
"verType = {}\n"
"version= {}\n"
"verstring_full = {}\n"
"CNIRTesserHash = {}\n"
"CNIRGitToken = {}\n"
"CNIRName = {}\n"
"CNIRCryptoKey = {}\n"
"CNIRlang = {}\n"
"CNIRVerStock = {}\n"
"CNIREnv = {}\n"
"CNIRBetaURL = {}\n"
"CNIRDefaultURL = {}\n"
"CNIRNewVersion = {}\n"
"CNIROpenFile = {}\n"
"debug = {}\n"
"\n\n"
"**Full reason of the crash:**\n{}\n\n"
"**Full log:** {}"
).format(
globs.verType,
globs.version,
globs.verstring_full,
globs.CNIRTesserHash,
globs.CNIRGitToken,
globs.CNIRName,
globs.CNIRCryptoKey,
globs.CNIRlang,
globs.CNIRVerStock,
globs.CNIREnv,
globs.CNIRBetaURL,
globs.CNIRDefaultURL,
globs.CNIRNewVersion,
globs.CNIROpenFile,
globs.debug,
reason,
log
),
"assignees":["neox95"], "labels":["bug", "AUTO"]
}
else:
payload = {
'title':"CNIRevelator User Bug Report",
'body': (
"**An error has been reported by a CNIRevelator user.**\n\n"
"**Global informations:**\n"
"verType = {}\n"
"version= {}\n"
"verstring_full = {}\n"
"CNIRTesserHash = {}\n"
"CNIRGitToken = {}\n"
"CNIRName = {}\n"
"CNIRCryptoKey = {}\n"
"CNIRlang = {}\n"
"CNIRVerStock = {}\n"
"CNIREnv = {}\n"
"CNIRBetaURL = {}\n"
"CNIRDefaultURL = {}\n"
"CNIRNewVersion = {}\n"
"CNIROpenFile = {}\n"
"debug = {}\n"
"\n\n"
"**Possible reason:**\n{}\n\n"
"**Full log:** {}"
).format(
globs.verType,
globs.version,
globs.verstring_full,
globs.CNIRTesserHash,
globs.CNIRGitToken,
globs.CNIRName,
globs.CNIRCryptoKey,
globs.CNIRlang,
globs.CNIRVerStock,
globs.CNIREnv,
globs.CNIRBetaURL,
globs.CNIRDefaultURL,
globs.CNIRNewVersion,
globs.CNIROpenFile,
globs.debug,
reason,
log
),
"assignees":["neox95"], "labels":["bug", "AUTO"]
}
handler = session.post('https://api.github.com/repos/neox95/cnirevelator/issues', headers={'Authorization': 'token %s' % decryptToken(globs.CNIRGitToken)}, data=json.dumps(payload)) handler = session.post('https://api.github.com/repos/neox95/cnirevelator/issues', headers={'Authorization': 'token %s' % decryptToken(globs.CNIRGitToken)}, data=json.dumps(payload))
logfile.printdbg(handler.reason) logfile.printdbg("Issue is " + handler.reason)
if handler.reason == "Created": if handler.reason == "Created":
return True return True

View File

@ -26,8 +26,8 @@
import os import os
# CNIRevelator version # CNIRevelator version
verType = "beta release" verType = "stable release"
version = [3, 1, 5] version = [3, 1, 6]
verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType) verstring_full = "{}.{}.{} {}".format(version[0], version[1], version[2], verType)
verstring = "{}.{}".format(version[0], version[1]) verstring = "{}.{}".format(version[0], version[1])

View File

@ -30,7 +30,6 @@ from tkinter import filedialog
from tkinter import ttk from tkinter import ttk
import PIL.Image, PIL.ImageTk import PIL.Image, PIL.ImageTk
import traceback import traceback
import webbrowser
import cv2 import cv2
import critical # critical.py import critical # critical.py
@ -45,13 +44,16 @@ controlKeys = ["Escape", "Right", "Left", "Up", "Down", "Home", "End", "BackSpac
class DocumentAsk(Toplevel): class DocumentAsk(Toplevel):
def __init__(self, parent, choices): def __init__(self, parent, choices):
self.choice = 0
vals = [0, 1]
super().__init__(parent) super().__init__(parent)
self.title("{} :".format(lang.all[globs.CNIRlang]["Choose the identity document"])) self.title("{} :".format(lang.all[globs.CNIRlang]["Choose the identity document"]))
ttk.Radiobutton(self, text=choices[0], command=self.register0, value=vals[0]).pack() self.choice = 0
ttk.Radiobutton(self, text=choices[1], command=self.register1, value=vals[1]).pack() vals = [i[2] for i in choices]
for i in range(len(vals)):
a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i])
a.pack(fill=Y)
if i == 0:
a.invoke()
self.button = Button(self, text='OK', command=(self.ok)).pack() self.button = Button(self, text='OK', command=(self.ok)).pack()
self.resizable(width=False, height=False) self.resizable(width=False, height=False)
@ -68,10 +70,11 @@ class DocumentAsk(Toplevel):
y = hs / 2 - h / 2 y = hs / 2 - h / 2
self.geometry('%dx%d+%d+%d' % (w, h, x, y)) self.geometry('%dx%d+%d+%d' % (w, h, x, y))
def register0(self): def createRegister(self, i):
self.choice = 0 def register():
def register1(self): self.choice = i
self.choice = 1 return register
def ok(self): def ok(self):
self.destroy() self.destroy()
@ -193,7 +196,7 @@ class ChangelogDialog(Toplevel):
class langDialog(Toplevel): class langDialog(Toplevel):
def __init__(self, parent): def __init__(self, parent, currentLang):
super().__init__(parent) super().__init__(parent)
self.title(lang.all[globs.CNIRlang]["Language"]) self.title(lang.all[globs.CNIRlang]["Language"])
@ -202,7 +205,10 @@ class langDialog(Toplevel):
vals = [i for i in lang.all] vals = [i for i in lang.all]
for i in range(len(lang.all)): for i in range(len(lang.all)):
ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]).pack(fill=Y) a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i])
a.pack(fill=Y)
if i == vals.index(currentLang):
a.invoke()
ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5) ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5)
@ -231,7 +237,7 @@ class langDialog(Toplevel):
class updateSetDialog(Toplevel): class updateSetDialog(Toplevel):
def __init__(self, parent): def __init__(self, parent, currentChannel):
super().__init__(parent) super().__init__(parent)
self.title(lang.all[globs.CNIRlang]["Update options"]) self.title(lang.all[globs.CNIRlang]["Update options"])
@ -241,7 +247,11 @@ class updateSetDialog(Toplevel):
self.vals = ["Stable", "Beta"] self.vals = ["Stable", "Beta"]
vals = self.vals vals = self.vals
for i in range(len(vals)): for i in range(len(vals)):
ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i]).pack(fill=Y) a = ttk.Radiobutton(self, text=vals[i], command=self.createRegister(i), value=vals[i])
a.pack(fill=Y)
if i == self.vals.index(currentChannel):
a.invoke()
ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5) ttk.Button(self, text="OK", command=(self.oki)).pack(fill=Y, pady=5)
@ -265,7 +275,7 @@ class updateSetDialog(Toplevel):
def createRegister(self, i): def createRegister(self, i):
def register(): def register():
updater.updateChannel(self.vals[i]) updater.setUpdateChannel(self.vals[i])
return register return register
class LauncherWindow(Tk): class LauncherWindow(Tk):
@ -372,3 +382,4 @@ class StatusBar(Frame):
## Global Handler ## Global Handler
launcherWindowCur = LauncherWindow() launcherWindowCur = LauncherWindow()
# test ?

View File

@ -72,6 +72,8 @@ french = \
"Nationality" : "Nationalité", "Nationality" : "Nationalité",
"Registration" : "Immatriculation", "Registration" : "Immatriculation",
"Document number" : "N° de document", "Document number" : "N° de document",
"Length" : "Longueur",
"Facultative" : "Facultatif",
"Unknown" : "Inconnu(e)", "Unknown" : "Inconnu(e)",
"Display and processing of " "Display and processing of "
"documents" : "Affichage et traitement de documents", "documents" : "Affichage et traitement de documents",
@ -141,7 +143,8 @@ french = \
"Coller :\t\t\t\tCtrl-V \n" "Coller :\t\t\t\tCtrl-V \n"
"Forcer une nouvelle détection du document :\tEchap\n", "Forcer une nouvelle détection du document :\tEchap\n",
"CHANGELOG" : "Version 3.1.5 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug affectant le signalement de bug\n- Améliorations de l'affichage de la conformité des informations\n\n" + \ "CHANGELOG" : "Version 3.1.5 \nMise-à-jour mineure avec les progressions suivantes :\n- Ajout de la longueur de la MRZ dans les informations\n- Correction d'un bug affectant les Visas\n\n" + \
"Version 3.1.5 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug affectant le signalement de bug\n- Améliorations de l'affichage de la conformité des informations\n- Ajout d'un nouveau système de selection plus simple et fiable'\n\n" + \
"Version 3.1.4 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug affectant la rotation de documents dans l'afficheur d'images\n- Ajout d'une période de mise-à-jour afin d'éviter de rechercher les mises-à-jour tous les jours\n\n" + \ "Version 3.1.4 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug affectant la rotation de documents dans l'afficheur d'images\n- Ajout d'une période de mise-à-jour afin d'éviter de rechercher les mises-à-jour tous les jours\n\n" + \
"Version 3.1.3 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug de la détection automatique de documents\n- Ajout d'une fonctionnalité de rapport d'erreur\n\n" + \ "Version 3.1.3 \nMise-à-jour mineure avec les progressions suivantes :\n- Correction d'un bug de la détection automatique de documents\n- Ajout d'une fonctionnalité de rapport d'erreur\n\n" + \
"Version 3.1.2 \nMise-à-jour mineure avec les progressions suivantes :\n- Montée de version de Tesseract OCR : 5.0\n- Correction de noms des documents\n- Résolution d'un problème avec le système de mise-à-jour\n- Amélioration des effets sur images\n\n" + \ "Version 3.1.2 \nMise-à-jour mineure avec les progressions suivantes :\n- Montée de version de Tesseract OCR : 5.0\n- Correction de noms des documents\n- Résolution d'un problème avec le système de mise-à-jour\n- Amélioration des effets sur images\n\n" + \
@ -208,6 +211,9 @@ french = \
"does not contain any non unicode " "does not contain any non unicode "
"character such as accent and " "character such as accent and "
"foreign characters." : "Une erreur critique s'est produite dans le gestionnaire de traitement d'images OpenCV utilisé par CNIRevelator. Veuillez vous assurer que le nom de fichier ne contient pas de caractères non unicode tels que des accents et des caractères étrangers.", "foreign characters." : "Une erreur critique s'est produite dans le gestionnaire de traitement d'images OpenCV utilisé par CNIRevelator. Veuillez vous assurer que le nom de fichier ne contient pas de caractères non unicode tels que des accents et des caractères étrangers.",
"No Internet Error. No effective "
"update !" : "Aucune connectivité. Pas de mise-à-jour !",
"Project Webpage" : "Site internet du projet",
"LANDCODE2" : { "LANDCODE2" : {
'AW': 'Aruba', 'AW': 'Aruba',
@ -777,6 +783,8 @@ english = \
"Nationality" : "Nationality", "Nationality" : "Nationality",
"Registration" : "Registration", "Registration" : "Registration",
"Document number" : "Document number", "Document number" : "Document number",
"Length" : "Length",
"Facultative" : "Facultative",
"Unknown" : "Unknown", "Unknown" : "Unknown",
"Display and processing of " "Display and processing of "
"documents" : "Display and processing of documents", "documents" : "Display and processing of documents",
@ -810,6 +818,8 @@ english = \
"the OpenCV image processing " "the OpenCV image processing "
"manager used by CNIRevelator, the " "manager used by CNIRevelator, the "
"application will reset itself" : "A critical error has occurred in the OpenCV image processing manager used by CNIRevelator, the application will reset itself", "application will reset itself" : "A critical error has occurred in the OpenCV image processing manager used by CNIRevelator, the application will reset itself",
"No Internet Error. No effective "
"update !" : "No Internet Error. No effective update !",
"ABOUT" : 'Software Version: CNIRevelator' + globs.verstring_full + '\n\n' "ABOUT" : 'Software Version: CNIRevelator' + globs.verstring_full + '\n\n'
"Copyright © 2018-2019 Adrien Bourmault (neox95)" + "\n\n" "Copyright © 2018-2019 Adrien Bourmault (neox95)" + "\n\n"
@ -848,7 +858,8 @@ english = \
"Paste:\t\t\t\tCtrl-V\n" "Paste:\t\t\t\tCtrl-V\n"
"Force a new document detection:\tEchap\n", "Force a new document detection:\tEchap\n",
"CHANGELOG" : "Version 3.1.5 \nMinor update with the following progressions:\n- Correction of a bug affecting bug reporting\n - Enhancements on information compliance display\n\n" + \ "CHANGELOG" : "Version 3.1.6 \nMinor update with the following progressionss :\n- Added MRZ length in the information\n- Fixed a bug affecting Visas\n\n" + \
"Version 3.1.5 \nMinor update with the following progressions:\n- Correction of a bug affecting bug reporting\n - Enhancements on information compliance display\n- Added new selection system to be more userfriendly\n\n" + \
"Version 3.1.4 \nMinor update with the following progressions:\n- Correction of a bug affecting rotation of document in image viewer\n- Added a new update period to prevent updating everyday\n\n" + \ "Version 3.1.4 \nMinor update with the following progressions:\n- Correction of a bug affecting rotation of document in image viewer\n- Added a new update period to prevent updating everyday\n\n" + \
"Version 3.1.3 \nMinor update with the following progressions:\n- Correction of a bug affecting automated document detection\n- Added bug reporting functionnality\n\n" + \ "Version 3.1.3 \nMinor update with the following progressions:\n- Correction of a bug affecting automated document detection\n- Added bug reporting functionnality\n\n" + \
"Version 3.1.2 \nMinor update with the following progressions: \n- Tesseract OCR version upgrade : 5.0\n- Correction of document names\n- Fixed a problem with the update system\n- Some enhancements about effects on images\n\n" + \ "Version 3.1.2 \nMinor update with the following progressions: \n- Tesseract OCR version upgrade : 5.0\n- Correction of document names\n- Fixed a problem with the update system\n- Some enhancements about effects on images\n\n" + \
@ -915,6 +926,7 @@ english = \
"does not contain any non unicode " "does not contain any non unicode "
"character such as accent and " "character such as accent and "
"foreign characters." : "A critical error has occurred in the OpenCV image processing manager used by CNIRevelator. Please be sure that the filename does not contain any non unicode character such as accent and foreign characters.", "foreign characters." : "A critical error has occurred in the OpenCV image processing manager used by CNIRevelator. Please be sure that the filename does not contain any non unicode character such as accent and foreign characters.",
"Project Webpage" : "Project website",
"LANDCODE2" : { "LANDCODE2" : {
"AW": "Aruba", "AW": "Aruba",

View File

@ -38,9 +38,9 @@ import re
import cv2 import cv2
import PIL.Image, PIL.ImageTk import PIL.Image, PIL.ImageTk
import os, shutil import os, shutil
import webbrowser
import sys, os import sys, os
import numpy import numpy
import webbrowser
import critical # critical.py import critical # critical.py
import ihm # ihm.py import ihm # ihm.py
@ -49,6 +49,7 @@ import mrz # mrz.py
import globs # globs.py import globs # globs.py
import pytesseract # pytesseract.py import pytesseract # pytesseract.py
import lang # lang.py import lang # lang.py
import updater # updater.py
# Global handler # Global handler
logfile = logger.logCur logfile = logger.logCur
@ -70,6 +71,7 @@ class mainWindow(Tk):
self.Tags = [] self.Tags = []
self.compliance = True self.compliance = True
self.corners = [] self.corners = []
self.indicators = []
self.validatedtext = "" self.validatedtext = ""
# The icon # The icon
@ -108,6 +110,7 @@ class mainWindow(Tk):
self.lecteur_ci.grid_rowconfigure(3, weight=1) self.lecteur_ci.grid_rowconfigure(3, weight=1)
self.lecteur_ci.grid_rowconfigure(4, weight=1) self.lecteur_ci.grid_rowconfigure(4, weight=1)
self.lecteur_ci.grid_rowconfigure(5, weight=1) self.lecteur_ci.grid_rowconfigure(5, weight=1)
self.lecteur_ci.grid_rowconfigure(6, weight=1)
# And what about the status bar ? # And what about the status bar ?
self.statusbar = ihm.StatusBar(self) self.statusbar = ihm.StatusBar(self)
@ -148,6 +151,9 @@ class mainWindow(Tk):
ttk.Label((self.lecteur_ci), text='{} : '.format(lang.all[globs.CNIRlang]["Document number"])).grid(column=4, row=5, padx=5, pady=5) ttk.Label((self.lecteur_ci), text='{} : '.format(lang.all[globs.CNIRlang]["Document number"])).grid(column=4, row=5, padx=5, pady=5)
self.no = ttk.Label((self.lecteur_ci), text=' ') self.no = ttk.Label((self.lecteur_ci), text=' ')
self.no.grid(column=5, row=5, padx=5, pady=5) self.no.grid(column=5, row=5, padx=5, pady=5)
ttk.Label((self.lecteur_ci), text='{} : '.format(lang.all[globs.CNIRlang]["Length"])).grid(column=0, row=6, padx=5, pady=5)
self.len = ttk.Label((self.lecteur_ci), text=' ')
self.len.grid(column=1, row=6, padx=5, pady=5)
self.nom['text'] = lang.all[globs.CNIRlang]["Unknown"] self.nom['text'] = lang.all[globs.CNIRlang]["Unknown"]
self.prenom['text'] = lang.all[globs.CNIRlang]["Unknown"] self.prenom['text'] = lang.all[globs.CNIRlang]["Unknown"]
@ -159,6 +165,7 @@ class mainWindow(Tk):
self.nat['text'] = lang.all[globs.CNIRlang]["Unknown"] self.nat['text'] = lang.all[globs.CNIRlang]["Unknown"]
self.pays['text'] = lang.all[globs.CNIRlang]["Unknown"] self.pays['text'] = lang.all[globs.CNIRlang]["Unknown"]
self.indic['text'] = lang.all[globs.CNIRlang]["Unknown"] self.indic['text'] = lang.all[globs.CNIRlang]["Unknown"]
self.len['text'] = lang.all[globs.CNIRlang]["Unknown"]
self.infoList = \ self.infoList = \
@ -172,7 +179,8 @@ class mainWindow(Tk):
"SEX" : self.sex, "SEX" : self.sex,
"NAT" : self.nat, "NAT" : self.nat,
"PAYS" : self.pays, "PAYS" : self.pays,
"INDIC" : self.indic "INDIC" : self.indic,
"LEN" : self.len,
} }
# The the image viewer # The the image viewer
@ -351,6 +359,7 @@ class mainWindow(Tk):
menu3.add_command(label=lang.all[globs.CNIRlang]["Keyboard commands"], command=(self.helpbox)) menu3.add_command(label=lang.all[globs.CNIRlang]["Keyboard commands"], command=(self.helpbox))
menu3.add_command(label=lang.all[globs.CNIRlang]["Report a bug"], command=(self.openIssuePage)) menu3.add_command(label=lang.all[globs.CNIRlang]["Report a bug"], command=(self.openIssuePage))
menu3.add_separator() menu3.add_separator()
menu3.add_command(label=lang.all[globs.CNIRlang]["Project Webpage"], command=(self.openProjectPage))
menu3.add_command(label=lang.all[globs.CNIRlang]["About CNIRevelator"], command=(self.infobox)) menu3.add_command(label=lang.all[globs.CNIRlang]["About CNIRevelator"], command=(self.infobox))
menubar.add_cascade(label=lang.all[globs.CNIRlang]["Help"], menu=menu3) menubar.add_cascade(label=lang.all[globs.CNIRlang]["Help"], menu=menu3)
menubar.add_command(label="<|>", command=(self.panelResize)) menubar.add_command(label="<|>", command=(self.panelResize))
@ -409,11 +418,19 @@ class mainWindow(Tk):
self.corners.append([canvas.canvasx(event.x), canvas.canvasy(event.y)]) self.corners.append([canvas.canvasx(event.x), canvas.canvasy(event.y)])
if len(self.corners) == 2: if len(self.corners) == 2:
self.select = self.imageViewer.ZONE.create_rectangle(self.corners[0][0], self.corners[0][1], self.corners[1][0], self.corners[1][1], outline ='cyan', width = 2) self.select = self.imageViewer.ZONE.create_rectangle(self.corners[0][0], self.corners[0][1], self.corners[1][0], self.corners[1][1], outline ='red', width = 2)
#print("Get rectangle : [{}, {}], for [{}, {}]".format(self.corners[0][0], self.corners[0][1], self.corners[1][0], self.corners[1][1])) #print("Get rectangle : [{}, {}], for [{}, {}]".format(self.corners[0][0], self.corners[0][1], self.corners[1][0], self.corners[1][1]))
# Reinit
if len(self.corners) > 2: if len(self.corners) > 2:
self.corners = [] self.corners = []
self.imageViewer.ZONE.delete(self.select) self.imageViewer.ZONE.delete(self.select)
for k in self.indicators:
self.imageViewer.ZONE.delete(k)
# Draw indicator
else:
self.indicators.append(self.imageViewer.ZONE.create_oval(canvas.canvasx(event.x)-4, canvas.canvasy(event.y)-4,canvas.canvasx(event.x)+4, canvas.canvasy(event.y)+4, fill='red', outline='red', width = 2))
def goOCRDetection(self): def goOCRDetection(self):
""" """
@ -447,10 +464,13 @@ class mainWindow(Tk):
cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA) cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA)
# Crop # Crop
x0 = int(self.corners[0][0])
y0 = int(self.corners[0][1]) coords = self.imageViewer.ZONE.coords(self.select)
x1 = int(self.corners[1][0])
y1 = int(self.corners[1][1]) x0 = int(coords[0])
y0 = int(coords[1])
x1 = int(coords[2])
y1 = int(coords[3])
crop_img = cv_img[y0:y1, x0:x1] crop_img = cv_img[y0:y1, x0:x1]
# Get the text by OCR # Get the text by OCR
@ -510,9 +530,9 @@ class mainWindow(Tk):
# Get the candidates # Get the candidates
candidates = mrz.allDocMatch(self.mrzChar.split("\n"), final=isFull) candidates = mrz.allDocMatch(self.mrzChar.split("\n"), final=isFull)
if len(candidates) == 2 and len(self.mrzChar) >= 8: if len(candidates) >= 2 and len(candidates) < 4 and len(self.mrzChar) >= 8:
# Parameters for the choice invite # Parameters for the choice invite
invite = ihm.DocumentAsk(self, [candidates[0][2], candidates[1][2]]) invite = ihm.DocumentAsk(self, candidates)
invite.transient(self) invite.transient(self)
invite.grab_set() invite.grab_set()
invite.focus_force() invite.focus_force()
@ -606,9 +626,9 @@ class mainWindow(Tk):
# Get the candidates # Get the candidates
candidates = mrz.allDocMatch(self.mrzChar.split("\n")) candidates = mrz.allDocMatch(self.mrzChar.split("\n"))
if len(candidates) == 2 and len(self.mrzChar) >= 8: if len(candidates) >= 2 and len(candidates) < 4 and len(self.mrzChar) >= 8:
# Parameters for the choice invite # Parameters for the choice invite
invite = ihm.DocumentAsk(self, [candidates[0][2], candidates[1][2]]) invite = ihm.DocumentAsk(self, candidates)
invite.transient(self) invite.transient(self)
invite.grab_set() invite.grab_set()
invite.focus_force() invite.focus_force()
@ -723,8 +743,8 @@ class mainWindow(Tk):
#print(docInfos) #print(docInfos)
# display the infos # display the infos
for key in [ e for e in docInfos ]: for key in [ e for e in docInfos ]:
print(key) #printkey)
if key in ["CODE", "CTRL", "CTRLF", "FACULT"]: if key in ["CODE", "CTRL", "CTRLF", "FACULT", "NOINT"]:
continue continue
if not docInfos[key][1] == False: if not docInfos[key][1] == False:
if not docInfos[key][0] == "": if not docInfos[key][0] == "":
@ -803,10 +823,13 @@ class mainWindow(Tk):
""" """
self.initialize() self.initialize()
path = '' path = ''
path = filedialog.askopenfilename(parent=self, title=lang.all[globs.CNIRlang]["Open a scan of document..."], filetypes=(('TIF files', '*.tif'), path = filedialog.askopenfilename(parent=self, title=lang.all[globs.CNIRlang]["Open a scan of document..."], filetypes=(
('TIF files', '*.tif'),
('TIF files', '*.tiff'), ('TIF files', '*.tiff'),
('JPEG files', '*.jpg'), ('JPEG files', '*.jpg'),
('JPEG files', '*.jpeg'))) ('JPEG files', '*.jpeg'),
('PNG files', '*.png')
))
self.openScanFile(path) self.openScanFile(path)
def openScanFile(self, path): def openScanFile(self, path):
@ -817,7 +840,8 @@ class mainWindow(Tk):
if ( path[-3:] != 'jpg' if ( path[-3:] != 'jpg'
and path[-3:] != 'tif' and path[-3:] != 'tif'
and path[-4:] != 'jpeg' and path[-4:] != 'jpeg'
and path[-4:] != 'tiff' ) or not os.path.isfile(path): and path[-4:] != 'tiff'
and path[-3:] != 'png' ) or not os.path.isfile(path):
showerror(lang.all[globs.CNIRlang]["Open a scan of document..."], lang.all[globs.CNIRlang]["The file you provided is not valid : {}"].format(path)) showerror(lang.all[globs.CNIRlang]["Open a scan of document..."], lang.all[globs.CNIRlang]["The file you provided is not valid : {}"].format(path))
return return
@ -841,7 +865,7 @@ class mainWindow(Tk):
cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB) cv_img = cv2.cvtColor(cv_img, cv2.COLOR_BGR2RGB)
except: except:
logfile.printerr("Error with : {} in {} with total of {} pages".format(cv2.imreadmulti(self.imageViewer.imagePath), self.imageViewer.imagePath, total)) logfile.printerr("Error with : {} in {} with total of {} pages".format(cv2.imreadmulti(self.imageViewer.imagePath), self.imageViewer.imagePath, total))
showerror(lang.all[globs.CNIRlang]["OpenCV error (image processing)"], lang.all[globs.CNIRlang]["A critical error has occurred in the OpenCV image processing manager used by CNIRevelator. Please be sure that the filename does not contain any non unicode character such as accent and foreign characters."] + "\n\n" + self.imageViewer.imagePath) critical.crashCNIR(False, "OpenCV openScanFile() error")
try: try:
# Get the image dimensions (OpenCV stores image data as NumPy ndarray) # Get the image dimensions (OpenCV stores image data as NumPy ndarray)
@ -854,6 +878,10 @@ class mainWindow(Tk):
# Get the image dimensions (OpenCV stores image data as NumPy ndarray) # Get the image dimensions (OpenCV stores image data as NumPy ndarray)
height, width = cv_img.shape height, width = cv_img.shape
# Update shape
self.imageViewer.height, self.imageViewer.width = cv_img.shape[:2]
# Use PIL (Pillow) to convert the NumPy ndarray to a PhotoImage # Use PIL (Pillow) to convert the NumPy ndarray to a PhotoImage
photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(cv_img)) photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(cv_img))
self.DisplayUpdate(photo) self.DisplayUpdate(photo)
@ -864,7 +892,7 @@ class mainWindow(Tk):
self.resizeScan() self.resizeScan()
def zoomOutScan50(self, quantity = 50): def zoomOutScan50(self, quantity = 50):
if self.imageViewer.image: if self.imageViewer.image and int(self.imageViewer.width * (self.imageViewer.imgZoom - quantity + 100) / 100) > 100:
self.imageViewer.imgZoom -= quantity self.imageViewer.imgZoom -= quantity
self.resizeScan() self.resizeScan()
@ -874,7 +902,7 @@ class mainWindow(Tk):
self.resizeScan() self.resizeScan()
def zoomOutScan20(self, quantity = 20): def zoomOutScan20(self, quantity = 20):
if self.imageViewer.image: if self.imageViewer.image and int(self.imageViewer.width * (self.imageViewer.imgZoom - quantity + 100) / 100) > 100:
self.imageViewer.imgZoom -= quantity self.imageViewer.imgZoom -= quantity
self.resizeScan() self.resizeScan()
@ -884,7 +912,7 @@ class mainWindow(Tk):
self.resizeScan() self.resizeScan()
def zoomOutScan(self, quantity = 1): def zoomOutScan(self, quantity = 1):
if self.imageViewer.image: if self.imageViewer.image and int(self.imageViewer.width * (self.imageViewer.imgZoom - quantity + 100) / 100) > 100:
self.imageViewer.imgZoom -= quantity self.imageViewer.imgZoom -= quantity
self.resizeScan() self.resizeScan()
@ -996,6 +1024,9 @@ class mainWindow(Tk):
dim = (int(width * (self.imageViewer.imgZoom + 100) / 100), int(height * (self.imageViewer.imgZoom + 100) / 100)) dim = (int(width * (self.imageViewer.imgZoom + 100) / 100), int(height * (self.imageViewer.imgZoom + 100) / 100))
cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA) cv_img = cv2.resize(cv_img, dim, interpolation = cv2.INTER_AREA)
# Update shape
self.imageViewer.height, self.imageViewer.width = cv_img.shape[:2]
# Use PIL (Pillow) to convert the NumPy ndarray to a PhotoImage # Use PIL (Pillow) to convert the NumPy ndarray to a PhotoImage
photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(cv_img)) photo = PIL.ImageTk.PhotoImage(image = PIL.Image.fromarray(cv_img))
self.DisplayUpdate( photo) self.DisplayUpdate( photo)
@ -1018,7 +1049,7 @@ class mainWindow(Tk):
self.DisplayUpdate(photo) self.DisplayUpdate(photo)
except Exception as e: except Exception as e:
logfile.printerr("Critical error with opencv : ".format(e)) logfile.printerr("Critical error with opencv : ".format(e))
showerror(lang.all[globs.CNIRlang]["OpenCV error (image processing)"], lang.all[globs.CNIRlang]["A critical error has occurred in the OpenCV image processing manager used by CNIRevelator, the application will reset itself"]) critical.crashCNIR(False, "OpenCV resizeScan() error")
self.initialize() self.initialize()
## IHM and user interface related functions ## IHM and user interface related functions
@ -1057,9 +1088,15 @@ class mainWindow(Tk):
def openIssuePage(self): def openIssuePage(self):
""" """
Opens the Github Issue Repository page Sends a bug report
""" """
webbrowser.open_new("https://github.com/neox95/CNIRevelator/issues") critical.crashCNIR(shutdown=False, option="Voluntary Bug Report", isVoluntary=True)
def openProjectPage(self):
"""
Opens the Project Repository webpage
"""
webbrowser.open_new("https://github.com/neox95/CNIRevelator")
def showChangeLog(self): def showChangeLog(self):
changelogWin = ihm.ChangelogDialog(self, ('{} : CNIRevelator {}\n\n{}'.format(lang.all[globs.CNIRlang]["Program version"], globs.verstring_full, lang.all[globs.CNIRlang]["CHANGELOG"]))) changelogWin = ihm.ChangelogDialog(self, ('{} : CNIRevelator {}\n\n{}'.format(lang.all[globs.CNIRlang]["Program version"], globs.verstring_full, lang.all[globs.CNIRlang]["CHANGELOG"])))
@ -1072,7 +1109,7 @@ class mainWindow(Tk):
""" """
Update Settings Update Settings
""" """
changeupdateWin = ihm.updateSetDialog(self) changeupdateWin = ihm.updateSetDialog(self, updater.getUpdateChannel())
changeupdateWin.transient(self) changeupdateWin.transient(self)
changeupdateWin.grab_set() changeupdateWin.grab_set()
changeupdateWin.focus_force() changeupdateWin.focus_force()
@ -1082,7 +1119,7 @@ class mainWindow(Tk):
""" """
Lang Settings Lang Settings
""" """
changelangWin = ihm.langDialog(self) changelangWin = ihm.langDialog(self, globs.CNIRlang)
changelangWin.transient(self) changelangWin.transient(self)
changelangWin.grab_set() changelangWin.grab_set()
changelangWin.focus_force() changelangWin.focus_force()

View File

@ -147,7 +147,7 @@ AC = [
] ]
VA = [ VA = [
["11222333333333333333333333333333333333333333", "444444444566677777789AAAAAABCCCCCCCCCCCCCCCCC"], ["11222333333333333333333333333333333333333333", "444444444566677777789AAAAAABCCCCCCCCCCCCCCCC"],
{ {
"1": ["2", "CODE", "V."], "1": ["2", "CODE", "V."],
"2": ["3", "PAYS", "[A-Z]+"], "2": ["3", "PAYS", "[A-Z]+"],
@ -166,7 +166,7 @@ VA = [
] ]
VB = [ VB = [
["112223333333333333333333333333333333", "444444444566677777789AAAAAABCCCCCC"], ["112223333333333333333333333333333333", "444444444566677777789AAAAAABCCCCCCCC"],
{ {
"1": ["2", "CODE", "V."], "1": ["2", "CODE", "V."],
"2": ["3", "PAYS", "[A-Z]+"], "2": ["3", "PAYS", "[A-Z]+"],
@ -487,6 +487,14 @@ def getDocInfos(doc, code):
res = {} res = {}
# Length of MRZ
length = len(code)
if length == len(doc[0][0]+doc[0][1]):
res["LEN"] = [length, True]
else:
res["LEN"] = [length, False]
for field in infoTypes: for field in infoTypes:
value = code[ field[1][0] : field[1][1] ].replace("<", " ").strip() value = code[ field[1][0] : field[1][1] ].replace("<", " ").strip()

View File

@ -24,7 +24,7 @@
* along with CNIRevelator. If not, see <https:*www.gnu.org/licenses/>. * * along with CNIRevelator. If not, see <https:*www.gnu.org/licenses/>. *
******************************************************************************** ********************************************************************************
""" """
import logger # logger.pu
try: try:
import Image import Image
@ -248,7 +248,7 @@ def image_to_string(image, lang=None, config='', nice=0, boxes=False, output_typ
Returns the result of a Tesseract OCR run on the provided image to string Returns the result of a Tesseract OCR run on the provided image to string
""" """
if boxes: if boxes:
print("\nWarning: Argument 'boxes' is deprecated and will be removed in future versions. Use function image_to_boxes instead.\n") logfile.printdbg("\nWarning: Argument 'boxes' is deprecated and will be removed in future versions. Use function image_to_boxes instead.\n")
return image_to_boxes(image, lang, config, nice, output_type) return image_to_boxes(image, lang, config, nice, output_type)
else: else:
args = [ args = [
@ -317,7 +317,7 @@ def main():
sys.stderr.write('Usage: python pytesseract.py [-l lang] input_file\n') sys.stderr.write('Usage: python pytesseract.py [-l lang] input_file\n')
exit(2) exit(2)
try: try:
print(image_to_string((Image.open(filename)), lang=lang)) logfile.printdbg(image_to_string((Image.open(filename)), lang=lang))
except IOError: except IOError:
sys.stderr.write('ERROR: Could not open file "%s"\n' % filename) sys.stderr.write('ERROR: Could not open file "%s"\n' % filename)
exit(1) exit(1)

View File

@ -88,13 +88,37 @@ def exitProcess(arg):
process.terminate() process.terminate()
sys.exit(arg) sys.exit(arg)
def updateChannel(choice): def setUpdateChannel(choice):
"""
Sets the new update channel and forces new update at next launch
"""
if choice == "Beta": if choice == "Beta":
with open(globs.CNIRUrlConfig, 'w') as (configFile): with open(globs.CNIRUrlConfig, 'w') as (configFile):
configFile.write("{}\n0\n0".format(globs.CNIRBetaURL)) configFile.write("{}\n0\n0".format(globs.CNIRBetaURL))
else: # Force new update
try:
os.remove(globs.CNIRLastUpdate)
except:
pass
elif choice == "Stable":
with open(globs.CNIRUrlConfig, 'w') as (configFile): with open(globs.CNIRUrlConfig, 'w') as (configFile):
configFile.write("{}\n0\n0".format(globs.CNIRDefaultURL)) configFile.write("{}\n0\n0".format(globs.CNIRDefaultURL))
# Force new update
try:
os.remove(globs.CNIRLastUpdate)
except:
pass
def getUpdateChannel():
"""
Returns the current update channel
"""
with open(globs.CNIRUrlConfig, 'r') as (configFile):
url = configFile.read()
if not "master" in url:
return "Beta"
else:
return "Stable"
def getLatestVersion(credentials): def getLatestVersion(credentials):
""" """
@ -354,8 +378,12 @@ def umain():
credentials = downloader.newcredentials() credentials = downloader.newcredentials()
if not credentials.valid: if not credentials.valid:
logfile.printerr("Credentials Error. No effective update !") if credentials.login == "nointernet":
launcherWindow.printmsg(lang.all[globs.CNIRlang]["Credentials Error. No effective update !"]) logfile.printerr("No Internet Error. No effective update !")
launcherWindow.printmsg(lang.all[globs.CNIRlang]["No Internet Error. No effective update !"])
else:
logfile.printerr("Credentials Error. No effective update !")
launcherWindow.printmsg(lang.all[globs.CNIRlang]["Credentials Error. No effective update !"])
time.sleep(2) time.sleep(2)
launcherWindow.exit() launcherWindow.exit()
return 0 return 0

View File

@ -6,8 +6,8 @@ VSVersionInfo(
ffi=FixedFileInfo( ffi=FixedFileInfo(
# filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4) # filevers and prodvers should be always a tuple with four items: (1, 2, 3, 4)
# Set not needed items to zero 0. # Set not needed items to zero 0.
filevers=(3, 1, 5, 0), filevers=(3, 1, 6, 0),
prodvers=(3, 1, 5, 0), prodvers=(3, 1, 6, 0),
# Contains a bitmask that specifies the valid bits 'flags'r # Contains a bitmask that specifies the valid bits 'flags'r
mask=0x3f, mask=0x3f,
# Contains a bitmask that specifies the Boolean attributes of the file. # Contains a bitmask that specifies the Boolean attributes of the file.
@ -31,12 +31,12 @@ StringFileInfo(
u'040904B0', u'040904B0',
[StringStruct(u'CompanyName', u'Adrien Bourmault (neox95)'), [StringStruct(u'CompanyName', u'Adrien Bourmault (neox95)'),
StringStruct(u'FileDescription', u'This file is part of CNIRevelator.'), StringStruct(u'FileDescription', u'This file is part of CNIRevelator.'),
StringStruct(u'FileVersion', u'3.1.5'), StringStruct(u'FileVersion', u'3.1.6'),
StringStruct(u'InternalName', u'CNIRevelator'), StringStruct(u'InternalName', u'CNIRevelator'),
StringStruct(u'LegalCopyright', u'Copyright (c) Adrien Bourmault (neox95)'), StringStruct(u'LegalCopyright', u'Copyright (c) Adrien Bourmault (neox95)'),
StringStruct(u'OriginalFilename', u'CNIRevelator.exe'), StringStruct(u'OriginalFilename', u'CNIRevelator.exe'),
StringStruct(u'ProductName', u'CNIRevelator 3.1'), StringStruct(u'ProductName', u'CNIRevelator 3.1'),
StringStruct(u'ProductVersion', u'3.1.5')]) StringStruct(u'ProductVersion', u'3.1.6')])
]), ]),
VarFileInfo([VarStruct(u'Translation', [1033, 1200])]) VarFileInfo([VarStruct(u'Translation', [1033, 1200])])
] ]