【跌倒检测】基于matlab中值滤波+二值化跌倒检测【含Matlab源码 344期】
一、获取代码方式
获取代码方式1:
通过订阅紫极神光博客付费专栏,凭支付凭证,私信博主,可获得此代码。
获取代码方式2:
完整代码已上传我的资源:【跌倒检测】基于matlab中值滤波+二值化跌倒检测【含Matlab源码 344期】
备注:
订阅紫极神光博客付费专栏,可免费获得1份代码(有效期为订阅日起,三天内有效);
二、简介
中值滤波是基于排序统计理论的一种能有效抑制噪声的非线性信号处理技术,中值滤波的基本原理是把数字图像或数字序列中一点的值用该点的一个邻域中各点值的中值代替,让周围的像素值接近的真实值,从而消除孤立的噪声点。方法是用某种结构的二维滑动模板,将板内像素按照像素值的大小进行排序,生成单调上升(或下降)的为二维数据序列。二维中值滤波输出为g(x,y)=med{f(x-k,y-l),(k,l∈W)} ,其中,f(x,y),g(x,y)分别为原始图像和处理后图像。W为二维模板,通常为33,55区域。经中值滤波后图像如图1所示。
三、部分源代码
clear all clc
global Bili;
A=[];
B=imread('46.jpg');
B=rgb2gray(B);
B=medfilt2(B); %中值滤波
fileName = '倾斜跌倒1.avi';
obj = VideoReader(fileName); %读取录制的视频
vidFrames=read(obj); %读取所有帧图像
numFrames=get(obj, 'NumberOfFrames');%总帧数
for k = 63:250 %帧数循环,人为选取33帧作为背景帧
mov(k).cdata=vidFrames(:,:,:,k);
mov(k).cdata=rgb2gray(mov(k).cdata);
mov(k).cdata=medfilt2(mov(k).cdata);
R=imabsdiff(mov(k).cdata,B);
z=im2bw(R,graythresh(R));
z=bwmorph(z,'erode',3); % 3次腐蚀处理掉噪点
P = bwmorph(z,'dilate',3); %3次膨胀膨胀
P= bwareaopen(P,50);
figure(1),subplot(121);imshow(vidFrames(:,:,:,k));
figure(1);subplot(122);imshow(P);
x=sum(P(:));
s=x/(480*640);
if s>=0.03
[m1,n1] = find(P == 1);
%第一级检测,角度
top1= min(m1);%纵向
bottom1= max(m1);
left1= min(n1);%横向
right1= max(n1);
height1=bottom1-top1+1;%纵向高;
width1 = right1-left1+1;%横向宽
rectangle('Position',[left1,top1,width1,height1],'EdgeColor','r');
line([left1,right1],[top1,bottom1],'color','r','LineWidth',1);%标记对角线
line([left1,right1],[bottom1,top1],'color','r','LineWidth',1);
tan=(bottom1-top1)/(right1-left1);
tan=atan(tan);
J=tan*180/pi;
%第二级检测,质心高度比Rz
[rectx,recty,area,perimeter] = minboundrect(n1,m1,'p');
line(rectx(:),recty(:),'color','w','LineWidth',1);
line([rectx(1),rectx(3)],[recty(1),recty(3)],'color','b','LineWidth',1);
line([rectx(2),rectx(4)],[recty(2),recty(4)],'color','b','LineWidth',1);
line([0,640],[max(bottom1),max(bottom1)],'color','r','LineWidth',2);%水平线
line([(rectx(1)+rectx(3))/2,(rectx(1)+rectx(3))/2],[(recty(1)+recty(3))/2,max(bottom1)],'color','b','LineWidth',2);%画高
h=max(bottom1)-(recty(1)+recty(3))/2;%高度
Rz=h/360;
function [rectx,recty,area,perimeter] = minboundrect(x,y,metric)
% minboundrect: Compute the minimal bounding rectangle of points in the plane
% usage: [rectx,recty,area,perimeter] = minboundrect(x,y,metric)
%
% arguments: (input)
% x,y - vectors of points, describing points in the plane as
% (x,y) pairs. x and y must be the same lengths.
%
% metric - (OPTIONAL) - single letter character flag which
% denotes the use of minimal area or perimeter as the
% metric to be minimized. metric may be either 'a' or 'p',
% capitalization is ignored. Any other contraction of 'area'
% or 'perimeter' is also accepted.
%
% DEFAULT: 'a' ('area')
%
% arguments: (output)
% rectx,recty - 5x1 vectors of points that define the minimal
% bounding rectangle.
%
% area - (scalar) area of the minimal rect itself.
%
% perimeter - (scalar) perimeter of the minimal rect as found
%
%
% Note: For those individuals who would prefer the rect with minimum
% perimeter or area, careful testing convinces me that the minimum area
% rect was generally also the minimum perimeter rect on most problems
% (with one class of exceptions). This same testing appeared to verify my
% assumption that the minimum area rect must always contain at least
% one edge of the convex hull. The exception I refer to above is for
% problems when the convex hull is composed of only a few points,
% most likely exactly 3. Here one may see differences between the
% two metrics. My thanks to Roger Stafford for pointing out this
% class of counter-examples.
%
% Thanks are also due to Roger for pointing out a proof that the
% bounding rect must always contain an edge of the convex hull, in
% both the minimal perimeter and area cases.
%
%
% Example usage:
% x = rand(50000,1);
% y = rand(50000,1);
% tic,[rx,ry,area] = minboundrect(x,y);toc
%
% Elapsed time is 0.105754 seconds.
%
% [rx,ry]
% ans =
% 0.99994 -4.2515e-06
% 0.99998 0.99999
% 2.6441e-05 1
% -5.1673e-06 2.7356e-05
% 0.99994 -4.2515e-06
%
% area
% area =
% 0.99994
%
%
% See also: minboundcircle, minboundtri, minboundsphere
%
%
% Author: John D'Errico
% E-mail: woodchips@rochester.rr.com
% Release: 3.0
% Release date: 3/7/07
% default for metric
if (nargin<3) || isempty(metric)
metric = 'a';
elseif ~ischar(metric)
error 'metric must be a character flag if it is supplied.'
else
% check for 'a' or 'p'
metric = lower(metric(:)');
ind = strmatch(metric,{'area','perimeter'});
if isempty(ind)
error 'metric does not match either ''area'' or ''perimeter'''
end
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 100
- 101
- 102
- 103
- 104
- 105
- 106
- 107
- 108
- 109
- 110
- 111
- 112
- 113
- 114
- 115
- 116
- 117
- 118
- 119
- 120
- 121
- 122
- 123
- 124
- 125
- 126
- 127
- 128
四、运行结果
五、matlab版本及参考文献
1 matlab版本
2014a
2 参考文献
[1] 蔡利梅.MATLAB图像处理——理论、算法与实例分析[M].清华大学出版社,2020.
[2]杨丹,赵海滨,龙哲.MATLAB图像处理实例详解[M].清华大学出版社,2013.
[3]周品.MATLAB图像处理与图形用户界面设计[M].清华大学出版社,2013.
[4]刘成龙.精通MATLAB图像处理[M].清华大学出版社,2015.
文章来源: qq912100926.blog.csdn.net,作者:海神之光,版权归原作者所有,如需转载,请联系作者。
原文链接:qq912100926.blog.csdn.net/article/details/113891027
- 点赞
- 收藏
- 关注作者
评论(0)