Professional Documents
Culture Documents
NEURAL NETWORK
DEEP LEARNING
New Comer
result: [[0.]]
neighbours: [[0. 1.
0.]]
distance: [[196.
289. 314.]]
IRIS. DATA
• Cài đặt phần mềm python-mnist có nhiệm vụ lấy thông tin từ tập
dữ liệu MNIST , trong command windows gõ pip install python-
mnist
• Khi viết chương trình knn, dùng lệnh sau
from mnist import MNIST
mndata = MNIST(‘đường dẫn thư mục chứa các file MNIST')
images, labels = mndata.load_training()
test, labeltest=mndata.load_testing()
• images, test là ma trận, mỗi hàng tương ứng một số, là vector 768
phần tử có giá trị là cường độ mỗi điểm ảnh,
TS NGUYỄN ĐỨC THÀNH 33
MNIST OCR HANDWRITTEN KNN PYTHON
• labes, labeltest là ma trận một cột, mỗi hàng là số từ 0 đến 9, số hàng
tùy thuộc số ảnh.
• Chương trình e:/computer vision/Project 2018/MNIST
HANDWRITTEN DIGIT/MINISTOCRHandWrittenDigitKNN.py
import winsound
frequency = 2500 # Set Frequency To 2500 Hertz
duration = 1000 # Set Duration To 1000 ms == 4 second
import time
import numpy as np
import cv2
from matplotlib import pyplot as plt
from mnist import MNIST
mnist = MNIST('e:/computer vision/MNIST/')
img_train, lbl_train = mnist.load_training()
img_test, lbl_test = mnist.load_testing()
Nhận dạng tiếng Việt có phần mềm VietOCR kết hợp Tesseract
download từ http://taimienphi.vn/download-vietocr-37671/taive
Giải nén, chạy file ocr.bat trong e:/computer vision/vietocr
Vào menu file open chọn file ảnh hay PDF… open, file sẽ xua61tt
hiện ở bên trái, chọn Command OCR d8e63 tách văn bả tiếng
Việt xuất hiện ở bên phải . Vào File Save để lưu văn bản vào đĩa.
TS NGUYỄN ĐỨC THÀNH 49
TESSERACT OCR VIETOCR
Tesseract làm việc tốt với chữ đen trên nền trắng, ký tự theo chiều
ngang và kích thước lớn họn 20 pixel
.. PA
I . SPECIAL i3LA'rE
REQUIRED
UNAUTHORIZED
VEHICLES L
- MAY BE ‘rowan E
AT OWNERS
'
TS NGUYỄN ĐỨC THÀNH 63
Automatically Detect and Recognize Text in Natural
Images
Có những vùng không văn bản bị nhầm,
để khắc phục ta dùng các tính chất hình
học của văn bản. Dùng hàm regionprops
để xét tính chất hình học các vùng
mserStats = regionprops(mserConnComp,
'BoundingBox', 'Eccentricity', ...
'Solidity', 'Extent', 'Euler', 'Image');
bbox = vertcat(mserStats.BoundingBox);
w = bbox(:,3);
h = bbox(:,4);
aspectRatio = w./h;
% Threshold the data to determine which
regions to remove. These thresholds
% may need to be tuned for other images.
TS NGUYỄN ĐỨC THÀNH 64
Automatically Detect and Recognize Text in
Natural Images
filterIdx = aspectRatio' > 3;
filterIdx = filterIdx | [mserStats.Eccentricity] > .995 ;
filterIdx = filterIdx | [mserStats.Solidity] < .3;
filterIdx = filterIdx | [mserStats.Extent] < 0.2 | [mserStats.Extent] > 0.9;
filterIdx = filterIdx | [mserStats.EulerNumber] < -4;
% Remove regions
mserStats(filterIdx) = []; mserRegions(filterIdx) = [];
% Show remaining regions
Figure;imshow(I);hold on
plot(mserRegions, 'showPixelList', true,'showEllipses',false)
title('After Removing Non-Text Regions Based On Geometric
Properties');hold off
TS NGUYỄN ĐỨC THÀNH 65
Automatically Detect and Recognize Text in
Natural Images
%Classify
[label,scores] = classify(net,I);
figure
imshow(I)
title(string(label) + ", " +
num2str(100*scores(classNames
== label),3) + "%");