嗨,我真的是图像处理和Matlab的真正新手。
我试图使用Matlab中的“ vision.forgroundDetector”检测交通视频的车辆。但是现在我想确定车辆转弯时车辆信号灯是亮还是灭。
我尝试了一些代码,但是它永远都行不通,而且我不知道在哪里写代码,编写的代码也行不通。
有人可以帮助我识别行驶中的车辆的信号灯吗? 您可以通过此链接找到我使用的视频 “ https://www.youtube.com/watch?v=jjlBnrzSGjc”
这是我的代码:
foregroundDetector = vision.ForegroundDetector('NumGaussians', 3, ...'NumTrainingFrames', 50);
videoReader = vision.VideoFileReader('vi.mp4');
for i = 1:150
figure; imshow(frame); title('Video Frame');
figure; imshow(foreground); title('Foreground');
videoPlayer = vision.VideoPlayer('Name', 'Detected Cars');
videoPlayer.Position(3:4) = [650,400]; % window size: [width, height]
se = strel('square', 3); % morphological filter for noise removal
no = {'0','00-0000'};
num =1;
k = 10;
m=0
while ~isDone(videoReader)
frame = step(videoReader); % read the next video frame
% Detect the foreground in the current video frame
foreground = step(foregroundDetector, frame);
% Use morphological opening to remove noise in the foreground
filteredForeground = imopen(foreground, se);
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 150);
% Detect the connected components with the specified minimum area, and
% compute their bounding boxes
bbox = step(blobAnalysis, filteredForeground);
% Draw bounding boxes around the detected cars
result = insertShape(frame, 'Rectangle', bbox, 'Color', 'green');
% Display the number of cars found in the video frame
numCars = size(bbox, 1);
m = m+ numCars;
%st = {'JRW-2731','BCR-5890','WJ-6629','MW-5587','RV-6929','BN-8944','AN-7037','BI-7899','BI-7899','RX-7294','TL-9090'};
noplat;
result = insertText(result, [10 50; 10 100], no, 'BoxOpacity', 1, ...
'FontSize', 14);
step(videoPlayer, result); % display the results
% step(videoPlayer, result1);
end
release(videoReader); % close the video file
这是下一个文件;
if m>6800 && k == 10
no = {'1','DAE-4321'};
k = k-1;
end
if m>9600 && k==9
no = {'2','204-0024'};
k = k-1;
end
if m>15000 && k==8
no = {'3','QK-BG18'};
k = k-1;
end
if m>23700 && k==7
no = {'4','KT-7349'};
k = k-1;
end
if m>25000 && k==6
no = {'5','K2-1479'};
k = k-1;
end
if m>25800 && k==5
no = {'6','BG-5218'};
k = k-1;
end
if m>33300 && k==4
no = {'7','B2-8697'};
k = k-1;
end
if m>37900 && k==3
no = {'8','PQ-1374'};
k = k-1;
end
if m>90500 && k==2
no = {'9','RX-7294'};
k = k-1;
end
if m>97000 && k==1
no = {'10','TL-9090'};;
k = k-1;
end