-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarDetectionProject.m
More file actions
50 lines (48 loc) · 2.06 KB
/
CarDetectionProject.m
File metadata and controls
50 lines (48 loc) · 2.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
% Hakkı Egemen Gülpınar / Seher Bengisu Akbulut
% Mersin University Department of Computer Engineering
Video = VideoReader('videoplayback_short.mp4');
Object_Detector = vision.ForegroundDetector(...
'NumTrainingFrames', 7, ...
'InitialVariance', 30*30)
for i = 1:25
frame = readFrame(Video);
Object = step(Object_Detector, frame);
end
%Show our Model
figure; imshow(frame); title('Video Frame');
figure; imshow(Object); title('The Object');
%Morphological Operation to Remove Noise
Structure = strel('square', 3);
Noise_Free_Object = imopen(Object, Structure);
figure; imshow(Noise_Free_Object); title('Object After Removing Noise');
%Locate the Object
Bounding_Box = vision.BlobAnalysis('CentroidOutputPort', false, 'AreaOutputPort', false, ...
'BoundingBoxOutputPort', true, ...
'MinimumBlobAreaSource', 'Property', 'MinimumBlobArea', 1400);
%Inserting the Box
The_Box = step(Bounding_Box, Noise_Free_Object);
% Drawing the Rectangle
Detected_Vehicle = insertShape(frame, 'Rectangle', The_Box, 'Color', 'yellow');
% Counting Vehicles
Number_of_Vehicle = size(The_Box, 1);
%Inserting Text Operations
Detected_Vehicle = insertText(Detected_Vehicle, [10 10], Number_of_Vehicle, 'BoxOpacity', 1,'FontSize', 14);
figure; imshow(Detected_Vehicle); title('Detected Vehicles');
videoPlayer = vision.VideoPlayer('Name', 'Detected Vehicles');
videoPlayer.Position(3:4) = [650,400];
%Video Sequence
while hasFrame(Video)
frame = readFrame(Video);
Object = step(Object_Detector, frame);
Noise_Free_Object = imopen(Object, Structure);
The_Box = step(Bounding_Box, Noise_Free_Object);
% Detected_Vehicle = insertShape(frame, 'Rectangle', The_Box, 'Color', 'yellow');
shapeInserter = vision.ShapeInserter('BorderColor','custom');
Detected_Vehicle = shapeInserter(frame,The_Box);
Number_of_Vehicle = size(The_Box, 1);
Detected_Vehicle = insertText(Detected_Vehicle, [10 10], Number_of_Vehicle, 'BoxOpacity', 1, 'FontSize', 14);
step(videoPlayer, Detected_Vehicle);
pause(0.06)
end
% Hakkı Egemen Gülpınar / Seher Bengisu Akbulut
% Mersin University Department of Computer Engineering