📄 testje.m
字号:
%% Gesture Recognition Hand
% En este proyecto se pretende reconocer gestos de la mano para comandar
% El puntero del mouse
% Vision de maquina - Universidad del cauca
% Jorge Andres Cerquera Yacumal
% Jhon Edwin Cordoba Papamija
clear all
close all
clc
%% Lectura de la imagen desde archivo
tic
I = imread('1.jpg'); % carga imagen en la variable I
figure, imshow(I); % muestra la imagen
I=rgb2gray(I); % Conversion RGB a gray
figure, imshow(K);
%% Filtrado y Mejoramiento del Contraste
MI = medfilt2(I,[3 3]); % Filtro de mediana
K = imadjust(MI); % Mejoramiento del contraste
%% Umbralizacion
JU = im2bw(K,0.55);
%level = graythresh(K);
%JU = im2bw(K,level);
figure, imshow(JU)
%% Apertura y cierre
se = strel('disk',3);
bw2 = imclose(JU,se);
bw3 = imopen(bw2,se);
figure, imshow(bw3)
%%
%BW2 = bwmorph(bw3,'remove');
%figure, imshow(BW2)
%%
SK = bwmorph(bw3,'thin',Inf);
%figure, imshow(SK);
hold on;
%% transformada de hough
[H,Theta,Rho] = hough(SK);
P = houghpeaks(H,10,'threshold',ceil(0.3*max(H(:))));
lines = houghlines(SK,Theta,Rho,P);
lenlines=1:1:length(lines);
max_len = 0;
largolines = length(lines);
valory = zeros(1,(largolines*2));
valorx = zeros(1,(largolines*2));
for k = 1:largolines
valory(k) = lines(k).point1(2);
valory(k+largolines) = lines(k).point2(2);
valorx(k) = lines(k).point1(1);
valorx(k+largolines) = lines(k).point2(1);
xy = [lines(k).point1; lines(k).point2];
%plot(xy(:,1),xy(:,2),'LineWidth',2,'Color','green');
% Plot beginnings and ends of lines
%plot(xy(1,1),xy(1,2),'x','LineWidth',2,'Color','yellow');
%plot(xy(2,1),xy(2,2),'x','LineWidth',2,'Color','red');
% Determine the endpoints of the longest line segment
len = norm(lines(k).point1 - lines(k).point2);
if ( len > max_len)
max_len = len;
xy_long = xy;
end
%message = sprintf('Ang=%2.3f leng=%2.3f',lines(k).theta,len);
%text(15,15+10*k,message,'Color','y','FontWeight','bold');
lenlines(k)=len;
%angulo(k) = lines(k).theta*pi/180;
end
%%
% for i=1:length(lines)
% hold on;
% plot(i,lenlines(i)*sin(lines(i).theta),'x','LineWidth',2,'Color','black');
% end
%% Determinar el numero de objetos de la imagen
[labeled,numObjects] = bwlabel(bw3,4);
%figure, imshow(bw3);
disp(numObjects);
%%
% pseudo_color = label2rgb(labeled, @spring, 'b', 'shuffle');
% figure, imshow(pseudo_color);
%%
% Medir las propiedades de los objetos de la imagen
% basic mide area, centroide y bounding box
graindata = regionprops(labeled,'basic');
%%
% Desplegar las caracteristicas del objeto 51
area = graindata(1).Area;
Centroide = graindata(1).Centroid;
BoundingBox = graindata(1).BoundingBox;
%Ibox = reshape(Ibox,[4 50]);
%% Plot the Object Location
hold on;
rectangle('position',BoundingBox,'edgecolor','r');
%%
xc = Centroide(1);
yc = Centroide(2);
Centrom = [xc yc];
% hold on;
% plot(xc,yc,'yx','LineWidth',10);
%message = sprintf('Area=%2.3f Centro=%2.3f - %2.3f ', area,Centroide(1),Centroide(2));
%text(15,15,message,'Color','y','FontWeight','bold');
%% Encotrar y dibujar la linea central en y
minimoy = min(valory);
[row,col] = find(valory <= minimoy);
if(col > (largolines))
col = col-(largolines);
puntominy = lines(col).point2;
else
puntominy = lines(col).point1;
end
linecy = [puntominy;Centrom];
plot(linecy(:,1),linecy(:,2),'LineWidth',2,'Color','blue');
%% Encotrar y dibujar la linea central en x
minimox = max(valorx);
[row,col] = find(valorx >= minimox);
if(col > (largolines))
col = col-(largolines);
puntominx = lines(col).point2;
else
puntominx = lines(col).point1;
end
linecx = [puntominx;Centrom];
plot(linecx(:,1),linecx(:,2),'LineWidth',2,'Color','blue');
toc
%%
%figure,rose(angulo,lenlines);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -