function varargout = main(varargin)
% MAIN MATLAB code for main.fig
% MAIN, by itself, creates a new MAIN or raises the existing
% singleton*.
%
% H = MAIN returns the handle to a new MAIN or the handle to
% the existing singleton*.
%
% MAIN('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in MAIN.M with the given input arguments.
%
% MAIN('Property','Value',...) creates a new MAIN or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before main_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to main_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 main
% Last Modified by GUIDE v2.5 26-Mar-2018 08:59:30
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @main_OpeningFcn, ...
'gui_OutputFcn', @main_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 main is made visible.
function main_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 main (see VARARGIN)
% Choose default command line output for main
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes main wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
function varargout = main_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;
function edit2_Callback(hObject, eventdata, handles)
% hObject handle to edit2 (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 edit2 as text
% str2double(get(hObject,'String')) returns contents of edit2 as a double
% --- Executes during object creation, after setting all properties.
function edit2_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit2 (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
function edit1_Callback(hObject, eventdata, handles)
% hObject handle to edit1 (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 edit1 as text
% str2double(get(hObject,'String')) returns contents of edit1 as a double
% --- Executes during object creation, after setting all properties.
function edit1_CreateFcn(hObject, eventdata, handles)
% hObject handle to edit1 (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 pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
[filename, pathname] = uigetfile( '*.avi', '开始');
implay([pathname,filename]);
mov=VideoReader(filename);
frames=read(mov);
%计数车流量
car_count=0;
set(handles.edit2,'string',num2str(0));
for i=1:2:size(frames,4)-1
%读取视频文件
img0=frames(:,:,:,i);%i表示要读取的第几帧
%显示当前处理的帧数
set(handles.edit1,'string',num2str(i));
%显示原视频文件
axes(handles.axes3);
imshow(img0);
axes(handles.axes4);
[us,vs]=HSoptflow(frames,i);
i3=im2bw(vs);
SE1=strel('square',1);
%腐蚀操作
a_erode=imerode(i3,SE1,'same'); %erode
SE2 = strel('square',7);
%膨胀操作
erode_dilate_img=imdilate(a_erode,SE2,'same'); %dilate
Ibw=im2bw(erode_dilate_img);
status=regionprops(Ibw,'BoundingBox');
%axes(handles.axes3);
%画出计数界线
[m,n]=size(Ibw);
Ibw(60-2:60+2,:)=1;
imshow(Ibw);hold on;
%画出轮廓并计数
for i=1:size(status,1)
if status(i).BoundingBox(3)<n/2&&status(i).BoundingBox(3)>n/10&&status(i).BoundingBox(4)<m/1.5&&status(i).BoundingBox(4)>m/5
rectangle('position',status(i).BoundingBox,'edgecolor','r');
if abs(status(i).BoundingBox(2)+status(i).BoundingBox(4)-60)<3
car_count=car_count+1;
set(handles.edit2,'string',num2str(floor((car_count+1)/2)));
end
end
end
end
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
[filename, pathname] = uigetfile( '*.avi', '开始');
% readerobj = mmreader([pathname,filename]);
rgb = 3;
gray = 1;
nop = 0;
% get(readerobj )
implay([pathname,filename]);
mov=VideoReader(filename);
frames=read(mov);
%读取第一帧图片
img0 = read( mov, 1);
i1=rgb2gray(img0);
[m,n]=size(i1);
im1=double(i1);
%建立保存图片
i3=zeros(size(i1));
%计数车流量
car_count=0;
set(handles.edit2,'string',num2str(0));
for i=1:2:size(frames,4)
%读取视频文件
img=frames(:,:,:,i);%i表示要读取的第几帧
%显示当前处理的帧数
set(handles.edit1,'string',num2str(i));
%显示原视频文件
axes(handles.axes1);
imshow(img);
%灰度化
i2=rgb2gray(img);
im2=double(i2);
im1=medfilt2(im1,[3,3]);
im2=medfilt2(im2,[3,3]);
%直接做差
% for i=1:m
% for j=1:n
% i3(i,j)=im2(i,j)-im1(i,j);
% end;
% end;
%差别超过阈值
for i=1:m
for j=1:n
if abs(im2(i,j)-im1(i,j))>40%&&im2(i,j)>80
i3(i,j)=255;
else
i3(i,j)=0;
end
end;
end;
SE1=strel('square',4);
%腐蚀操作
a_erode=imerode(i3,SE1,'same'); %erode
SE2 = strel('square',20);
%膨胀操作
erode_dilate_img=imdilate(a_erode,SE2,'same'); %dilate
%去掉上面的干扰部分
%erode_dilate_img(1:100,:)=0;
%size(erode_dilate_img)
axes(handles.axes2);
%imshow(erode_dilate_img);
Ibw=im2bw(erode_dilate_img);
status=regionprops(Ibw,'BoundingBox');
%axes(handles.axes3);
%画出计数界线
Ibw(60-2:60+2,:)=1;
imshow(Ibw)
神经网络机器学习智能算法画图绘图
- 粉丝: 2853
- 资源: 660
最新资源
- 基于SOGI代替传统滑模观测器的永磁同步电机无感FOC算法研究与实践,基于SOGI-PLL的永磁同步电机无感FOC 1.采用SOGI代替传统滑模观测器smo中的低通滤波器,有效减小转速波动; 2.提供
- 基于MATLAB Simulink的200W双输入反激变换器模型:输入电压可调230-280V,输出设定为48V闭环控制仿真分析,双输入反激变器模型,200W, 输入电压可变230-280V(可以自己
- 感应电机初步设计报告:功率性能分析、定子设计与仿真,高转矩输出及效率优化,感应电机,功率55KW,转速1485rpm,定子48槽,内容包含RMxprt初步设计以及mawell 2D设计,启动转矩仿真
- 电机控制器与电动车电驱方案的主动阻尼控制与转矩补偿技术-波动抑制效果展示,电机控制器,电动车电驱方案,主动阻尼控制,damping control,转矩补偿,振动、谐振抑制 公司多个量产实际项目中用
- "电力电子方向入门学习-探究PSIM的DC-DC仿真降压斩波电路Buck的工作原理",PSIM的DC-DC仿真,降压斩波电路Buck~~可用作电力电子方向入门学习 ,PSIM的DC-DC仿真; 降压
- 汽车BCM程序源代码解析:从内外灯光到CAN通讯,全面研究国产车电路控制系统的绝佳参考,汽车BCM程序源代码,国产车BCM程序源代码,喜好汽车电路控制系统研究的值得入手 外部灯光:前照灯、
- 轴承清洗机控制系统中S7-200 PLC与MCGS组态的梯形图编程及系统配置详解, S7-200 PLC程序MCGS组态轴承清洗机控制系统 带解释的梯形图程序,接线图原理图图纸,io分配,组态画面
- “Multisim仿真下的220V转12V开关电源电路设计与优化:精密稳压与光耦合器应用”,220v转12v开关电源电路仿真 Multisim仿真 该电路增加了光耦合器和可调精密并联稳压器r4为限流
- 基于模型预测控制MPC的三种路径跟踪仿真:超车、蛇形与直线轨迹,运行稳定,控制流畅,效果良好,基于模型预测mpc的三种路径跟踪,三个仿真,超车轨迹,蛇形轨迹,直线轨迹,仿真运行稳定,控制量变化平滑自然
- 基于MPC的电动汽车分布式协同自适应巡航控制仿真研究:期望加速度与扭矩分配策略,基于MPC的分布式电动汽车协同自适应巡航控制,采用上下分层控制方式,上层控制器采用模型预测控制mpc方式,产生期望的加速
- 基于滑膜控制的后轮主动与DYC协调稳定性控制策略 采用ARS产生期望后轮转角度,DYC产生横摆力矩,实现路面附着系数与车速下的附加横摆力矩分配,提升车辆稳定性,适用于轨迹跟踪的横向稳性控制 ,基于滑膜
- 基于MPC算法的车辆稳定性控制策略:精确预测模型与协调控制仿真验证,基于MPC算法实现的车辆稳定性控制,建立了横摆角速度r、侧向速度、前后质心侧偏角动力学模型作为预测模型,同时考虑车辆的稳定性可通过控
- 基于PID控制的超车轨迹跟踪技术:高效跟踪期望轨迹的详细指南,基于pid控制的超车轨迹跟踪,能够很好的跟踪期望轨迹 有详细的说明文档 ,基于pid控制的超车轨迹跟踪; 轨迹跟踪性能; 详细说明文档
- 递归最小二乘法估计车辆前后轮胎侧偏刚度:仿真实验验证与算法参数需求解析,基于递归最小二乘法估计的车辆前后轮胎的侧偏刚度,如仿真结果图可知,在恒定转角变化速度下,能够很好的估算出前后轮胎的平均刚度,该估
- 基于四轮驱动电动汽车控制平台的模型预测控制轨迹跟踪技术:稳定速度与轨迹跟踪实现及原理详解,附carsim与matlab仿真学习参考,基于四轮驱动电动汽车控制平台实现了纵向速度和横向轨迹跟踪控制,横向算
- 自动驾驶控制下的车辆二、三自由度动力学MPC任意路径跟踪技术-Carsim与Simulink联合仿真展示,自动驾驶控制-二 三自由度动力学MPC任意路径跟踪 是可以跟踪各种自定义路径,可以自己更改参
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈