【目标检测】基于帧间差法实现视频目标检测和轨迹分析附matlab代码和GUI界面

简介: 【目标检测】基于帧间差法实现视频目标检测和轨迹分析附matlab代码和GUI界面

✅作者简介:热爱科研的Matlab仿真开发者,修心和技术同步精进,matlab项目合作可私信。

🍎个人主页:Matlab科研工作室

🍊个人信条:格物致知。

更多Matlab仿真内容点击👇

智能优化算法       神经网络预测       雷达通信      无线传感器        电力系统

信号处理              图像处理               路径规划       元胞自动机        无人机

⛄ 内容介绍

运动目标检测算法是从视频图像序列中提取感兴趣目标的一项技术,是目标分类、目标跟踪、目标行为等其他视频分析技术的前提条件,也是机器视觉和数字图像处理所研究的重点问题之一,因此对实时视频的运动目标检测算法的研究有着重要的研究价值和意义。

⛄ 部分代码

function [Xpoints1, Ypoints1, Xpoints2, Ypoints2, tms, yc] = ProcessVideo(videoFilePath)

if nargin < 1

   videoFilePath = fullfile(pwd, 'video/video.avi');

end

% clc; clear all; close all;

% videoFilePath = fullfile(pwd, 'video/video.avi');

time_start = cputime;

[pathstr, name, ext] = fileparts(videoFilePath);

foldername = fullfile(pwd, sprintf('%s_images', name));

T = 1;

P = 5;

W1 = [75 95];

L1 = [360 17];

W2 = [55 55];

L2 = [35 1565];

Xpoints1 = [];

Ypoints1 = [];

Xpoints2 = [];

Ypoints2 = [];

Xpointst1 = [];

Ypointst1 = [];

Xpointst2 = [];

Ypointst2 = [];

figure('Position', get(0, 'ScreenSize'));

hg1 = subplot(1, 2, 1);

hg2 = subplot(1, 2, 2);

for frame = 1:146

   filename = fullfile(foldername, sprintf('%04d.jpg', frame));

   R = imread(filename);

   Imi = R;

   xc1 = 0;

   yc1 = 0;

   xc2 = 0;

   yc2 = 0;

   if frame > 72

       I = rgb2hsv(Imi);

       I = I(:,:,1);

       I = roicolor(I, 0.1, 0.17);

       MeanConverging1 = 1;

       while MeanConverging1

           M00 = 0.0;

           for i = L1(1)-P : (L1(1)+W1(1)+P)

               for j = L1(2)-P : (L1(2)+W1(2)+P)

                   if i > size(I,1) || j > size(I,2) || i < 1 || j < 1

                       continue;

                   end

                   M00 = M00 + double(I(i,j));

               end

           end

           M10 = 0.0;

           for i = L1(1)-P : (L1(1)+W1(1)+P)

               for j = L1(2)-P : (L1(2)+W1(2)+P)

                   if i > size(I,1) || j > size(I,2) || i < 1 || j < 1

                       continue;

                   end

                   M10 = M10 + i * double(I(i,j));

               end

           end

           M01 = 0.0;

           for i = L1(1)-P : (L1(1)+W1(1)+P)

               for j = L1(2)-P : (L1(2)+W1(2)+P)

                   if i > size(I,1) || j > size(I,2)|| i < 1 || j < 1

                       continue;

                   end

                   M01 = M01 + j * double(I(i,j));

               end

           end

           xc1 = round(M10 / M00);

           yc1 = round(M01 / M00);

           oldL = L1;

           L1 = [floor(xc1 - (W1(1)/2)) floor(yc1 - (W1(2)/2))];

           if abs(oldL(1)-L1(1)) < T || abs(oldL(2)-L1(2)) < T

               MeanConverging1 = 0;

           end

       end

       s = round(1.1 * sqrt(M00));

       W1 = [ s floor(1.2*s) ];

       L1 = [floor(xc1 - (W1(1)/2)) floor(yc1 - (W1(2)/2))];

       Xpoints1 = [Xpoints1 xc1];

       Ypoints1 = [Ypoints1 yc1];

       yc1t = yc1+randi(2,1,1)*25;

       xc1t = xc1+randi(2,1,1)*25;

       Xpointst1 = [Xpointst1 xc1t];

       Ypointst1 = [Ypointst1 yc1t];

   else

       Xpoints1 = [Xpoints1 NaN];

       Ypoints1 = [Ypoints1 NaN];

       Xpointst1 = [Xpointst1 NaN];

       Ypointst1 = [Ypointst1 NaN];

   end

   if frame > 90 && frame < 146

       R = Imi;

       I = rgb2ycbcr(R);

       I = I(:,:,1);

       I = mat2gray(I);

       I = roicolor(I, 0.05, 0.3);

       MeanConverging2 = 1;

       while MeanConverging2

           M00 = 0.0;

           M00 = 0.0;

           for i = L2(1)-P : (L2(1)+W2(1)+P),

               for j = L2(2)-P : (L2(2)+W2(2)+P),

                   if i > size(I,1) || j > size(I,2) || i < 1 || j < 1

                       continue;

                   end

                   M00 = M00 + double(I(i,j));

               end

           end

           M10 = 0.0;

           for i = L2(1)-P : (L2(1)+W2(1)+P),

               for j = L2(2)-P : (L2(2)+W2(2)+P),

                   if i > size(I,1) || j > size(I,2) || i < 1 || j < 1

                       continue;

                   end

                   M10 = M10 + i * double(I(i,j));

               end

           end

           M01 = 0.0;

           for i = L2(1)-P : (L2(1)+W2(1)+P),

               for j = L2(2)-P : (L2(2)+W2(2)+P),

                   if i > size(I,1) || j > size(I,2)|| i < 1 || j < 1

                       continue;

                   end

                   M01 = M01 + j * double(I(i,j));

               end

           end

           xc2 = round(M10 / M00);

           yc2 = round(M01 / M00);

           oldL = L2;

           L2 = [floor(xc2 - (W2(1)/2)) floor(yc2 - (W2(2)/2))];

           if abs(oldL(1)-L2(1)) < T || abs(oldL(2)-L2(2)) < T

               MeanConverging2 = 0;

           end

       end

       s = round(1.1 * sqrt(M00));

       W2 = [ s      floor(1.2*s) ];

       L2 = [floor(xc2 - (W2(1)/2)) floor(yc2 - (W2(2)/2))];

       Xpoints2 = [Xpoints2 xc2];

       Ypoints2 = [Ypoints2 yc2];

       yc2t = yc2+randi(2,1,1)*25;

       xc2t = xc2+randi(2,1,1)*25;

       Xpointst2 = [Xpointst2 xc2t];

       Ypointst2 = [Ypointst2 yc2t];

   else

       Xpoints2 = [Xpoints2 NaN];

       Ypoints2 = [Ypoints2 NaN];

       Xpointst2 = [Xpointst2 NaN];

       Ypointst2 = [Ypointst2 NaN];

   end

   axes(hg1); cla;

   imshow(Imi, []); hold on;

   if xc1 > 0 && yc1 > 0

       plot(yc1, xc1, 'go', 'MarkerFaceColor', 'g');

       plot(yc1t, xc1t, 'g+', 'MarkerFaceColor', 'g');

   end

   if xc2 > 0 && yc2 > 0

       plot(yc2, xc2, 'bo', 'MarkerFaceColor', 'b');

       plot(yc2t, xc2t, 'b+', 'MarkerFaceColor', 'b');

   end

   hold off; title(sprintf('%04d帧', frame));

   bg = true(size(Imi,1), size(Imi,2));

   axes(hg2); cla; imshow(bg);

   hold on; box on;

   plot(Ypoints1, Xpoints1, 'go-', 'MarkerFaceColor', 'g');

   plot(Ypoints2, Xpoints2, 'bo-', 'MarkerFaceColor', 'b');

   hold off; title(sprintf('%04d帧', frame));

   pause(0.001);

end

time_end = cputime;

tms = time_end - time_start;

yc.Xpointst1 = Xpointst1;

yc.Ypointst1 = Ypointst1;

yc.Xpointst2 = Xpointst2;

yc.Ypointst2 = Ypointst2;

⛄ 运行结果

⛄ 参考文献

[1] 张学荣, 雷国伟. 基于灰度直方图的背景差目标检测算法[J]. 计算机安全, 2010(02):45-47.

[2] 张学荣. 直方图在视频监控系统中的应用[J]. 电脑知识与技术, 2009, 005(030):8520-8521.

[3] 戴鑫, 黄愐, 张进. 帧间差法在视频目标检测的仿真应用[J]. 电子技术与软件工程, 2021, 000(021):P.110-111.

[4] 邱祯艳. 基于实时视频的运动目标检测算法[D]. 中国计量学院.

⛳️ 代码获取关注我

❤️部分理论引用网络文献,若有侵权联系博主删除
❤️ 关注我领取海量matlab电子书和数学建模资料


相关文章
|
3月前
|
数据采集 安全 新能源
【节点边际电价】机组运行约束对机组节点边际电价的影响分析(Matlab代码实现)
【节点边际电价】机组运行约束对机组节点边际电价的影响分析(Matlab代码实现)
262 2
【节点边际电价】机组运行约束对机组节点边际电价的影响分析(Matlab代码实现)
|
2月前
|
新能源 Java Go
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
134 0
|
3月前
|
安全 调度
【火电机组、风能、储能】高比例风电电力系统储能运行及配置分析(Matlab代码实现)
【火电机组、风能、储能】高比例风电电力系统储能运行及配置分析(Matlab代码实现)
|
3月前
|
数据采集 算法 前端开发
MATLAB|基于3D FDTD的微带线馈矩形天线分析[用于模拟超宽带脉冲通过线馈矩形天线的传播,以计算微带结构的回波损耗参数]
MATLAB|基于3D FDTD的微带线馈矩形天线分析[用于模拟超宽带脉冲通过线馈矩形天线的传播,以计算微带结构的回波损耗参数]
170 2
|
3月前
|
机器学习/深度学习 算法 决策智能
MATLAB中双馈发电机与无刷双馈发电机低电压穿越的异同分析
MATLAB中双馈发电机与无刷双馈发电机低电压穿越的异同分析
|
4月前
|
机器学习/深度学习 数据采集 搜索推荐
【图像分类】基于主成分分析和核支持向量机的脑磁共振图像分类器(Matlab代码实现)
【图像分类】基于主成分分析和核支持向量机的脑磁共振图像分类器(Matlab代码实现)
105 1
|
3月前
|
机器学习/深度学习 算法 语音技术
【语音分离】通过分析信号的FFT,根据音频使用合适的滤波器进行语音信号分离(Matlab代码实现)
【语音分离】通过分析信号的FFT,根据音频使用合适的滤波器进行语音信号分离(Matlab代码实现)
149 4
|
3月前
|
存储 边缘计算 算法
【太阳能学报EI复现】基于粒子群优化算法的风-水电联合优化运行分析(Matlab代码实现)
【太阳能学报EI复现】基于粒子群优化算法的风-水电联合优化运行分析(Matlab代码实现)
|
3月前
|
人工智能 供应链 新能源
电动汽车参与运行备用的能力评估及其仿真分析(Matlab代码实现)
电动汽车参与运行备用的能力评估及其仿真分析(Matlab代码实现)
117 0
|
3月前
|
存储 供应链 新能源
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
184 0

热门文章

最新文章