【图像识别】基于计算机视觉实现红绿灯识别含Matlab代码

 1 简介

交通信号灯控制主要是利用检测技术和传感技术来检测交通参数,以此为基础进行控制。在交通压力日渐增大的背景下,各个路口车流量不均衡的问题逐渐凸显出来,往往一边路口车流量较小而绿灯开启时间长,另一路口车流量较大而绿灯开启时间短,这种不合理的控制严重影响了城市交通的顺畅性,如何实现交通信号灯的智能控制越来越受到关注。对交通灯的识别主要基于对交通灯的色彩及形状特征.基于信号灯的亮度对其进行分割,提取,并设置了一种自动最优选择阈值的方法.再由HIS彩色空间的H信息识别颜色.最后根据二值化的交通灯的横坐标和纵坐标方向的投影进行形状匹配识别.

2 部分代码

function varargout = Maindeng(varargin)
% MAINDENG MATLAB code for Maindeng.fig
%      MAINDENG, by itself, creates a new MAINDENG or raises the existing
%      singleton*.
%
%      H = MAINDENG returns the handle to a new MAINDENG or the handle to
%      the existing singleton*.
%
%      MAINDENG('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MAINDENG.M with the given input arguments.
%
%      MAINDENG('Property','Value',...) creates a new MAINDENG or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before Maindeng_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to Maindeng_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help Maindeng

% Last Modified by GUIDE v2.5 21-Jun-2022 22:14:12

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @Maindeng_OpeningFcn, ...
                   'gui_OutputFcn',  @Maindeng_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 Maindeng is made visible.
function Maindeng_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 Maindeng (see VARARGIN)

% Choose default command line output for Maindeng
handles.output = hObject;      %下面全部为设定作图区域属性
handles.cd0 = cd;
handles.Color = 0;
handles.I = [];

axes(handles.axes1);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes2);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes3);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;

axes(handles.axes4);
set(gca,'Xtick',[]);
set(gca,'Ytick',[]);
box on;
% Update handles structure
guidata(hObject, handles);

% UIWAIT makes Maindeng wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = Maindeng_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)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on button press in radiobutton3.
function radiobutton3_Callback(hObject, eventdata, handles)
% hObject    handle to radiobutton3 (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 radiobutton3



Y=[Y(1,:),Y(2,:)];  Y=minmax(Y);
GI=GI(x1:x2,Y(1):Y(2));         %定位图像区域
a=handles.sin;
a=a(x1:x2,Y(1):Y(2),:);  handles.image=a;
axes(handles.axes4);
imshow(GI);
title('图像分割'); 
handles.GI = GI;       %将当前的图像数据传递给全局句柄
guidata(hObject, handles);  %刷新


% --- If Enable == 'on', executes on mouse press in 5 pixel border.
% --- Otherwise, executes on mouse press in 5 pixel border or over text2.
function text2_ButtonDownFcn(hObject, eventdata, handles)
% hObject    handle to text2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
if isempty(handles.string);
   set(handles.text2,'string',handles.string); 
end
 

3 仿真结果

4 参考文献

[1]李佳阳, 刘奇. 基于MATLAB的交通信号灯识别方法[J]. 甘肃科技, 2016, 32(23):4.

博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。

部分理论引用网络文献,若有侵权联系博主删除。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

matlab科研助手

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值