Luận Văn Ứng dụng xử lý ảnh thiết kế thi công mạch chống trộm thông minh

108 132 0
Luận Văn Ứng dụng xử lý ảnh thiết kế thi công mạch chống trộm thông minh

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

Thông tin tài liệu

TR NG B B GIÁO D C & ÀO T O I H C S PH M K THU T TP H CHÍ MINH KHOA I N – I N T MÔN I N T CÔNG NGHI P – Y SINH - ÁN T T NGHI P NGÀNH CÔNG NGH K THU T I N T TRUY N THÔNG TÀI: NG D NG X LÝ NH THI T K THI CÔNG M CH CH NG TR M THÔNG MINH GVHD : ThS Võ c D ng SVTH: T ng Nguy n Công Thiên MSSV : 13141328 Tp H Chí Minh - 7/2018 TR NG B B GIÁO D C & ÀO T O I H C S PH M K THU T TP H CHÍ MINH KHOA I N – I N T MƠN I N T CÔNG NGHI P – Y SINH - ÁN T T NGHI P NGÀNH K THU T I N T TRUY N THÔNG TÀI: NG D NG X LÝ NH THI T K THI CÔNG M CH CH NG TR M THÔNG MINH GVHD : ThS Võ c D ng SVTH: T ng Nguy n Công Thiên MSSV : 13141328 Tp H Chí Minh - 7/2018 TR B NG H S PH M K THU T C NG HÒA XÃ H I CH NGH A VI T NAM TP H CHÍ MINH C L P - T DO - H NH PHÚC KHOA I N- I N T MÔN I N T CÔNG NGHI P Y SINH Tp HCM, ngày 16 tháng n m 2018 NHI M V H tên sinh viên: Chuyên ngành: H đào t o: Khóa: I TÊN TÀI: II NHI M V ÁN T T NGHI P T ng Nguy n Công Thiên i n t công nghi p i h c quy 2013 MSSV: 13141328 Mã ngành: 141 Mã h : NG D NG X LÝ NH THI T K CH NG TR M THÔNG MINH THI CÔNG M CH Các s li u ban đ u:  Matlab 2017a  S d ng Webcam Logitech  Kit u n chính: Arduino Uno R3, Servo SG90, Module Sim 800A, Ngu n t ong 10V-5A, Chuông, Led đ n N i dung th c hi n:  tài th c hi n n i dung phát hi n ng i nh n di n khuôn m t v i đ u vào hình nh l y đ c t webcam, k t qu s đ c g i qua arduino đ u n Servo SG90, Module Sim 800A, Chng, Led đ n Nhóm s th c hi n nơi dung nh sau:  Tìm hi u v Matlab  Tìm hi u v Arduino Uno R3  Cài đ t th c vi n cho Arduino liên k t gi a Matlab Arduino  Tìm hi u thu t tốn nh n di n, phát hi n ng i khn m t  Xây d ng q trình x lý nh đ u vào  Xây d ng h th ng phát hi n ng i nh n di n khuôn m t đ ng th i g i d li u thu đ c qua Arduino  Xây d ng ch ng trình u n servo SG90, Module Sim 800A, chuông, Led đ n  ánh giá k t qu th c hi n III NGÀY GIAO NHI M V : 21/03/2018 IV NGÀY HOÀN THÀNH NHI M V : 05/07/2018 V H VÀ TÊN CÁN B H NG D N: ThS Võ CÁN B H NG D N BM I N T c D ng CÔNG NGHI P - Y SINH TR B NG H S PH M K THU T TP H CHệ MINH KHOA I N- I N T MÔN I N T CƠNG NGHI P C NG HỊA XÃ H I CH NGH A VI T NAM C L P - T DO - H NH PHÚC Tp.HCM, ngày 19 tháng 03 n m 2018 L CH TRÌNH TH C HI N ÁN T T NGHI P H tên sinh viên : T ng Nguy n Công Thiên L p:13141DT3B MSSV:13141328 Tên đ tài: NG D NG X LÝ NH THI T K THI CÔNG M CH CH NG TR M THÔNG MINH Tu n/ngày N i dung (19-25/3)  G p GVHD đ ph bi n quy đ nh th c hi n, ch n đ tài, tên đ tài, th i gian làm vi c  Duy t đ tài  Vi t đ c ng cho đ tài (26/3-1/4)  Tìm hi u ho t đ ng ki n th c liên quan t i Arduino Matlab (2/4-8/4) (9/4-15/4)  Cài đ t Matlab, k t n i Arduino v i Matlab (16/4-22/4) (23/4-29/4)  Xây d ng h th ng nh n di n phát hi n chuy n đ ng ng i  Xây d ng h th ng nh n di n so sánh khuôn m t  Ti n hành xây d ng c s d li u đ l u gi khuôn m t  L p trình Arduino v i chân I/O đ nhúng d li u  Thi t k s đ kh i gi i thích ch c n ng kh i c a k t n i ngo i vi  Tính tốn s li u (30/4-6/5) (7/5-13/5)  L p trình xây d ng ch ng trình cho x lý hình nh đ u vào Matlab (14/5-20/5)  Thi công mơ hình  L p đ t k t n i thi t v ngo i vi 10 (21/5-28/5)  Ki m tra l i ch y th ch hình hồn ch nh  Vi t báo cáo hồn ch nh ng trình mơ Xác nh n GVHD 11 (29/5-3/6)  Hồn thi n s a báo cáo g i cho GVHD đ xem xét góp ý l n cu i 12 (4/6-11/6)  N p quy n báo cáo hoàn ch nh làm slide powerpoint báo cáo GV H NG D N (Ký ghi rõ h tên) ii L I CAM OAN tài nhóm sinh viên T ng Nguy n Công Thiên t th c hi n, d a vào m t s tài li u tr c khơng chép t tài li u hay cơng trình có tr c Ng i th c hi n đ tài T ng Nguy n Công Thiên iv L IC M N Trong th i gian th c hi n đ tài, nh ng ng đình, q th y b n bè nên đ tài đ i th c hi n đ c s giúp đ c a gia c hoàn thành Nh ng ng i th c hi n xin chân thành g i l i c m n đ n: Th y Võ tr c ti p h c D ng, gi ng viên tr ng i H c S Ph m K Thu t Tp.HCM ng d n t n tình giúp đ t o u ki n đ nhóm có th hồn thành t t đ tài Nh ng ng i n- i th c hi n c ng xin chân thành cám n đ n th y cô khoa i n t c a tr ng b o, cung c p cho nh ng ng i H c S Ph m K Thu t Tp.HCM t n tình d y d , ch i th c hi n nh ng ki n th c n n, chuyên môn làm c s đ hoàn thành đ tài C m n gia đình đ ng viên ln ln bên c nh nh ng lúc khó kh n nh t Xin g i l i c m n đ n nh ng ng nh ng ng i b n sinh viên khoa i n- i n t giúp đ i th c hi n đ tài đ có th hoàn thành t t đ tài Xin chân thành c m n! Ng i th c hi n đ tài: T ng Nguy n Công Thiên v M CL C Trang bìa i Nhi m v đ án ii L ch trình th c hi n đ án t t nghi p iii Cam đoan iv L i c m n v M c l c vi Li t kê hình v ix Li t kê b ng v xi Tóm t t xii CH NG T NG QUAN 1.1 Lụ DO CH N TÀI 1.2 M C TIểU 1.2.1 M c tiêu 1.2.2 Gi i h n 1.3 B C C CH NG C ÁN T T NHI P S LÝ THUY T 2.1 GI I THI U V H TH NG X Lụ NH 2.1.1 Ph n thu nh n nh (Image Acquisiton) 2.1.2 Ti n x lý (Image Processing) 2.1.3 Phân đo n (Segmentation) hay phân vùng nh 2.1.4 Bi u di n nh (Image Representation) 2.1.5 Nh n d ng n i suy (Image Recognition and Interpretation) 2.1.6 C s tri th c 2.1.7 Các thành ph n c b n c a h th ng 2.2 NH NG V N C B N TRONG X Lụ NH 2.2.1 i m nh (Picture Element) 2.2.2 phân gi i c a nh 2.2.3 M c xám c a nh 2.2.4 nh ngh a nh s vi 2.3 GI I THI U KHÁI QUÁT V CÁC LINH KI N S D NG TRONG THI T K , THI CÔNG TÀI 2.3.1 M ch Arduino Uno R3 2.3.2 T ng quan v đ ng c Servo 14 2.3.3 T ng quan v Buzzer 14 2.3.4 Module SIM 800A 15 CH NG TÍNH TỐN VÀ THI T K 16 3.1 T NG QUAN CÁC K THU T NH N BI T MÀU DA D A TRểN TệNH CH T I M NH 16 3.1.1 Gi i thi u 16 3.1.2 Không gian màu s d ng cho mơ hình hóa màu da 16 3.1.2.1 Không gian màu RGB 17 3.1.2.2 Không gian RGB chu n hóa 17 3.1.2.3 Không gian màu HIS, HSV, HSL 18 3.1.2.4 Không gian màu HIS 18 3.1.2.5 Không gian màu HSV 19 3.1.2.6 Không gian màu HSL 20 3.1.2.7 Không gian màu TSL 21 3.1.2.8 Không gian màu Y 21 3.1.2.9 Các h t a đ không gian màu khác 22 3.1.3 Mơ hình hóa màu da 22 3.1.3.1 Xác đinh ng 3.1.3.2 Ph ng c th m t m nh màu da 22 ng pháp mơ hình hóa màu da s d ng phân phôi không tham s 23 3.1.3.3 B ng tra c u chu n c u (LUT – Lookup Table) 23 3.1.3.4 Phân l p Bayes (bayes Classifier) 24 3.1.3.5 T ng k t ph ng pháp không tham s 25 3.1.3.6 Mơ hình hóa phân ph i màu da có tham s 25 3.1.3.7 Mơ hình d a phân ph i Gauss đ n 26 3.1.3.8 Mơ hình k t h p d a phân ph i Gauss 26 3.1.3.9 a phân ph i Gauss 27 3.1.3.10 T ng k t ph ng pháp mơ hình hóa theo tham s 27 3.1.4 So sánh k t qu mơ hình 27 3.1.5 ánh giá ph ng pháp 29 vii 3.1.6 Ch n l a không gian màu ph ng pháp mơ hình hóa dùn đ nh n bi t màu da cho đ án 29 3.2 PHỂN TệCH THÀNH PH N CHệNH PCA 30 3.2.1 T ng quan v ph ng pháp PCA 30 3.2.1.1 Gi i thi u 30 3.2.1.2 ụ t ng 30 3.2.2 Trích ch n đ c tr ng khuôn m t ng i d a ph ng pháp PCA 34 3.2.2.1 Chuy n đ i nh 34 3.2.2.2 Tính khn m t ng i trung bình 35 3.2.2.3 Tr m i nh cho m t trung bình 35 3.2.2.4 Xây d ng ma tr n h p ph ng sai 35 3.2.2.5 Phép chi u 36 3.3 PHÂN TÍCH HOG 37 3.3.1 Gi i thi u 37 3.3.2 Chu n hóa hình nh tr c x lý 38 3.3.3 Tính tốn gradient 38 3.3.4 L y votes m i cell 39 3.3.5 Chu n hóa block 40 3.3.6 S d ng toán object recognition 40 3.3 K T N I V I THI T B NGO I VI 41 3.4.1 Kh i x lý trung tâm 42 3.4.2 Kh i Module Sim 800A 42 3.4.3 Kh i đ ng c servo 43 3.4.4 Kh i hi n th báo đ ng 44 3.4.5 Kh i ngu n 45 3.4.6 S đ nguyên lý h th ng ngo i vi 46 CH NG THI CÔNG H TH NG 47 4.1 GI I THI U 47 4.2 THI CÔNG H TH NG 47 4.2.1 H th ng nh n hi n chuy n đ ng 47 4.2.1 H th ng nh n di n khuôn m t 50 4.2.2.1 L u đ gi i thu t c a h th ng nh n di n khuôn m t 50 4.2.2.2 L u đ gi i thu t c a h th ng hu n luy n 51 4.2.2.3 Yêu c u v d li u nh 52 viii CH NG K T LU N VÀ H 6.2 H NG PHÁT TRI N NG PHÁT TRI N Có th nâng c p h th ng b ng vi c g i d li u lên internet đ h th ng có th d dàng qu n lý t xa h n Thi t k thêm nguôn d tr dùng pin m t tr i ác-quy đ ngu n n b m t h th ng v n có th ho t đ ng bình th B MƠN I N T ng CƠNG NGHI P – Y SINH 78 TÀI LI U THAM KH O TÀI LI U THAM KH O Sách tham kh o [1] Nguy n Thanh H i, Giáo trình X lý nh, Nhà xu t b n H Qu c Gia TP HCM, 2014 [2] L ng M nh Bá Nguy n Thanh Th y, Ch ng 7, Nh p Môn X Lý nh s , Nxb Khoa h c K Thu t, 2002, trang 179-208 [3] John Boxal, “ Arduino Workshop, Willinam Pollock”, May 2013 [4] Stuart William Perry, Hau-San Wong and Ling Guan, Adaptive Image Processing: A Computational Intelligence Perspective, CEC Press LLC, 2002 [5] Kyungnam Kim, Face Recognition using Principle Component Analysis, Department of Computer Science University of MaryLand, USA, trang1-6 [6] Howard A Draper, Kyungim Baek, Marian Stewart Barlett, J Ross Bervridge, “Recognizing Faces with PCA and ICA”, 2004, trang 1-24 DATASHEET [7] Arduino Uno R3, https://www.arduino.cc/en/uploads/Main/arduino-mega2560_R3schematic.pdf [8] Sim 800A, http://simcomm2m.com/En/module/detail.aspx?id=138 [9] T p l nh AT, http://www.espruino.com/datasheets/SIM900_AT.pdf [10] B ng c Servo, http://www.micropik.com/PDF/SG90Servo.pdf MÔN I N T CÔNG NGHI P – Y SINH 79 PH L C PH L C CH I Ch NG TRÌNH C A T NG H TH NG ng trình c a h th ng nh n di n vƠ phát hi n chuy n đ ng function varargout = giaodien123(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, 'gui_Singleton', gui_Singleton, 'gui_OpeningFcn', @giaodien123_OpeningFcn, 'gui_OutputFcn', @giaodien123_OutputFcn, 'gui_LayoutFcn', [] , 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function giaodien123_OpeningFcn(hObject, eventdata, handles, varargin) guidata(hObject, handles); function varargout = giaodien123_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function figure1_CreateFcn(hObject, eventdata, handles) im = imread('GetArticleImage.jpg'); imshow(im); function pushbutton1_Callback(hObject, eventdata, handles) global s; s=serial('COM6'); fopen(s); i=0; peopleDetector = vision.PeopleDetector('MergeDetections',true); peopleDetector.ClassificationThreshold =2; pointTracker = vision.PointTracker('MaxBidirectionalError', 2); cam = webcam(); videoFrame = snapshot(cam); frameSize = size(videoFrame); videoPlayer = vision.VideoPlayer('Position', [100 100 [frameSize(2), frameSize(1)]+30]); runLoop = true; numPts = 0; frameCount = 0; while runLoop videoFrame = snapshot(cam); videoFrameGray = rgb2gray(videoFrame); B MÔN I N T CÔNG NGHI P – Y SINH 80 PH L C frameCount = frameCount + 1; if numPts < 10 bbox = step(peopleDetector,videoFrame); if ~isempty(bbox) points = detectMinEigenFeatures(videoFrameGray, 'ROI', bbox(1, :)); xyPoints = points.Location; numPts = size(xyPoints,1); release(pointTracker); initialize(pointTracker, xyPoints, videoFrameGray); oldPoints = xyPoints; bboxPoints = bbox2points(bbox(1, :)); bboxPolygon = reshape(bboxPoints', 1, []); D=1; videoFrame = insertObjectAnnotation(videoFrame,'rectangle',bbox,D); end else [xyPoints, isFound] = step(pointTracker, videoFrameGray); visiblePoints = xyPoints(isFound, :); oldInliers = oldPoints(isFound, :); numPts = size(visiblePoints, 1); if numPts >= 30 bbox = step(peopleDetector,videoFrame); [xform, oldInliers, visiblePoints] = estimateGeometricTransform( oldInliers, visiblePoints, 'similarity', 'MaxDistance', 4); bboxPoints = transformPointsForward(xform, bboxPoints); bboxPolygon = reshape(bboxPoints', 1, []); D=1; videoFrame = insertObjectAnnotation(videoFrame,'rectangle',bbox,D); step(videoPlayer,videoFrame); oldPoints = visiblePoints; setPoints(pointTracker, oldPoints); if i==0 fwrite(s,2) end i=1; end end step(videoPlayer, videoFrame); runLoop = isOpen(videoPlayer); end clear cam; release(videoPlayer); release(pointTracker); close; function figure1_DeleteFcn(hObject, eventdata, handles) global s; fwrite(s,0); out = instrfind; fclose(out); B MÔN I N T CÔNG NGHI P – Y SINH 81 PH L C function pushbutton2_Callback(hObject, eventdata, handles) global s; fwrite(s,0); out = instrfind; fclose(out); II Ch ng trình c a h th ng nh n di n khuôn m t function varargout = regconition(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, 'gui_Singleton', gui_Singleton, 'gui_OpeningFcn', @regconition_OpeningFcn, 'gui_OutputFcn', @regconition_OutputFcn, 'gui_LayoutFcn', [] , 'gui_Callback', []); if nargin && ischar(varargin{1}) gui_State.gui_Callback = str2func(varargin{1}); end if nargout [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:}); else gui_mainfcn(gui_State, varargin{:}); end function regconition_OpeningFcn(hObject, eventdata, handles, varargin) handles.output = hObject; guidata(hObject, handles); function varargout = regconition_OutputFcn(hObject, eventdata, handles) varargout{1} = handles.output; function figure1_CreateFcn(hObject, eventdata, handles) global q; q = serial('com3'); fopen(q); im = imread('GetArticleImage.jpg'); imshow(im); function pushbutton1_Callback(hObject, eventdata, handles) global co if isfield(handles,'vdx') vid = handles.vdx; stoppreview(vid) delete(vid) handles = rmfield(handles,'vdx'); guidata(hObject,handles) cla(handles.axes1) reset(handles.axes1) B MÔN I N T CÔNG NGHI P – Y SINH 82 PH L C set(handles.axes1,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) cla(handles.axes2) reset(handles.axes2) set(handles.axes2,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) end fd = vision.CascadeObjectDetector(); fd.MergeThreshold = 15; info = imaqhwinfo('winvideo'); did = info.DeviceIDs; if isempty(did) msgbox({'YOUR SYSTEM DO NOT HAVE A WEBCAM';' ';'CONNECT A ONE'},'WARNING !!!!','warn','modal') return end did = cell2mat(did); for k = 1:length(did) devinfo = imaqhwinfo('winvideo',k); na(1,k) = {devinfo.DeviceName}; sr(1,k) = {devinfo.SupportedFormats}; end [a,b] = listdlg('promptstring','SELECT A WEB CAM DEVICE','liststring',na,'ListSize', [125, 75],'SelectionMode','single'); if b == return end if b ~= frmt = sr{1,a}; [a1,b1] = listdlg('promptstring','SELECT RESOLUTION','liststring',frmt,'ListSize', [150, 100],'SelectionMode','single'); if b1 == return end end frmt = frmt{a1}; l = find(frmt == '_'); res = frmt(l+1 : end); l = find(res == 'x'); res1 = str2double(res(1: l-1)); res2 = str2double(res(l+1 : end)); axes(handles.axes1) vid = videoinput('winvideo', a); vr = [res1 res2]; nbands = get(vid,'NumberofBands'); h2im = image(zeros([vr(2) vr(1) nbands] , 'uint8')); preview(vid,h2im); handles.vdx = vid; guidata(hObject,handles) tx = msgbox('PLZ STAND IN FRONT OF CAMERA STILL','INFO !!!'); B MÔN I N T CÔNG NGHI P – Y SINH 83 PH L C pause(1) delete(tx) kx = 0; while im = getframe(handles.axes1); im = im.cdata; bbox = step(fd, im); vo = insertObjectAnnotation(im,'rectangle',bbox,'FACE'); axes(handles.axes2) imshow(vo) if size(bbox,1) > msgbox({'TOO MANY FACES IN FRAME';' ';'ONLY ONE FACE IS ACCEPTED'},'WARNING !!!','warn','modal') uiwait stoppreview(vid) delete(vid) handles = rmfield(handles,'vdx'); guidata(hObject,handles) cla(handles.axes1) reset(handles.axes1) set(handles.axes1,'box','on','xtick',[],'ytick',[],'xcolor',[1 1],'ycolor',[1 1],'color',co,'linewidth',1.5) cla(handles.axes2) reset(handles.axes2) set(handles.axes2,'box','on','xtick',[],'ytick',[],'xcolor',[1 1],'ycolor',[1 1],'color',co,'linewidth',1.5) return end kx = kx + 1; if kx > 10 && ~isempty(bbox) break end end imc = imcrop(im,[bbox(1)+3 bbox(2)-35 bbox(3)-10 bbox(4)+70]); imx = imresize(imc,[300 300]); fhx = figure(2); set(fhx,'menubar','none','numbertitle','off','name','PREVIEW') imshow(imx) cd ('database'); l = length(dir(pwd)); n = [int2str(l-1) '.jpg']; imwrite(imx,n); cd while qq = inputdlg('WHAT IS UR NAME?','FILL'); if isempty(qq) msgbox({'YOU HAVE TO ENTER A NAME';' ';'YOU CANT CLICK CANCEL'},'INFO','HELP','MODAL') uiwait else break B MÔN I N T CÔNG NGHI P – Y SINH 84 PH L C end end qq = qq{1}; if exist('info.mat','file') == load ('info.mat') r = size(z2,1); z2{r+1,1} = {n , qq}; save('info.mat','z2') else z2{1,1} = {n,qq}; save('info.mat','z2') end close gcf stoppreview(vid) delete(vid) handles = rmfield(handles,'vdx'); guidata(hObject,handles) cla(handles.axes1) reset(handles.axes1) cla(handles.axes2) reset(handles.axes2) function pushbutton2_Callback(hObject, eventdata, handles) flist = dir('database'); if length(flist) == msgbox('NOTHING TO DELETE','INFO','modal'); return end cd('database') [f,p] = uigetfile('*.jpg','SELECT A PIC TO DELETE IT'); if f == cd return end p1 = fullfile(p,f); delete(p1) flist = dir(pwd); if length(flist) == cd return end for k = 3:length(flist) z = flist(k).name; z(strfind(z,'.') : end) = []; nlist(k-2) = str2double(z); end nlist = sort(nlist); h = waitbar(0,' MATLAB IS RENAMING','name','PROGRESS '); for k = 1:length(nlist) if k ~= nlist(k) p = nlist(k); B MÔN I N T CÔNG NGHI P – Y SINH 85 PH L C movefile([num2str(p) '.jpg'] , [num2str(k) '.jpg']) waitbar((k-2)/length(flist),h,sprintf('RENAMED %s to %s',[num2str(p) '.jpg'],[num2str(k) '.jpg'])) end pause(.5) end close(h) cd function pushbutton4_Callback(hObject, eventdata, handles) runLoop = true; global co global q; if exist('features.mat','file') == msgbox('FIRST TRAIN YOUR DATABASE','INFO !!!','MODAL') return end ff = dir('database'); if length(ff) == h = waitbar(0,'Xin ch? ','name','SCANNING IS IN PROGRESS'); for k = 1:100 waitbar(k/100) pause(0.03) end close(h) msgbox({'NO IMAGE FOUND IN DATABASE';'FIRST LOAD YOUR DATABASE';'USE ''ADD NEW IMAGE'' MENU'},'WARNING !!!','WARN','MODAL') return end if isfield(handles,'vdx') vid = handles.vdx; stoppreview(vid) delete(vid) handles = rmfield(handles,'vdx'); guidata(hObject,handles) cla(handles.axes1) reset(handles.axes1) set(handles.axes1,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) cla(handles.axes2) reset(handles.axes2) set(handles.axes2,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) end info = imaqhwinfo('winvideo'); did = info.DeviceIDs; if isempty(did) msgbox({'YOUR SYSTEM DO NOT HAVE A WEBCAM';' ';'CONNECT A ONE'},'WARNING !!!!','warn','modal') return B MÔN I N T CÔNG NGHI P – Y SINH 86 PH L C end fd = vision.CascadeObjectDetector(); fd.MergeThreshold =15; did = cell2mat(did); for k = 1:length(did) devinfo = imaqhwinfo('winvideo',k); na(1,k) = {devinfo.DeviceName}; sr(1,k) = {devinfo.SupportedFormats}; end [a,b] = listdlg('promptstring','SELECT A WEB CAM DEVICE','liststring',na,'ListSize', [125, 75],'SelectionMode','single'); if b == return end if b ~= frmt = sr{1,a}; [a1,b1] = listdlg('promptstring','SELECT RESOLUTION','liststring',frmt,'ListSize', [150, 100],'SelectionMode','single'); if b1 == return end end while runLoop frmt = sr{1,a}; frmt = frmt{a1}; l = find(frmt == '_'); res = frmt(l+1 : end); l = find(res == 'x'); res1 = str2double(res(1: l-1)); res2 = str2double(res(l+1 : end)); axes(handles.axes1) vid = videoinput('winvideo', a); vr = [res1 res2]; nbands = get(vid,'NumberofBands'); h2im = image(zeros([vr(2) vr(1) nbands] , 'uint8')); preview(vid,h2im); handles.vdx = vid; guidata(hObject,handles) tx = msgbox('XIN DUNG YEN TRUOC CAMERA','INFO !!!'); pause(1) delete(tx) kx = 0; while im = getframe(handles.axes1); im = im.cdata; bbox = step(fd, im); vo = insertObjectAnnotation(im,'rectangle',bbox,'FACE'); axes(handles.axes2) imshow(vo) if size(bbox,1) > B MÔN I N T CÔNG NGHI P – Y SINH 87 PH L C msgbox({'QUA NHIEU KHUON MAT';' ';'CHI DUOC MOT KHUON MAT'},'WARNING !!!','warn','modal') uiwait stoppreview(vid) delete(vid) handles = rmfield(handles,'vdx'); guidata(hObject,handles) cla(handles.axes1) reset(handles.axes1) set(handles.axes1,'box','on','xtick',[],'ytick',[],'xcolor',[1 1],'ycolor',[1 1],'color',co,'linewidth',1.5) cla(handles.axes2) reset(handles.axes2) set(handles.axes2,'box','on','xtick',[],'ytick',[],'xcolor',[1 1],'ycolor',[1 1],'color',co,'linewidth',1.5) return end kx = kx + 1; if kx > 10 && ~isempty(bbox) break end end imc = imcrop(im,[bbox(1)+3 bbox(2)-35 bbox(3)-10 bbox(4)+70]); imx = imresize(imc,[300 300]); axes(handles.axes1) image(imx) text(20,20,'\bfHINH HIEN TAI.','fontsize',12,'color','y','fontname','comic sans ms') set(handles.axes1,'xtick',[],'ytick',[],'box','on') immxx = imx; zz = findsimilar(immxx); zz = strtrim(zz); fxz = imread(['database/' zz]); q1= ehd(immxx,0.1); q2 = ehd(fxz,0.1); q3 = pdist([q1 ; q2]); disp(q3) if q3 < 0.5 axes(handles.axes2) image(fxz) set(handles.axes1,'xtick',[],'ytick',[],'box','on') text(20,20,'\bf HINH LUU TRU.','fontsize',12,'color','y','fontname','comic sans ms') set(handles.axes2,'xtick',[],'ytick',[],'box','on') xs = load('info.mat'); xs1 = xs.z2; for k = 1:length(xs1) st = xs1{k}; stx = st{1}; if strcmp(stx,zz) == str = st{2}; break end B MÔN I N T CÔNG NGHI P – Y SINH 88 PH L C end fid = fopen('attendence_sheet.txt','a'); fprintf(fid,'%s %s %s %s\r\n\n', 'Name','Date','Time', 'Attendence'); c = clock; if c(4) > 12 s = [num2str(c(4)-12) ,':',num2str(c(5)), ':', num2str(round(c(6))) ]; else s = [num2str(c(4)) ,':',num2str(c(5)), ':', num2str(round(c(6))) ]; end fwrite(q,1) pause(4) else msgbox('BAN KHONG PHAI NGUOI TRONG NHA', 'WARNING','WARN','MODAL') cla(handles.axes1) reset(handles.axes1) cla(handles.axes2) reset(handles.axes2) fwrite(q,3); end pause(5); end function pushbutton5_Callback(hObject, eventdata, handles) f = dir('database'); if length(f) == msgbox('YOUR DATA BASE HAS NO IMAGE TO DISPLAY','SORRY','modal') return end l = length(f)-2; while a = factor(l); if length(a) >= break end l = l+1; end d = a(1: ceil(length(a)/2)); d = prod(d); d1 = a(ceil(length(a)/2)+1 : end); d1 = prod(d1); zx = sort([d d1]); figure('menubar','none','numbertitle','off','name','Images of Database','color',[0.0431 0.5176 0.7804],'position',[300 200 600 500]) for k = 3:length(f) im = imread(f(k).name); subplot(zx(1),zx(2),k-2) imshow(im) title(f(k).name,'fontsize',10,'color','w') end B MÔN I N T CÔNG NGHI P – Y SINH 89 PH L C function pushbutton6_Callback(hObject, eventdata, handles) x = questdlg({'Tat Ca Du Lieu Se Bi Xoa'},'Please select !!'); if strcmpi(x,'yes') == delete('attendence_sheet.txt') delete('features.mat') delete('info.mat') cd ([pwd, '\database']) f = dir(pwd); for k = 1:length(f) delete(f(k).name) end cd cla(handles.axes1); reset(handles.axes1); set(handles.axes1,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) cla(handles.axes2); reset(handles.axes2); set(handles.axes2,'box','on','xcolor','w','ycolor','w','xtick',[],'ytick',[],'color',[0.0431 0.5176 0.7804],'linewidth',1.5) beep msgbox('All Reset','Info','modal') end function pushbutton7_Callback(hObject, eventdata, handles) if exist('attendence_sheet.txt','file') == winopen('attendence_sheet.txt') else msgbox('NO ATTENDENCE SHEET TO DISPLAY','INFO !!!','HELP','MODAL') end function pushbutton8_Callback(hObject, eventdata, handles) ff = dir('database'); if length(ff) == h = waitbar(0,'Xin Doi Trong Giay Lat','name','SCANNING IS IN PROGRESS'); for k = 1:100 waitbar(k/100) pause(0.03) end close(h) msgbox({'NO IMAGE FOUND IN DATABASE';'FIRST LOAD YOUR DATABASE';'USE ''ADD NEW IMAGE'' MENU'},'WARNING !!!','WARN','MODAL') return end if exist('features.mat','file') == bx = questdlg({'TRAINING HAS ALREDY BEEN DONE';' ';'WANT TO TRAIN DATABASE AGAIN?'},'SELECT','YES','NO','CC'); if strcmpi(bx,'yes') == builddatabase msgbox('TRAINING DONE PRESS OK TO CONTINUE','OK','modal') B MÔN I N T CÔNG NGHI P – Y SINH 90 PH L C return else return end else builddatabase msgbox('TRAINING DONE PRESS OK TO CONTINUE','OK','modal') return end function figure1_DeleteFcn(hObject, eventdata, handles) if ~isempty(instrfind) fclose(instrfind); delete(instrfind); end III CH NG TRÌNH H TH NG NGO I VI #include "SoftwareSerial.h" #include "Hshopvn_GSM.h" #include SoftwareSerial sim800ds(2, 3); HshopGSM HGSM = HshopGSM(&sim800ds); String Str_PhoneNum = "01672131349"; unsigned long UL_PhoneNum = 1672131349; Servo myservo; int data =0; int servoPin = 10; int j=1; int led = 4; int bell = 9; int i; void setup() { Serial.begin(9600); HGSM.init(&GSM_Ready, 9600); pinMode(led, OUTPUT); pinMode(bell, OUTPUT); myservo.attach(servoPin); myservo.write(130); } void loop() { HGSM.handle(); if(Serial.available()>0){ data = Serial.read(); j=1; B MÔN I N T CÔNG NGHI P – Y SINH 91 PH L C i=1; } if (data == 2) { digitalWrite(led,HIGH); delay(1000); digitalWrite(led,LOW); delay(1000); digitalWrite(bell,HIGH); if (i==1){ HGSM.sendsms(Str_PhoneNum, "BAO DONG CO TROM "); i =i + 1; } } else if (data == 1) { if (j==1){ myservo.write(0); delay(4000); myservo.write(130); j=j+1; } } else { digitalWrite(led,LOW); digitalWrite(bell,LOW); } } void GSM_Ready() { if (HGSM.getDataGSM() != "") { Serial.println(HGSM.getDataGSM()); //show data comming } else; } B MÔN I N T CÔNG NGHI P – Y SINH 92 ... H CHÍ MINH KHOA I N – I N T MÔN I N T CÔNG NGHI P – Y SINH - ÁN T T NGHI P NGÀNH K THU T I N T TRUY N THÔNG TÀI: NG D NG X LÝ NH THI T K THI CÔNG M CH CH NG TR M THÔNG MINH GVHD... đ án Ch ng 2: C s lý thuy t  Gi i thi u v h th ng x lý nh  Nh ng v n đ h th ng x lý nh  Gi i thi u khái quát v linh ki n s d ng thi t k , thi công đ tài Ch ng 3: Tính tốn thi t k  T ng quan... n i v i thi t b ngo i vi B MÔN I N T CÔNG NGHI P – Y SINH CH NG T NG QUAN Ch ng 4: Thi cơng gi i thi u ch ng trình  Gi i thi u  Thi công h th ng  Gi i thi u ch ng trình  óng gói thi cơng

Ngày đăng: 16/11/2019, 15:19

Từ khóa liên quan

Tài liệu cùng người dùng

Tài liệu liên quan