(Luận văn thạc sĩ hcmute) phân loại và đếm lưu lượng xe lưu thông

124 7 0
(Luận văn thạc sĩ hcmute) phân loại và đếm lưu lượng xe lưu thông

Đ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

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SĨ THIỀU ĐOÀN QUANG HUY PHÂN LOẠI VÀ ĐẾM LƯU LƯỢNG XE LƯU THÔNG NGÀNH: KỸ THUẬT ĐIỆN TỬ - 8520203 S K C0 Tp Hồ Chí Minh, tháng - 2020 Luan van BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SĨ THIỀU ĐOÀN QUANG HUY PHÂN LOẠI VÀ ĐẾM LƯU LƯỢNG XE LƯU THÔNG NGÀNH: KỸ THUẬT ĐIỆN TỬ - 8520203 Tp Hồ Chí Minh, tháng 5/2020 Luan van BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH LUẬN VĂN THẠC SĨ THIỀU ĐOÀN QUANG HUY PHÂN LOẠI VÀ ĐẾM LƯU LƯỢNG XE LƯU THÔNG NGÀNH: KỸ THUẬT ĐIỆN TỬ - 8520203 Hướng dẫn khoa học: PGS.TS NGUYỄN THANH HẢI Tp Hồ Chí Minh, tháng 5/2020 Luan van LÝ LỊCH KHOA HỌC I LÝ LỊCH SƠ LƯỢC Họ & tên: Thiều Đồn Quang Huy Giới tính: Nam Ngày, tháng, năm sinh: 25/12/1994 Nơi sinh: Phú Yên Quê quán: Phú Yên Dân tộc: Kinh Địa chỉ: 212/6, Lã Xuân Oai, Phường Tăng Nhơn Phú B, Quận 9, TPHCM Điện thoại quan: Điện thoại: 0376708337 E-mail: thieudoanquanghuy@gmail.com Fax: II QUÁ TRÌNH ĐÀO TẠO Đại học Hệ đào tạo: Đại học quy Thời gian đào tạo từ 07/2016 đến 03/2018 Nơi học (trường, thành phố): Trường Đại Học Sư Phạm Kỹ Thuật TPHCM Ngành học: Kỹ thuật Điện Tử Truyền Thông III Q TRÌNH CƠNG TÁC CHUN MƠN KỂ TỪ KHI TỐT NGHIỆP ĐẠI HỌC: Thời gian Từ 04/2019 đến Nơi công tác Công việc đảm nhiệm Công Ty TNHH Greystones Data Việt Nam Trang i Luan van Kỹ Sư Điện Tử LỜI CAM ĐOAN Tôi cam đoan cơng trình nghiên cứu tơi Các số liệu, kết nêu luận văn trung thực chưa cơng bố cơng trình khác Tp Hồ Chí Minh, ngày … tháng 05 năm 2020 (Ký tên ghi rõ họ tên) Thiều Đoàn Quang Huy Trang ii Luan van LỜI CẢM ƠN Luận văn thực Trường Đại học Sư phạm kỹ thuật TP Hồ Chí Minh Để hồn thành luận văn nhận nhiều động viên, giúp đỡ nhiều cá nhân tập thể Trước hết, tơi xin bày tỏ lịng biết ơn sâu sắc đến Thầy PGS.TS Nguyễn Thanh Hải hướng dẫn tơi thực nghiên cứu Xin bày tỏ lòng biết ơn chân thành tới thầy cô giáo, người đem lại cho kiến thức bổ trợ, vơ có ích năm học vừa qua Cũng xin gửi lời cám ơn chân thành tới Ban Giám hiệu, Phòng Đào tạo sau đại học, Đại học Sư phạm kỹ thuật TP Hồ Chí Minh tạo điều kiện cho tơi q trình học tập Cuối tơi xin gửi lời cám ơn đến gia đình, bạn bè, người ln bên tơi, động viên khuyến khích tơi trình thực luận văn Trang iii Luan van TÓM TẮT Ở Việt Nam, số lượng phương tiện giao thông thành phố lớn tăng lên ngày, tắc nghẽn giao thông xảy thường xun Vì việc kiểm sốt mật độ xe lưu thông tuyến đường quan trọng, để giải vấn đề Luận văn xây dựng hệ thống phân loại đếm lưu lượng xe lưu thông đường dùng xử lý ảnh với liệu ngõ vào video thực tế thu từ camera máy ảnh đặt đường Phương pháp thực trừ nền, xử lý hình thái, phát theo dõi xe, tính số xe phân loại xe lớn xe nhỏ phát Đầu tiên, sử dụng mơ hình Gaussian hỗn hợp để trừ nền, chuyển ảnh màu sang ảnh nhị phân xe đốm trắng đường màu đen Sử dụng phép xử lý hình thái để lấp đầy khoảng trống xe, loại bỏ thành phần không mong muốn, kết thu ảnh nhị phân hồn chỉnh Cuối cùng, Sử dụng Thuật tốn dán nhãn để dán nhãn đếm xe, áp dụng thuật toán phân loại xe lớn xe nhỏ dựa vào kích thước hộp đánh dấu bao xung quanh xe Kết xử lý ảnh video, tách xe khỏi đường, phát theo dõi xe, đếm phân loại xe lớn, xe nhỏ từ camera giao thông Trang iv Luan van ABSTRACT In Vietnam, the number of vehicles in big cities is increasing day by day, traffic jams regularly occur So controlling the density of vehicles on the roads is very important, to solve this problem In this paper has developed a system classification and counting circulating traffic flow on the road by using image processing using with input data is obtained from the video camera or cameras placed on the road Implementation method is background subtraction, morphological operation, vehicle detection and vehicle tracking, count the number of vehicle and classification the number of large vehicle and small vehicle detected The first thing, using the Gaussian mixture model for background subtraction, color pictures into a binary image in which vehicles are white spots and roads are black Using morphological operation to fill the white vehicle into unified block and remove unwanted components The result is a complete binary image Finally, using labeling algorithm for labeling and counting the number of vehicles Using the large and Small Vehicle Classification Algorithm based on the size of the box marked around the vehicle Video image processing results shows, isolated vehicle out of the road Vehicle detection and tracking, counting and classification large and small vehicle from traffic cameras Trang v Luan van MỤC LỤC Lý lịch cá nhân i Lời cam đoan ii Lời cảm ơn iii Tóm tắt iv Abstract v Mục lục vi Danh sách bảng xi Danh sách hình .xii Các chữ viết tắt xv CHƯƠNG TỔNG QUAN 1.1 Tổng quan lĩnh vực nghiên cứu, kết nghiên cứu nước công bố 1.1.1 Tổng quan lĩnh vực nghiên cứu 1.1.2 Một số kết nghiên cứu công bố 1.2 Mục tiêu luận văn 1.3 Nhiệm vụ giới hạn luận văn 1.3.1 Nhiệm vụ: 1.3.2 Giới hạn: 1.4 Phương pháp nghiên cứu 1.5 Tóm tắt chương Trang vi Luan van CHƯƠNG CƠ SỞ LÝ THUYẾT 2.1 Xử lý ảnh 2.2 Các giai đoạn xử lý ảnh 10 2.2.1 Thu nhận ảnh 10 2.2.2 Tiền xử lý 10 2.2.3 Phân đoạn ảnh 10 2.2.4 Biểu diễn ảnh 11 2.2.5 Nhận dạng nội suy ảnh 11 2.2.6 Cơ sở trí thức 12 2.3 xử lý video hiển thị đồ họa 12 2.4 Một số ứng dụng phổ biến xử lý ảnh giao thông 13 2.4.1 Nhận dạng biển số xe 13 2.4.2 Phát hiện, cảnh báo biển báo đèn tín hiệu 14 2.4.3 Phát hiện, cảnh báo vật cản dự báo tắt đèn 14 2.5 Thuật toán ứng dụng để phát theo dõi đối tượng 15 2.5.1 Phương pháp trừ 15 2.5.2 Mơ hình hỗn hợp Gaussian xử lý ảnh 17 2.5.2.1 Khái niệm mơ hình trừ hỗn hợp 17 2.5.2.2 Mơ hình trừ hỗn hợp ảnh số 17 2.5.3 Phương pháp xử lý hình thái, lọc trung bình lọc trung vị để lọc nhiễu ảnh 18 Trang vii Luan van Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” [9] Cristani M., Farenzena M., Bloisi D., Murino V (2010), “Background Subtraction for Automated Multisensor Surveillance: A Comprehensive Review”, EURASIP Journal on Advances in Signal Processing, 24 pages, Volume 2010 [10] Can Nguyen Van, Huy Huynh Van, Tao Ngo Quoc (2014), “Car counting method using Gaussian Mixture Model and Optical Flow”, The 3rd Solid State Systems Symposium-VLSIs and Semiconductor Related Technologies & The 17th International Conference on Analog VLSI Circuits-Analog Signal and Information Processing Applications Ho Chi Minh City, 10/2014 Proceeding, pages 192-198 [11] Chris Stauffer, W.E.L Grimson, “Adaptive background mixture models for real-time tracking”, The Artificial Intelligence Laboratory Massachusetts Institute of Technology Cambridge, MA 02139 [12] G SalviAn Automated Vehicle Counting System Based on Blob Analysis for Traffic Surveillance Department of Economics Studies, University of Naples "Parthenope", Naples, Italy, 2012 [13] Pejman Niksaz Automatic Traffic Estimation Using Image Processing International Journal of Signal Processing, Image Processing and Pattern Recognition, Vol 5, No 4, December, 2012 [14] Mrs Muth Sebastian, Anisha Ann Sam, Aleena Jose Vehicle Collision Avoidance System In Curved Roads International Journal of Engineering Research in Electronic and Communication Engineering (IJERECE), Vol 2, Issue 8, August 2015 [15] Li, Y., Yin, L., Jia, Y., Wang, M., E.F (2008), “Vehicle speed measurement based on video images”, in Proc 3rd International Conf Innovative Computing Information and Control HVTH: Thiều Đoàn Quang Huy Trang 91 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” [16] Jyotsna Tripathi, Kavita Chaudhary, Akanksha Joshi and Prof J B Jawale Student, Electronics and Telecommunication dept., Army Institute of Technology, Pune, India bProfessor, Electronics and Telecommunication dept., AIT, Pune, India, “Automatic Vehicle Counting and Classification” International Journal of Innovative and Emerging Research in Engineering Volume 2, Issue 4, 2015 [17] Samet, H.; Tamminen, M (1988) "Efficient Component Labeling of Images of Arbitrary Dimension Represented by Linear Bintrees" IEEE Transactions on Pattern Analysis and Machine Intelligence Volume: 10 , Issue: , Jul 1988 [18] Huang, J & Yang, X Fast reduction of speckle noise in real ultrasound images Signal Processing 93, 684–694 (2013) [19] M Forouzanfar and H Abrishami-Moghaddam, Ultrasound Speckle Reduction in the Complex Wavelet Domain, in Principles of Waveform Diversity and Design, M Wicks, E Mokole, S Blunt, R Schneible, and V Amuso (eds.), SciTech Publishing, 2010, Section B - Part V: Remote Sensing, pp 558-77 [20] Mahammad, Aini Hussain, “An Automatic Traffic Sign Detection and Recognition System Based on Colour Segmentation, Shape Matching, and SVM”, IEEE Transactions on Intelligent Transportation Systems,17 nov 2015 [21] TS Đỗ Năng Tồn, TS Phạm Việt Bình (2007), Giáo trình môn học xử lý ảnh, Khoa Công nghệ thông tin - Đại học Thái Nguyên [22] Chris Solomon, Toby Breckon Fundamentals of Digital Image Processing Wiley-Blackwell, 2010, tr 213 [23] Surendra Gupte, Osama Masoud, Robert F K Martin, and Nikolaos P Papanikolopoulos, “Detection and Classification of Vehicles” IEEE Transactions on intelligent transportation systems, VOL 3, NO 1, March 2002 HVTH: Thiều Đoàn Quang Huy Trang 92 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” [24] P Srinivas, Y L Malathilatha, Dr M.V.N.K Prasad Image Processing Edge DetectionTechnique used for Traffic Control Problem International Journal of Computer Science and Information Technologies, Vol (1) , 2013, pp 17 – 20 [25] The Mathworks, Inc (2015), Image Processing Toolbox User Guide [26] Richard Szeliski (2010), “Computer Vision: Algorithms and Applications” [27] M Piccardi, "Background subtraction techniques: a review", IEEE International Conference on Systems, Man and Cybernetics, 2004 PHỤ LỤC Main code %============Clear Windows================ clc; % Clear the command window clear all; % Clear workspace close all; % Close all figures (except those of imtool.) workspace; % Make sure the workspace panel is showing %==============Input Video================ video_name = 'Road_lvv2.mp4'; % video name %==============Video Information=============== %==============Detect Foreground================ video_info = VideoReader(video_name); % Show information of video %===============Read Video File=============== videoReader = vision VideoFileReader (video_name); %==============Set Parameters================= NumTrainingFrames = 100; %line_pos = [0 185 185]; % [x1 y1 x2 y2] HVTH: Thiều Đoàn Quang Huy Trang 93 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” %object_4lx1 = 70; %object_4lx2 = 151; pixel_up = 280; % round((y1-5)/5) pixel_down = 290; Td_tr1 = 500; %182 Td_tr2 = 600; %231 Td_tr3 = 123; Td_tr4 = 129; % round((y2+5)/5) dif_x = 140; %180 dif_y = 120; %140 lane_pix1 = 135; lane_pix2 = 260; foregroundDetector = vision ForegroundDetector ('NumGaussians', 3, 'NumTrainingFrames', NumTrainingFrames); % detect foreground %///////////anh chua loc %for img = 264:267 %frame = step(videoReader); % read the next video frame %foreground = step (foregroundDetector, frame); % filename=strcat ('frame', num2str(img),'.jpg'); % b = read (video_info, img); % imwrite (b, filename); %end %figure; imshow(frame); title ('Video Frame'); %figure; imshow(foreground); title('Foreground'); HVTH: Thiều Đoàn Quang Huy Trang 94 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” %==============Create blob of object============== %==============Create blob of object============== blobAnalysis = vision BlobAnalysis ('BoundingBoxOutputPort', true, 'AreaOutputPort', false, 'CentroidOutputPort', false, 'MinimumBlobArea', 350); % return blob area % minimum blob in pixels is 350 %=============Insert box==================== %for img = 0:500 % frame = step(videoReader); % read the next video frame % foreground = step (foregroundDetector, frame); % filename=strcat ('frame', num2str(img),'.jpg'); % b = read (video_info, img); %imwrite (b, filename); %end %figure; imshow(frame); title ('Video Frame'); shapeInserter = vision ShapeInserter ('BorderColor','white'); % allow insert shapes in image %=============Set up videoPlayer================ videoPlayer = vision VideoPlayer ('Name', 'Detected Cars'); videoPlayer.Position(3:4) = [video_info Width, video_info Height+50]; videoPlayer2 = vision VideoPlaye ('Name', 'Foreground'); videoPlayer2.Position(3:4) = [video_info Width, video_info Height + 50]; %==============Morphological Filter================ se = strel ('square', 3); % morphological filter for noise removal %se = strel ('diamond', 3) HVTH: Thiều Đoàn Quang Huy Trang 95 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” %filteredForeground = imopen (foreground, se); %if (i == 531) %figure; imshow(filteredForeground); title('filteredForeground'); %end %=============Counting Parameters=============== count = 0; count_car = 0; count_truck = count_frame = -1; lane_1 = 0; lane_2 = 0; lane_3 = 0; isVehicle = 0; time_speed=0; speed=0; %==============Process total video============== while ~isDone(videoReader) frame = step(videoReader); % read the next video frame count_frame = count_frame + 1; % Detect the foreground in the current video frame foreground = step (foregroundDetector, frame); %filter average to remove noise %m=fspecial ('average', [3 3]); %filteredForeground = imfilter (foreground, m); %finish %filteredForeground = foreground; HVTH: Thiều Đoàn Quang Huy Trang 96 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” %hinhAnh = rgb2gray(frame); %result = imnoise (frame,'salt & pepper',0.4); % Use morphological opening to remove noise in the foreground %filteredForeground = imdilate (foreground, se); filteredForeground = imopen (foreground, se); %filteredForeground = imerode (foreground, se); %filteredForeground1 = imdilate (filteredForeground, se); %filteredForeground = imclose (foregrou nd, se); %filteredForeground = imtophat (foreground, strel('disk',50)); % Detect the connected components with th e specified minimum area, and filteredForeground = bwareaopen(filteredForeground,100); filteredForeground = imfill(filteredForeground,'holes'); %//////// % compute their bounding boxes bbox = step (blobAnalysis, filteredForeground) % Draw bounding boxes around the detected cars result = insertShape (frame, 'Rectangle', bbox, 'Color', 'green','Linewidth',4); %toa_do4 = size(bbox,1); %distance = size (toa_do4, 1); %result = insertText (result, [100 120], distance, 'BoxOpacity', 1, %'FontSize', 14); %figure; imshow(frame); title ('Video Frame'); % Display the number of cars found in the video frame numCars = size (bbox, 1); labelname = cell(numCars,1); result = insertText (result, [75 100], numCars, 'BoxOpacity', 1, HVTH: Thiều Đoàn Quang Huy Trang 97 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” 'FontSize', 14); pos_C = [6 100]; result = insertText (result, pos_C, 'Detection', 'BoxOpacity', 1, 'TextColor','black','BoxColor', 'yellow', 'FontSize', 14); % Display the Line where vehicles are counted % result = insertShape (result, 'Line', line_pos, 'Color', 'yellow'); % If the bbox is detected pos_lane_1 = [40 280 110 6]; pos_lane_2 = [160 280 140 6]; pos_lane_3 = [310 280 180 6]; %pos_pox_detect1 = [109 171 75 79]; %34 %yellow %pos_pox_detect2 = [180 133 53 71]; %127 % red %pos_pox_detect3 = [153 49 43 54]; %pos_pox_detect1_ck1 = [92 196 132 101]; %40 green %pos_pox_detect2_ck2 = [92 221 123 97]; %31blue %pos_pox_detect3_ck3 = [77 255 129 126]; %52 %posx = 52; result = insertShape (result, 'FilledRectangle', pos_lane_1, 'Color', 'red'); result = insertShape (result, 'FilledRectangle', pos_lane_2, 'Color', 'red'); result = insertShape (result, 'FilledRectangle', pos_lane_3, 'Color', 'red'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect1, 'Color', 'yellow'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect2, 'Color', 'red'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect3, 'Color', 'blue'); %pos_pox_detect112 = [95 184 129 105]; %127 % red %pos_pox_detect113 = [107 177 76 80]; %127 % yellow HVTH: Thiều Đoàn Quang Huy Trang 98 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” %pos_pox_detect114 = [173 142 59 73]; %127 % green %result = insertShape (result, 'FilledRectangle', pos_pox_detect112, 'Color', 'red'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect113, 'Color', 'yellow'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect114, 'Color', 'green'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect2_ck2, 'Color', 'blue'); %result = insertShape (result, 'Rectangle', pos_pox_detect3_ck3, 'Color', 'yellow'); %result = insertShape (result, 'FilledRectangle', pos_pox_detect_ck4, 'Color', 'red'); pos_A = [40 330]; result = insertText (result, pos_A, 'A', 'BoxOpacity', 1, 'TextColor','black','BoxColor', 'yellow', 'FontSize', 20); pos_B = [150 330]; result = insertText (result, pos_B, 'B', 'BoxOpacity', 1, 'TextColor','black','BoxColor', 'green', 'FontSize', 20); pos_C = [330 330]; result = insertText (result, pos_C, 'C', 'BoxOpacity', 1, 'TextColor','black','BoxColor', 'red', 'FontSize', 20); if (size(bbox) ~= 0) % Get size of the bbox sizebbox = size(bbox); % Run one by one bbox for k = 1: sizebbox (1) bot_bbox = bbox(k,2) + bbox(k,4); % Get y of bottom bbox toa_do = bbox(k,2) + bbox(k,4); Width_bbox = bbox(k,1) + bbox(k,3); % Divide by HVTH: Thiều Đoàn Quang Huy Trang 99 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” x_right = bbox(k,1) + bbox(k,3)/2; %compare lane % % Position to display word: "Object" %pos = zeros(k,2); pos = [bbox(k,1), bbox(k,2)]; pos1 = [bbox(k,1), bbox(k,3)]; % Top left of bbox result = insertText (result, pos, 'Object', 'BoxOpacity', 1, 'TextColor','black','BoxColor', 'yellow', 'FontSize',12); %imshow(pos, [bbox(k,2) bbox(k,4)]); % %end % Center position of bbox, display a filled circle % pos2 = zeros(k,3); pos2 = [bbox(k,1) + bbox(k,3)/2, bbox(k,2) + bbox(k,4)/2,4]; result = insertShape (result, 'filledcircle', pos2, 'Color', 'red'); % Counted position is interval pixel from 180 to 190, % divide by is 36 to 38 if(bbox(k,3) < dif_x) && (bbox(k,4) < dif_y) && (toa_do > 150) && (toa_do dif_x) && (bbox(k,4) > dif_y) && (toa_do > 150) && (toa_do pixel_up) && (toa_do < pixel_down) if (isVehicle==0) isVehicle = 1; HVTH: Thiều Đoàn Quang Huy Trang 100 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” s1 = toa_do; %if(Width_bbox>=Td_tr1) && (Width_bbox224) if(bbox(k,3) >= Td_tr3) && (bbox(k,3) = lane_pix1) && (x_right < lane_pix2) lane_2 = lane_2 + 2; result = insertShape (result, 'FilledRectangle', pos_lane_2, 'Color', 'blue'); elseif (x_right > lane_pix2) lane_3 = lane_3 + 2; result = insertShape (result, 'FilledRectangle', pos_lane_3, 'Color', 'blue'); end else count = count +1; % vehicle classifiacation if(bbox(k,3) < dif_x) && (bbox(k,4) < dif_y) count_car = count_car + 1; HVTH: Thiều Đoàn Quang Huy Trang 101 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” else count_truck = count_truck +1 end % caculate lane If (x_right < lane_pix1) lane_1 = lane_1 + 1; result = insertShape (result, 'FilledRectangle', pos_lane_1, 'Color', 'blue'); elseif (x_right >= lane_pix1) && (x_right < lane_pix2) lane_2 = lane_2 + 1; result = insertShape (result, 'FilledRectangle', pos_lane_2, 'Color', 'blue'); elseif(x_right > lane_pix2) lane_3 = lane_3 + 1; result = insertShape (result, 'FilledRectangle', pos_lane_3, 'Color', 'blue'); end end end else isVehicle=0; end %//// speed vehicle If (toa_do > pixel_up) if (toa_do < pixel_down+20) time_speed = time_speed + 1; % s1-s2(23frame) s2 = toa_do; else speed =10*(s2-s1)/time_speed; HVTH: Thiều Đoàn Quang Huy Trang 102 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” end if (toa_do > 350) time_speed = 0; speed = 0; end end end end % Display total of number the car pass through line pixel %position = [10 230; 10 200; 40 300; 150 300;330 300; 10 140; 10 170]; %position_2 = [60 230; 40 200; 90 300; 200 300;380 300; 95 140; 95 170]; position = [10 200; 40 300; 150 300; 330 300; 10 140; 10 170]; position_2 = [40 200; 90 300; 200 300; 380 300; 95 140; 95 170]; %box_color = {'blue', 'red', 'yellow', 'green', 'red', 'blue', 'yellow'}; box_color = {'red','yellow','green', 'red', 'red', 'yellow'}; text_str = cell (6,1); %str = {'Speed: Km/h', 'total:', 'Lane_A: ', 'Lane_B:', 'Lane_C:', 'Small Vehicle:','Large Vehicle:'}; %conf_val = [speed count lane_1 lane_2 lane_3 count_car count_truck]; str = {'total:','Lane_A: ', 'Lane_B: ', 'Lane_C:', 'Small Vehicle:', 'Large Vehicle:'}; conf_val = [count lane_1 lane_2 lane_3 count_car count_truck]; for j=1:6 text_str{j} = num2str(conf_val(j),'%0.0f'); end result = insertText (result, position, str, 'BoxOpacity', 1, 'TextColor','black','BoxColor', box_color, 'FontSize', 12); HVTH: Thiều Đoàn Quang Huy Trang 103 Luan van GVHD: PGS.TS Nguyễn Thanh Hải Luận Văn Thạc Sĩ: “Phân Loại Và Đếm Lưu Lượng Xe Lưu Thông” result = insertText (result, position_2, text_str, 'BoxOpacity', 1, 'TextColor','black','BoxColor', box_color, 'FontSize', 12); % Display the results %if (frame>=214) && (frame

Ngày đăng: 02/02/2023, 09:57

Từ khóa liên quan

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

Tài liệu liên quan