No ACL setup yet! Denying access to everyone.
en:edu:zmitac:ai:projects:idrecognition
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| en:edu:zmitac:ai:projects:idrecognition [2018/04/13 22:48] – [1. Co to jest MRZ] maribaj746 | en:edu:zmitac:ai:projects:idrecognition [2018/04/13 23:20] (current) – [2.3 Video MRZ Recognition] maribaj746 | ||
|---|---|---|---|
| Line 6: | Line 6: | ||
| |{{: | |{{: | ||
| - | ====2. | + | ====2. |
| - | Program do odczytu strefy MRZ został napisyany w języku **PYTHON | + | Application are written in Python language |
| - | Po uruchomieniu program wyświetli nam listę zadań które można wykonać: | + | After application launch we can see menu: |
| {{ : | {{ : | ||
| ====2.1 Start Training ==== | ====2.1 Start Training ==== | ||
| - | Uczenie Nadzorowane | + | Supervised learning- it is a function, that generate neccessary data for KNN classifier. |
| - | **Algorytm działania:** | + | **Working algorithm:** |
| ^Step ^Description ^ | ^Step ^Description ^ | ||
| - | | 1 | Wyświetl przygotowany przez użytkownika plik z danymi wzorcowymi | + | | 1 | Shows file prepared by user which contains pattern data (characters are written using OCR-B font). In this file every character is prepared several time in a different size.{{: |
| - | |2|Funkcja nakłada niezbędne filtry na plik z danymi:<code python> | + | |2|Function put some neccessary filters on file with data:<code python> |
| gray = cv2.cvtColor(im, | gray = cv2.cvtColor(im, | ||
| blur = cv2.GaussianBlur(gray, | blur = cv2.GaussianBlur(gray, | ||
| thresh = cv2.adaptiveThreshold(blur, | thresh = cv2.adaptiveThreshold(blur, | ||
| - | </ | + | </ |
| - | |3 |Następnie funkcja wyszukuje znaki, wycina oraz skaluje do rozmiaru | + | |3 |In the next step function find characters, crop and scale it to size 20x20 pixels:<code python> |
| image, contours, _ = cv2.findContours(thresh, | image, contours, _ = cv2.findContours(thresh, | ||
| for cnt in contours: | for cnt in contours: | ||
| Line 33: | Line 33: | ||
| roi = thresh[y:y + h, x:x + w] | roi = thresh[y:y + h, x:x + w] | ||
| roismall = cv2.resize(roi, | roismall = cv2.resize(roi, | ||
| - | </ | + | </ |
| - | |4 |Następnie Użytkownik jest proszony o wpisanie na klawiaturze jaki to znak. Po tej operacji obraz oraz numer znaku jest zapisywany w tablicy pamięci programu. | | + | |4 |In the last step user is obligate |
| - | |5 |Po klasyfikacji wszystkich znaków tablice danych są zapisane na dysku <code python> | + | |5 |When all characters are classified the arrays were save in drive <code python> |
| np.savetxt(' | np.savetxt(' | ||
| np.savetxt(' | np.savetxt(' | ||
| </ | </ | ||
| ====2.2 Verify Engine ==== | ====2.2 Verify Engine ==== | ||
| - | Testowanie i weryfikacja „nauczenia Sieci | + | Testing and verification " |
| ^Step ^Description ^ | ^Step ^Description ^ | ||
| - | | 1 |Inicjujemy Silnik sieci oraz ładujemy dane uczące: <code python> | + | | 1 |We initialize engine and load data to learning: <code python> |
| self.samples = np.loadtxt(" | self.samples = np.loadtxt(" | ||
| self.responses = np.loadtxt(" | self.responses = np.loadtxt(" | ||
| Line 48: | Line 48: | ||
| self.model.train(self.samples, | self.model.train(self.samples, | ||
| </ | </ | ||
| - | | 2 |Funkcja lądujemy obrazek z danymi testowymi. {{ : | + | | 2 |Function load picture with test data. {{ : |
| - | | 3 |Nakładamy niezbędne filtry | + | | 3 |We put necessary filters |
| - | | 4 |Na podstawie konturów extraktujemy pojedyncze linie (uwaga sprawdzamy czy są rozpoznane 3 linie (obligatoryjnie dowód posiada | + | | 4 |Based on contours we extract single lines. We have to check that our application recognize |
| ef extract_lines(self, | ef extract_lines(self, | ||
| line_list = {} | line_list = {} | ||
| Line 73: | Line 73: | ||
| return None | return None | ||
| </ | </ | ||
| - | | 5 |Wycinamy obrazki | + | | 5 |We cut and extract pictures of each lines based on parameters from extract_lines |
| def decode(self, | def decode(self, | ||
| if len(image) > 0 and image is not None: | if len(image) > 0 and image is not None: | ||
| Line 88: | Line 88: | ||
| return None | return None | ||
| </ | </ | ||
| - | | 6 |Funkcja | + | | 6 |OCR function extract character from lines using extract_chars_from_line |
| def extract_chars_from_line(self, | def extract_chars_from_line(self, | ||
| image, contours, _ = cv2.findContours(image, | image, contours, _ = cv2.findContours(image, | ||
| Line 100: | Line 100: | ||
| lista_rect[x] = [x, y, w, h] | lista_rect[x] = [x, y, w, h] | ||
| return sorted(lista_rect.items()) | return sorted(lista_rect.items()) | ||
| - | </ | + | </ |
| def validate(self, | def validate(self, | ||
| print "Read Data: %s" % read_data | print "Read Data: %s" % read_data | ||
| Line 126: | Line 126: | ||
| return Accuracy | return Accuracy | ||
| </ | </ | ||
| - | | 7 |Zwrócony String w postaci tablicy | + | | 7 |Returned string in form of 3 lines array we compare with our prepared pattern. Counting all positive and negaive recognition we calculate accuracy of our engine.<code python> |
| def validate(self, | def validate(self, | ||
| print "Read Data: %s" % read_data | print "Read Data: %s" % read_data | ||
| Line 153: | Line 153: | ||
| </ | </ | ||
| ====2.3 Photo MRZ Recognition ==== | ====2.3 Photo MRZ Recognition ==== | ||
| - | Zadaniem tego Modul jest zdekodowanie strefy | + | This module is responsible for decoding |
| - | Algorytm działania: | + | |
| ^Step ^Description ^ | ^Step ^Description ^ | ||
| - | | 1 | Program Włącza kamerę i wyświetla obraz, użytkownik robi zdjęcie naciskając klawisz „SPACE” , klawisz „q” zamyka | + | | 1 | Application turn on camera and shows image, user are taking picture using ' |
| def capture_process(self, | def capture_process(self, | ||
| cap = cv2.VideoCapture(cam) | cap = cv2.VideoCapture(cam) | ||
| Line 172: | Line 171: | ||
| break | break | ||
| </ | </ | ||
| - | | 2 |Po zrobieniu zdjecia na obraz nakładane są niezbędne filtry a następnie obraz jest przekazany do funkcji oryginalny obraz oraz obraz z nałożonymi filtrami jest przekazany do funkcji locate_MRZ która | + | | 2 |When picture are taken necessary filters are put and picture is passing |
| def filtr(self, image): | def filtr(self, image): | ||
| rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT, | rectKernel = cv2.getStructuringElement(cv2.MORPH_RECT, | ||
| Line 203: | Line 202: | ||
| thresh[:, image.shape[1] - p:] = 0 | thresh[:, image.shape[1] - p:] = 0 | ||
| return thresh | return thresh | ||
| - | </ | + | </ |
| def locate_MRZ(self, | def locate_MRZ(self, | ||
| _oryginal = cv2.adaptiveThreshold(_oryginal, | _oryginal = cv2.adaptiveThreshold(_oryginal, | ||
| Line 218: | Line 217: | ||
| result = _oryginal[y: | result = _oryginal[y: | ||
| return self.decode(result) | return self.decode(result) | ||
| - | </ | + | </ |
| - | | 3 | Takie zdjęcie przekazane jest do funkcji | + | | 3 | This picture are passing to Decode |
| def decode(self, | def decode(self, | ||
| if len(image) > 0 and image is not None: | if len(image) > 0 and image is not None: | ||
| Line 234: | Line 233: | ||
| return None | return None | ||
| </ | </ | ||
| - | | 4 |Funkcja | + | | 4 |OCR function extract characters of every line using extract_chars_from_line |
| def extract_chars_from_line(self, | def extract_chars_from_line(self, | ||
| image, contours, _ = cv2.findContours(image, | image, contours, _ = cv2.findContours(image, | ||
| Line 246: | Line 245: | ||
| lista_rect[x] = [x, y, w, h] | lista_rect[x] = [x, y, w, h] | ||
| return sorted(lista_rect.items()) | return sorted(lista_rect.items()) | ||
| - | </ | + | </ |
| self.clear_folder(' | self.clear_folder(' | ||
| result = "" | result = "" | ||
| Line 267: | Line 266: | ||
| return result | return result | ||
| </ | </ | ||
| - | | 5 | Wynik jest zwracany na konsolę w formie tekstowej.| | + | | 5 | Result are printed to console.| |
| ====2.3 Video MRZ Recognition ==== | ====2.3 Video MRZ Recognition ==== | ||
| - | Zadaniem tego Modul jest zdekodowanie strefy | + | The task of this module is decoding |
| {{ : | {{ : | ||
en/edu/zmitac/ai/projects/idrecognition.1523652530.txt.gz · Last modified: by maribaj746
