Thiết kế Camera giám sát

18 14 0
Thiết kế Camera giám sát

Đ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

Camera quan sát hay camera giám sát, camera an ninh (Closedcircuit television CCTV)12, là việc sử dụng các máy quay video để truyền tín hiệu đến một nơi cụ thể, trên một số màn hình giới hạn. Nó khác với truyền hình quảng bá ở chỗ tín hiệu không được truyền công khai, mặc dù nó có thể sử dụng liên kết điểmđiểm (P2P), điểmđa điểm (P2MP) hoặc liên kết có dây hoặc không dây dạng lưới. Mặc dù hầu hết tất cả các máy quay video đều phù hợp với định nghĩa này, thuật ngữ này thường được áp dụng cho những máy ảnh được sử dụng để giám sát trong các khu vực yêu cầu bảo mật bổ sung hoặc giám sát liên tục. Mặc dù videotelephony hiếm khi được gọi là CCTV, một ngoại lệ là việc sử dụng video trong giáo dục từ xa, nơi nó là một công cụ quan trọng

KHOA CÔNG NGHỆ ĐIỆN – ĐIỆN TỬ BỘ MÔN TỰ ĐỘNG HÓA  THIẾT KẾ CAMERA GIÁM SÁT TP HỒ CHÍ MINH, tháng 12 năm 2020 Mục lục Mục lục CHƯƠNG I GIỚI THIỆU ĐỀ TÀI .3 Mục tiêu đề tài .3 Hoạt động .3 Thực .3 Sản phẩm hoàn thiện CHƯƠNG II PHẦN CỨNG .5 Động bước .5 Webcam Mạch điều khiển động .6 CHƯƠNG III PHẦN MỀM Thuật toán xử lý ảnh Điều khiển động bước .8 Code chương trình 10 CHƯƠNG IV TỔNG KẾT 17 Đánh giá .17 Hướng phát triển 18 CHƯƠNG I GIỚI THIỆU ĐỀ TÀI Mục tiêu đề tài  Thiết kế camera an ninh bám theo chuyển động vùng khơng gian xác định-có giao tiếp, điều khiển máy tính  Xây dựng giao diện phần mềm có hiệu giám sát cao, dễ sử dụng, nhiều tính Hoạt động Camera có tác dụng giám sát chuyển động phạm vi giới hạn, ví dụ phịng kín  Khi có đối tượng xâm nhập vào phạm vi giám sát Camera có tín hiệu báo động cho người (còi báo động đèn báo động)  Khi đối tượng chuyển động, Camera điều khiển động bước tiếp tục bám theo đối tượng, đưa tín hiệu báo động đồng thời liên tiếp chụp lại ảnh đối tượng Thực  Phần cứng Camera (webcam) thu tín hiệu hình ảnh gửi cho máy tính xử lý Webcam kết nối với máy tính cổng USB thơng dụng Trước hoạt động, webcam cần cài sẵn driver nhà sản xuất Để truyền động cho động cơ, ta sử dụng động bước Theo đó, đế Camera gắn trực tiếp lên trục động đặt thẳng đứng Khi trục động quay, camera quay mặt phẳng ngang vng góc với trục động Mạch điều khiển động bước lấy xung từ cống LPT máy tính qua cách ly quang IC đệm công suất để cấp xung cho cuộn dây động  Phần mềm Lập trình điều khiển camera ngôn ngữ matlab với ưu điểm khả tính tốn mạnh đồng thời hỗ trợ nhiều hàm thu thập xử lý hình ảnh từ thiết bị số camera Chương trình viết GUIs (Guide User Interfaces) Matlab, tạo giao diện người dùng-gần gũi với ứng dụng windows, dễ vận hành, điều khiển, thao tác Giao diện sử dụng tiếng Việt Sản phẩm hoàn thiện CHƯƠNG II PHẦN CỨNG Động bước Để điều khiển chuyển động camera, ta sử dụng động bước loại nhỏ Trung Quốc sản xuất Một số đặc điểm kỹ thuật:  Loại động cơ: động đơn cực dây  Điện áp cuộn dây: 24V DC  Dịng điện cuộn: 0.5A  Góc bước: 1.8o/bước Với góc bước nhỏ ta điều khiển camera bám đối tượng xác Webcam Để thu hình ảnh vùng giám sát, ta sử dụng webcam kí hiệu Tako01 hãng Tako Một số đặc điểm kỹ thuật  Độ phân giải ảnh : 300000 pixels  Có đèn hồng ngoại chụp ảnh vào ban đêm  Kết nối máy tính qua cổng USB  Tốc độ chụp ảnh hạn chế, nhiên đáp ứng tốt mục tiêu đặt đề tài Mạch điều khiển động 1B 2A 6 6 6 P1 1A LED 1B SPEAKER 2A 2B 2B LED G _PC C O N N EC TO R D B9 SPEAKER G _PC J2 12V 5V 2A_M C O M C C C C C C C L S 12V C O N U LN 2003A 5V 2B_M 5V LED _M 12V 5V LS1 SPEAKER _M D LED SPEAKER L V IN G N D 12V C C ~ 1B_M VO U T 5V C C C O N 5V 1B 2B 3B 4B 5B 6B 7B J1 68 U + - 1A_M 1 1 1 D ~ 1A _M 1B _M 2A _M 2B _M LED _M SPEAKER _M S U 5V G N D 1A L M /T O D IO D E B R ID G E _  Khối kết nối với cổng LPT máy tính P 1 1A LE D 1B S P E A K E R 2A 2B G _P C C O N N E C TO R D B  Khối cách ly quang: cách ly mạch lực động mạch điều khiển từ cổng LPT, đảm bảo an toàn cho cổng máy in A B A B L E D S P E A K E R G _ P C 6 6 6 5 V A _ M V B _ M V A _ M V B _ M V L E D _ M V S P E A K E R _ M  Khối tạo nguồn 5V cấp cho Cách ly quang J2 D ~ U + - C ON 12V V IN GN D 5V C C C C VOU T L M /T O D IO D E B R ID G E _ ~  Khối IC đệm: sử dụng IC ULN2003A U 12V B B B B B B B 1 1 1 1C 2C 3C 4C 5C 6C 7C C O M L S 12V C O N G N D 1A_M 1B_M 2A_M 2B_M LED _M SPEAKER _M J1 68 U LN 2003A  Khối báo động: còi báo động đèn báo động 12V LS D LE D S L S P E A K E R CHƯƠNG III PHẦN MỀM Thuật toán xử lý ảnh Để phát bám đối tượng chuyển động, hình ảnh thu từ camera đưa vào máy tính để xử lý Thuật tốn xử lý ảnh đơn giản, bao gồm bước:  Chụp ảnh liên tiếp: ảnh1 ảnh2 Mỗi ảnh thu từ webcam ảnh số hóa RGB, coi ma trận chiều lớp Bức ảnh chia thành ô nhỏ gọi pixel: với kích thước 352x288 Mỗi pixel pha trộn ba màu đỏ(Red), xanh (Green), xanh da trời (Blue) Mỗi màu pixel đặc trưng giá trị từ 0255 Để tiện xử lý, ta chuyển ảnh sang ảnh xám, tức gồm màu đen trắng  Trừ ảnh1 ảnh2 cho lấy giá trị tuyệt đối hiệu thu Việc trừ ảnh thực chất trừ giá trị số hóa màu đen, trắng ảnh cho ứng với điểm ảnh  Nếu khơng có đối tượng chuyển động phạm vi chụp ảnh, hiệu trừ xấp xỉ giá trị ứng với điểm ảnh Ngược lại, có đối tượng chuyển động hiệu có giá trị khác điểm ảnh ứng với khu vực chuyển động đối tượng  Xử lý ảnh cách quét theo chiều ngang ảnh hiệu thu đến phát biên trái biên phải Lấy trung bình cộng tọa độ biên trái biên phải ta xác định tọa độ trung bình đối tượng Giả sử tọa độ trung bình < 176 (ảnh 352x288) đối tượng bên trái ảnh, ta điều khiển camera quay bên trái Ngược lại, giả sử tọa độ trung bình > 176 (ảnh 352x288) đối tượng bên phải ảnh, ta điều khiển camera quay bên phải Điều khiển động bước Để điều khiển động bước, ta cần phát xung qua cổng LPT máy tính Hỗ trợ việc này, matlab cần sử dụng thư viện liên kết động io32.dll inpout32.dll Đầu tiên, khai báo sử dụng thư viện sau: obj_io=io32; status=io32(obj_io); address=hex2dec('378');%địa cổng LPT Để xuất giá trị 60 qua cổng LPT: io32(obj_io,address,60) Giả sử để xuất xung điều khiển động quay theo chiều thuận, ta phát chùm xung tương ứng (cách điều khiển pha bước): 0011 1100 0011 0110 0011 0011 0011 1001 Trong đó: 0011 để điều khiển cịi loa báo động (bit 1) Hàm quay trái động cơ: function quay_trai(obj_io,address,x) %obj_io=io32; %status=io32(obj_io); %if status =0 thi cong da san sang %address=hex2dec('378'); for i=1:x io32(obj_io,address,60) pause(0.01); io32(obj_io,address,57); pause(0.01); io32(obj_io,address,51); pause(0.01); io32(obj_io,address,54); pause(0.01); end io32(obj_io,address,0); Hàm quay phải động cơ: function quay_phai(obj_io,address,x) %obj_io=io32; %status=io32(obj_io); %if status =0 thi cong da san sang %address=hex2dec('378'); for i=1:x io32(obj_io,address,54) pause(0.01); io32(obj_io,address,51); pause(0.01); io32(obj_io,address,57); pause(0.01); io32(obj_io,address,60); pause(0.01); end io32(obj_io,address,0); Code chương trình function varargout = myCameraGUI(varargin) gui_Singleton = 1; gui_State = struct('gui_Name', mfilename, 'gui_Singleton', gui_Singleton, 'gui_OpeningFcn', @myCameraGUI_OpeningFcn, 'gui_OutputFcn', @myCameraGUI_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 % End initialization code - DO NOT EDIT % - Executes just before myCameraGUI is made visible function myCameraGUI_OpeningFcn(hObject, eventdata, handles, varargin) % This function has no output args, see OutputFcn % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % varargin command line arguments to myCameraGUI (see VARARGIN) %khai bao cong vao LPT global obj_io address status temp tong_so_anh tong_so_anh=str2double(get(handles.tong_so_anh,'String')); temp=0; obj_io=io32; status=io32(obj_io); address=hex2dec('378'); % Choose default command line output for myCameraGUI handles.output = hObject; imaqreset; %reset webcam %khai bao cac doi tuong anh handles.video=videoinput('winvideo',1,'RGB24_352x288'); set(handles.video,'TriggerRepeat',Inf); 10 set(handles.video, 'FramesPerTrigger', 1) triggerconfig(handles.video, 'Manual'); start(handles.video); % Update handles structure guidata(hObject, handles); % UIWAIT makes myCameraGUI wait for user response (see UIRESUME) % uiwait(handles.figure1); %=========================================================== uiwait(handles.MyCameraGUI); %=========================================================== % - Outputs from this function are returned to the command line function varargout = myCameraGUI_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT); % hObject handle to figure % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %================== handles.output = hObject; %================== % Get default command line output from handles structure varargout{1} = handles.output; % - Executes on button press in startStopCamera %function startStopCamera_Callback(hObject, eventdata, handles) % hObject handle to startStopCamera (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) %============================================================ ============== function startStopCamera_Callback(hObject, eventdata, handles) % hObject handle to startStopCamera (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global obj_io address bien_trai bien_phai nguong n so_anh tong_so_anh % Start/Stop Camera tong_so_anh=str2double(get(handles.tong_so_anh,'String')); if strcmp(get(hObject,'String'),'Take Photo') 11 so_anh=so_anh+1; if so_anh==tong_so_anh+1 so_anh=1; end imwrite(getsnapshot(handles.video),strcat(num2str(so_anh),'.jpg'),'jpg'); end if strcmp(get(hObject,'String'),'Start Camera')&& (get(handles.automation,'Value')==1) % Camera is off Change button string and start camera set(hObject,'String','Stop Camera'); n=0; so_anh=0; bien_trai=176; bien_phai=176; nguong=50; while strcmp(get(hObject,'String'),'Stop Camera')&& strcmp(get(hObject,'Enable'),'on') time=clock; Image1=getsnapshot(handles.video); %pause(0.05); imshow(Image1); Image2=getsnapshot(handles.video); imshow(Image2); if rem(round(time(6)),3)==0 so_anh=so_anh+1; if so_anh==(tong_so_anh+1) so_anh=1; end imwrite(Image2,strcat(num2str(so_anh),'.jpg'),'jpg'); end Image=imsubtract(Image1,Image2); %handles=guidata(gcf); de thi khong chay duoc Image_grey= rgb2gray(Image); for i=1:1:352 if max(Image_grey(:,i))>=nguong bien_trai=i; break end end for i=352:-1:1 if max(Image_grey(:,i))>=nguong bien_phai=i; 12 break end end trung_tam=int16(((bien_trai)+(bien_phai))/2); n=int8(abs((176-trung_tam))/70); if (trung_tam176) quay_phai(obj_io,address,n); end end %===================================================== %start(handles.video) elseif strcmp(get(hObject,'String'),'Stop Camera') % Camera is on Stop camera and change button string set(handles.startStopCamera,'String','Start Camera'); %stop(handles.video); %close all; end % - Executes on button press in automation function automation_Callback(hObject, eventdata, handles) % hObject handle to automation (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of automation set(handles.automation,'Value',1); set(handles.startStopCamera,'Enable','on'); set(handles.startStopCamera,'String','Stop Camera'); set(handles.direction,'Enable','off'); % - Executes on button press in manual function manual_Callback(hObject, eventdata, handles) % hObject handle to manual (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: get(hObject,'Value') returns toggle state of manual set(handles.manual,'Value',1); %set(handles.startStopCamera,'Enable','off'); set(handles.startStopCamera,'String','Take Photo'); 13 %set(handles.startStopCamera,'Enable','off'); set(handles.direction,'Enable','on'); set(handles.direction,'Value',0); uicontrol(handles.direction); stop(handles.video); start(handles.video); while (get(handles.automation,'Value')~=1) imshow(getsnapshot(handles.video)); end % - Executes on slider movement function direction_Callback(hObject, eventdata, handles) % hObject handle to direction (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'Value') returns position of slider % get(hObject,'Min') and get(hObject,'Max') to determine range of slider global obj_io address temp quay=get(handles.direction,'Value')*100-temp; temp=get(handles.direction,'Value')*100; if (quay0) quay_phai(obj_io,address,int16(quay)); end % - Executes on mouse motion over figure - except title and menu function MyCameraGUI_WindowButtonMotionFcn(hObject, eventdata, handles) % hObject handle to MyCameraGUI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % - Executes during object creation, after setting all properties function cameraAxes_CreateFcn(hObject, eventdata, handles) % hObject handle to cameraAxes (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: place code in OpeningFcn to populate cameraAxes 14 % - Executes during object creation, after setting all properties function direction_CreateFcn(hObject, eventdata, handles) % hObject handle to direction (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: slider controls usually have a light gray background if isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor',[.9 9]); end % - Executes on mouse press over figure background, over a disabled or % - inactive control, or over an axes background function MyCameraGUI_WindowButtonDownFcn(hObject, eventdata, handles) % hObject handle to MyCameraGUI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % - Executes on scroll wheel click while the figure is in focus function MyCameraGUI_WindowScrollWheelFcn(hObject, eventdata, handles) % hObject handle to MyCameraGUI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % - Executes when user attempts to close MyCameraGUI function MyCameraGUI_CloseRequestFcn(hObject, eventdata, handles) % hObject handle to MyCameraGUI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hint: delete(hObject) closes the figure % Get the current position of the GUI from the handles structure % to pass to the modal dialog pos_size = get(handles.MyCameraGUI,'Position'); % Call modaldlg with the argument 'Position' user_response = modaldlg('Title','Confirm Close'); switch user_response case ('No') % take no action case ('Yes') % Prepare to close GUI application window 15 % % % delete(hObject); close all; end % - Executes during object deletion, before destroying properties function MyCameraGUI_DeleteFcn(hObject, eventdata, handles) % hObject handle to MyCameraGUI (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % - Executes on button press in Exit function Exit_Callback(hObject, eventdata, handles) % hObject handle to Exit (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) close all; % - Executes on button press in about function about_Callback(hObject, eventdata, handles) % hObject handle to about (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) about; % - Executes on button press in Help function Help_Callback(hObject, eventdata, handles) % hObject handle to Help (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) help; function tong_so_anh_Callback(hObject, eventdata, handles) % hObject handle to tong_so_anh (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) % Hints: get(hObject,'String') returns contents of tong_so_anh as text % str2double(get(hObject,'String')) returns contents of tong_so_anh as a double 16 % - Executes during object creation, after setting all properties function tong_so_anh_CreateFcn(hObject, eventdata, handles) % hObject handle to tong_so_anh (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles empty - handles not created until after all CreateFcns called % Hint: edit controls usually have a white background on Windows % See ISPC and COMPUTER if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor')) set(hObject,'BackgroundColor','white'); end % - Executes on button press in so_anh function so_anh_Callback(hObject, eventdata, handles) % hObject handle to so_anh (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) global tong_so_anh tong_so_anh=str2double(get(handles.tong_so_anh,'String')); CHƯƠNG IV TỔNG KẾT Đánh giá Sản phẩm (phần cứng+phần mềm) đảm bảo mục tiêu mà đề tài hướng tới Quá trình thử nghiệm nhà chạy báo cáo tốt, bám 17 sát đối tượng chuyển động, đưa cảnh báo (còi đèn) kịp thời, hiệu Với giao diện thân thiện, dễ sử dụng nhiều tính năng, sản phẩm phần đáp ứng chức camera giám sát an ninh hiệu quả, ổn định, tin cậy với chi phí vừa phải Tuy vậy, đề tài có vài hạn chế định • Tốc độ chụp ảnh gửi webcam chậm hạn chế phần cứng • Camera quay mặt phẳng chiều • Chỉ đưa cảnh báo không bám nhiều đối tượng chuyển động lúc Hướng phát triển Từ đề tài phát triển lên, xây dựng nhiều ứng dụng giám sát an ninh có hiệu thực tế Chúng em đề xuất số hướng phát triển sau: • Phát triển thuật tốn xử lý ảnh, cho nhận dạng hình dạng đối tượng, giúp cho việc bám đối tượng thêm hiệu • Tăng thêm bậc tự cho camera giúp cho camera giám sát linh hoạt, theo nhiều chiều không gian 18 ... mềm có hiệu giám sát cao, dễ sử dụng, nhiều tính Hoạt động Camera có tác dụng giám sát chuyển động phạm vi giới hạn, ví dụ phịng kín  Khi có đối tượng xâm nhập vào phạm vi giám sát Camera có tín... %start(handles.video) elseif strcmp(get(hObject,'String'),'Stop Camera' ) % Camera is on Stop camera and change button string set(handles.startStopCamera,'String','Start Camera' ); %stop(handles.video); %close all;... strcmp(get(hObject,'String'),'Start Camera' )&& (get(handles.automation,'Value')==1) % Camera is off Change button string and start camera set(hObject,'String','Stop Camera' ); n=0; so_anh=0; bien_trai=176;

Ngày đăng: 08/10/2021, 18:02

Mục lục

  • CHƯƠNG I. GIỚI THIỆU ĐỀ TÀI

    • 1. Mục tiêu đề tài

    • 4. Sản phẩm hoàn thiện

    • 3. Mạch điều khiển động cơ

    • CHƯƠNG III. PHẦN MỀM

      • 1. Thuật toán xử lý ảnh

      • 2. Điều khiển động cơ bước

      • 3. Code chương trình chính

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

  • Đang cập nhật ...

Tài liệu liên quan