clc
mainfc;
[name,path]=uigetfile({'*.jpg';'*.bmp';'tif'},'载入图像');
x=imread([path,name]); %获取位置
figure(1);%axes表示获取位置,这里选取的位置为axes1;
imshow(x); %显示图像
title('测试原图')
f=x;
f=rgb2gray(f);
f=edge(f,'canny');
figure
imshow(f);
title('边缘检测');
f=bwareaopen(f,200);
figure
imshow(f);
title('腐蚀');
se=strel('disk',2); %生成圆形结构元素
f=imdilate(f,se); %用生成的结构元素对图像进行腐蚀
figure
imshow(f);
title('膨胀');
se=strel('disk',1);
fc=imclose(f,se);%闭运算
fc=imfill(fc,'hole');%填洞
figure,imshow(fc);
title('填洞')
%%%%定位
L = bwlabel(fc);
STATS = regionprops(L,'all');
%在bw图像上绘制出连通域的矩形框
figure(1); imshow(x); title('定位图')
hold on
BW=fc;
[L,num] = bwlabel(BW); %标记
global boundary
for i = 1 : size(STATS, 1)
boundary = STATS(i).BoundingBox;
rectangle('Position',boundary,'edgecolor','r' );
end
diyilie=boundary(1);
diyihang=boundary(2);
liekuan=boundary(3);
hanggao=boundary(4);
%%%判断姿势
rate=hanggao/liekuan;
if rate>3
msgbox('站立');
end
猪尾巴草龙
- 粉丝: 1120
- 资源: 69