【目标检测】基于帧间差法实现视频目标检测和轨迹分析附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电子书和数学建模资料


相关文章
|
8月前
|
机器学习/深度学习 算法 机器人
【水下图像增强融合算法】基于融合的水下图像与视频增强研究(Matlab代码实现)
【水下图像增强融合算法】基于融合的水下图像与视频增强研究(Matlab代码实现)
749 0
|
8月前
|
算法 定位技术 计算机视觉
【水下图像增强】基于波长补偿与去雾的水下图像增强研究(Matlab代码实现)
【水下图像增强】基于波长补偿与去雾的水下图像增强研究(Matlab代码实现)
1033 0
|
8月前
|
算法 机器人 计算机视觉
【图像处理】水下图像增强的颜色平衡与融合技术研究(Matlab代码实现)
【图像处理】水下图像增强的颜色平衡与融合技术研究(Matlab代码实现)
273 0
|
8月前
|
机器学习/深度学习 算法 机器人
使用哈里斯角Harris和SIFT算法来实现局部特征匹配(Matlab代码实现)
使用哈里斯角Harris和SIFT算法来实现局部特征匹配(Matlab代码实现)
374 8
|
8月前
|
机器学习/深度学习 编解码 算法
基于OFDM技术的水下声学通信多径信道图像传输研究(Matlab代码实现)
基于OFDM技术的水下声学通信多径信道图像传输研究(Matlab代码实现)
367 8
|
8月前
|
机器学习/深度学习 数据采集 测试技术
基于CEEMDAN-VMD-BiLSTM的多变量输入单步时序预测研究(Matlab代码实现)
基于CEEMDAN-VMD-BiLSTM的多变量输入单步时序预测研究(Matlab代码实现)
324 8
|
8月前
|
机器学习/深度学习 算法 自动驾驶
基于导向滤波的暗通道去雾算法在灰度与彩色图像可见度复原中的研究(Matlab代码实现)
基于导向滤波的暗通道去雾算法在灰度与彩色图像可见度复原中的研究(Matlab代码实现)
431 8
|
8月前
|
新能源 Java Go
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
【EI复现】参与调峰的储能系统配置方案及经济性分析(Matlab代码实现)
274 0
|
8月前
|
编解码 运维 算法
【分布式能源选址与定容】光伏、储能双层优化配置接入配电网研究(Matlab代码实现)
【分布式能源选址与定容】光伏、储能双层优化配置接入配电网研究(Matlab代码实现)
732 12
|
8月前
|
人工智能 数据可视化 网络性能优化
【顶级SCI复现】虚拟电厂的多时间尺度调度:在考虑储能系统容量衰减的同时,整合发电与多用户负荷的灵活性研究(Matlab代码实现)
【顶级SCI复现】虚拟电厂的多时间尺度调度:在考虑储能系统容量衰减的同时,整合发电与多用户负荷的灵活性研究(Matlab代码实现)
276 9

热门文章

最新文章