1423 Sign Language Detection
vid = videoinput('winvideo',1);
set(vid,'TriggerRepeat',Inf);
vid.FrameGrabInterval = 2;
vid_src = getselectedsource(vid);
set(vid_src,'Tag','Indian sign langauge');
%figure;
start(vid)
while(vid.FramesAcquired<=5) % Stop after 100 frames
data = getdata(vid,2);
diff_im = data(:,:,:,1);
end
stop(vid)
delete(vid)
[m,n,p]=size(diff_im);
I=ycbcr2rgb(diff_im);
mov=data
set(vid,'TriggerRepeat',Inf);
vid.FrameGrabInterval = 2;
vid_src = getselectedsource(vid);
set(vid_src,'Tag','Indian sign langauge');
%figure;
start(vid)
while(vid.FramesAcquired<=5) % Stop after 100 frames
data = getdata(vid,2);
diff_im = data(:,:,:,1);
end
stop(vid)
delete(vid)
[m,n,p]=size(diff_im);
I=ycbcr2rgb(diff_im);
mov=data
Paper
Code
skinThresh = 0.25; % Threshold for skintone detection
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480','ROI', [1 1 640 480], 'ReturnedColorSpace', 'rgb');% Acquire input video stream
vidInfo = imaqhwinfo(vidDevice); % Acquire input video property
hblob = vision.BlobAnalysis('AreaOutputPort', false,'CentroidOutputPort', true,'BoundingBoxOutputPort', true','MinimumBlobArea', 800,'MaximumBlobArea', 3000,'MaximumCount', 10);% Set blob analysis handling
hshapeinsskinBox = vision.ShapeInserter('BorderColor', 'Custom', 'CustomBorderColor', [1 0 0],'Fill', true, 'FillColor', 'Custom', 'CustomFillColor', [1 0 0],'Opacity', 0.4);% Set skin box handling
htextins = vision.TextInserter('Text', 'Number of skin Object: %2d','Location', [7 2],'Color', [1 0 0],'FontSize', 12); % Set text for number of blobs
htextinsCent = vision.TextInserter('Text', '+ X:%4d, Y:%4d', 'LocationSource', 'Input port','Color', [1 1 0],'FontSize', 14);% set text for centroid
hVideoIn = vision.VideoPlayer('Name', 'Indian sign language', 'Position', [100 100 vidInfo.MaxWidth+20 vidInfo.MaxHeight+30]);
nFrame = 0; % Frame number initialization
while(nFrame < 20) % set time
rgbFrame = step(vidDevice); % Acquire single frame
rgbFrame = flipdim(rgbFrame,2); % obtain the mirror image for displaying
diffFrame = imsubtract(rgbFrame(:,:,1), rgb2gray(rgbFrame)); % Get skin component of the image
diffFrame = medfilt2(diffFrame, [3 3]); % Filter out the noise by using median filter
binFrame = im2bw(diffFrame, skinThresh); % Convert the image into binary image with the skin objects as white
[centroid, bbox] = step(hblob, binFrame); % Get the centroids and bounding boxes of the blobs
centroid = uint16(centroid); % Convert the centroids into Integer for further steps
rgbFrame(1:20,1:165,:) = 0; % put a black region on the output stream
vidIn = step(hshapeinsskinBox, rgbFrame, bbox); % Instert the box across skin
for object = 1:1:length(bbox(:,1)) % Write the corresponding centroids
centX = centroid(object,1); centY = centroid(object,2);
vidIn = step(htextinsCent, vidIn, [centX centY], [centX-6 centY-9]);
end
vidIn = step(htextins, vidIn, uint8(length(bbox(:,1)))); % Count the number of blobs
step(hVideoIn, vidIn); % Output video stream
nFrame = nFrame+1;
end
release(hVideoIn); % Release all memory and buffer used
release(vidDevice);
clc;% clear all;
vidDevice = imaq.VideoDevice('winvideo', 1, 'YUY2_640x480','ROI', [1 1 640 480], 'ReturnedColorSpace', 'rgb');% Acquire input video stream
vidInfo = imaqhwinfo(vidDevice); % Acquire input video property
hblob = vision.BlobAnalysis('AreaOutputPort', false,'CentroidOutputPort', true,'BoundingBoxOutputPort', true','MinimumBlobArea', 800,'MaximumBlobArea', 3000,'MaximumCount', 10);% Set blob analysis handling
hshapeinsskinBox = vision.ShapeInserter('BorderColor', 'Custom', 'CustomBorderColor', [1 0 0],'Fill', true, 'FillColor', 'Custom', 'CustomFillColor', [1 0 0],'Opacity', 0.4);% Set skin box handling
htextins = vision.TextInserter('Text', 'Number of skin Object: %2d','Location', [7 2],'Color', [1 0 0],'FontSize', 12); % Set text for number of blobs
htextinsCent = vision.TextInserter('Text', '+ X:%4d, Y:%4d', 'LocationSource', 'Input port','Color', [1 1 0],'FontSize', 14);% set text for centroid
hVideoIn = vision.VideoPlayer('Name', 'Indian sign language', 'Position', [100 100 vidInfo.MaxWidth+20 vidInfo.MaxHeight+30]);
nFrame = 0; % Frame number initialization
while(nFrame < 20) % set time
rgbFrame = step(vidDevice); % Acquire single frame
rgbFrame = flipdim(rgbFrame,2); % obtain the mirror image for displaying
diffFrame = imsubtract(rgbFrame(:,:,1), rgb2gray(rgbFrame)); % Get skin component of the image
diffFrame = medfilt2(diffFrame, [3 3]); % Filter out the noise by using median filter
binFrame = im2bw(diffFrame, skinThresh); % Convert the image into binary image with the skin objects as white
[centroid, bbox] = step(hblob, binFrame); % Get the centroids and bounding boxes of the blobs
centroid = uint16(centroid); % Convert the centroids into Integer for further steps
rgbFrame(1:20,1:165,:) = 0; % put a black region on the output stream
vidIn = step(hshapeinsskinBox, rgbFrame, bbox); % Instert the box across skin
for object = 1:1:length(bbox(:,1)) % Write the corresponding centroids
centX = centroid(object,1); centY = centroid(object,2);
vidIn = step(htextinsCent, vidIn, [centX centY], [centX-6 centY-9]);
end
vidIn = step(htextins, vidIn, uint8(length(bbox(:,1)))); % Count the number of blobs
step(hVideoIn, vidIn); % Output video stream
nFrame = nFrame+1;
end
release(hVideoIn); % Release all memory and buffer used
release(vidDevice);
clc;% clear all;
![](http://www.weebly.com/weebly/images/file_icons/gz.png)
db.zip | |
File Size: | 524 kb |
File Type: | zip |
close all;
clear all;
clc;
filename = 'C:\Users\NINAD\Desktop\db\1.mpg';
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
figure()
imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
%figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
BW24=BW3;
for itrw=1:1:4
path1= 'C:\Users\NINAD\Desktop\db\';
path2= num2str(itrw);
path3='.mpg';
filename = strcat(path1,path2,path3);
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
% figure()
% imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
% figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
%figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
% % I = BW3;
% I = rgb2gray(I);
% [a, b] = size(I);
% I1 = uint8(zeros(a,b));
% flag =0;
%
% for i = 2:1:a-1
% flag = 0;
% for j = 2:1:b-1
% if(I(i, j) > 21 && I(i,j) < 220 )
% if(flag == 0)
% I1(i, j) = 255;
% flag =1;
% end
%
% end
% end
% end
%
% [m, n] = size(I1);
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) == 255)
% b1(x) = i;
% b1(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) < 255)
% b2(x) = i;
% b2(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
%
% plot(b1, 'r-')
% % axis off
% hold on
% plot(b2, 'r-')
%
% for t = 1 : numFrames
Im1 =uint8( bwdist(BW3)) ; %reading individual frames
Im2= uint8(bwdist(BW24)) ;
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
D(itrw) = sum(sqrt(hn1-hn2).^2);
% end
% a = rgb2gray(imread('C:\Data\September\5\s001.png'));
% b = rgb2gray(imread('C:\Data\September\5\s0045.png'));
%
% if(D == 0)
% display('the videos have same frames')
% else
% display('the videos have diff frames')
% end
end
Val=min(abs(D))
for i=1:1:4
if(abs(D(i))==Val)
break
end
end
if(i==1)
disp('Khush');
end
if(i==2)
disp('Dukhi');
end
if(i==3)
disp('Pareshaan');
end
if(i==4)
disp('Gussa');
end
clear all;
clc;
filename = 'C:\Users\NINAD\Desktop\db\1.mpg';
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
figure()
imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
%figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
BW24=BW3;
for itrw=1:1:4
path1= 'C:\Users\NINAD\Desktop\db\';
path2= num2str(itrw);
path3='.mpg';
filename = strcat(path1,path2,path3);
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
% figure()
% imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
% figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
%figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
% % I = BW3;
% I = rgb2gray(I);
% [a, b] = size(I);
% I1 = uint8(zeros(a,b));
% flag =0;
%
% for i = 2:1:a-1
% flag = 0;
% for j = 2:1:b-1
% if(I(i, j) > 21 && I(i,j) < 220 )
% if(flag == 0)
% I1(i, j) = 255;
% flag =1;
% end
%
% end
% end
% end
%
% [m, n] = size(I1);
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) == 255)
% b1(x) = i;
% b1(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) < 255)
% b2(x) = i;
% b2(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
%
% plot(b1, 'r-')
% % axis off
% hold on
% plot(b2, 'r-')
%
% for t = 1 : numFrames
Im1 =uint8( bwdist(BW3)) ; %reading individual frames
Im2= uint8(bwdist(BW24)) ;
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
D(itrw) = sum(sqrt(hn1-hn2).^2);
% end
% a = rgb2gray(imread('C:\Data\September\5\s001.png'));
% b = rgb2gray(imread('C:\Data\September\5\s0045.png'));
%
% if(D == 0)
% display('the videos have same frames')
% else
% display('the videos have diff frames')
% end
end
Val=min(abs(D))
for i=1:1:4
if(abs(D(i))==Val)
break
end
end
if(i==1)
disp('Khush');
end
if(i==2)
disp('Dukhi');
end
if(i==3)
disp('Pareshaan');
end
if(i==4)
disp('Gussa');
end
Latest code on 12th Jan 2015
![](http://www.weebly.com/weebly/images/file_icons/gz.png)
input.zip | |
File Size: | 287 kb |
File Type: | zip |
close all;
clear all;
clc;
filename = 'C:\Users\NINAD\Desktop\db\input.mpg';
movt = VideoReader(filename);
numFrames = movt.NumberOfFrames;
frmax=30;
loop = floor(numFrames/frmax);
mov=movt;
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
for titr = 1:1:loop
filename = 'C:\Users\NINAD\Desktop\db\input.mpg';
mov = VideoReader(filename);
numFrames = mov.NumberOfFrames;
mov1=mov;
j2=(((titr-1)*frmax)+1);
j1= titr*frmax;
%for loop to traverse & process from frame '1' to 'last' frames
for t = j2 : j1
currFrame = read(mov, t); %reading individual frames
figure()
imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
%figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = j2 : (j1-1)
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
BW24=BW3;
for itrw=1:1:4
path1= 'C:\Users\NINAD\Desktop\db\';
path2= num2str(itrw);
path3='.mpg';
filename = strcat(path1,path2,path3);
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
% figure()
% imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
% figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
%figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
% % I = BW3;
% I = rgb2gray(I);
% [a, b] = size(I);
% I1 = uint8(zeros(a,b));
% flag =0;
%
% for i = 2:1:a-1
% flag = 0;
% for j = 2:1:b-1
% if(I(i, j) > 21 && I(i,j) < 220 )
% if(flag == 0)
% I1(i, j) = 255;
% flag =1;
% end
%
% end
% end
% end
%
% [m, n] = size(I1);
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) == 255)
% b1(x) = i;
% b1(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) < 255)
% b2(x) = i;
% b2(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
%
% plot(b1, 'r-')
% % axis off
% hold on
% plot(b2, 'r-')
%
% for t = 1 : numFrames
Im1 =uint8( bwdist(BW3)) ; %reading individual frames
Im2= uint8(bwdist(BW24)) ;
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
D(itrw) = sum(sqrt(hn1-hn2).^2);
% end
% a = rgb2gray(imread('C:\Data\September\5\s001.png'));
% b = rgb2gray(imread('C:\Data\September\5\s0045.png'));
%
% if(D == 0)
% display('the videos have same frames')
% else
% display('the videos have diff frames')
% end
end
Val=min(abs(D))
for i=1:1:4
if(abs(D(i))==Val)
break
end
end
if(i==1)
disp('Khush');
end
if(i==2)
disp('Dukhi');
end
if(i==3)
disp('Pareshaan');
end
if(i==4)
disp('Gussa');
end
end
clear all;
clc;
filename = 'C:\Users\NINAD\Desktop\db\input.mpg';
movt = VideoReader(filename);
numFrames = movt.NumberOfFrames;
frmax=30;
loop = floor(numFrames/frmax);
mov=movt;
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
for titr = 1:1:loop
filename = 'C:\Users\NINAD\Desktop\db\input.mpg';
mov = VideoReader(filename);
numFrames = mov.NumberOfFrames;
mov1=mov;
j2=(((titr-1)*frmax)+1);
j1= titr*frmax;
%for loop to traverse & process from frame '1' to 'last' frames
for t = j2 : j1
currFrame = read(mov, t); %reading individual frames
figure()
imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
%figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = j2 : (j1-1)
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
BW24=BW3;
for itrw=1:1:4
path1= 'C:\Users\NINAD\Desktop\db\';
path2= num2str(itrw);
path3='.mpg';
filename = strcat(path1,path2,path3);
mov = VideoReader(filename);
mov1 = mov;
%getting no of frames
numFrames = mov.NumberOfFrames;
%setting current status of number of frames written to zero
numFramesWritten = 0;
%for loop to traverse & process from frame '1' to 'last' frames
for t = 1 : numFrames
currFrame = read(mov, t); %reading individual frames
% figure()
% imshow(currFrame)
x(:,:,:,t) = currFrame;
I = x(:,:,:,t);
if(size(I, 3) > 1)
final_image = zeros(size(I,1), size(I,2));
for i = 1:size(I,1)
for j = 1:size(I,2)
R = I(i,j,1);
G = I(i,j,2);
B = I(i,j,3);
if(R > 95 && G > 40 && B > 20)
v = [R,G,B];
if((max(v) - min(v)) > 15)
if(abs(R-G) > 15 && R > G && R > B)
%it is a skin
final_image(i,j) = 1;
end
end
end
end
end
% end %%% added
% figure, imshow(final_image);
% figure()
% imshow(final_image)
BW=im2bw(final_image);
else
BW=im2bw(I);
% figure, imshow(BW);
end
BW3 = bwmorph(BW,'skel',Inf);
% figure, imshow(BW3)
y(:,:,:,t) = BW3;
% figure()
% imshow(BW3)
end
[m, n ,o, p] = size(y);
B = im2bw(zeros(m, n ,o));
for t = 1 : p
I = y(:,:,:,t);
B = B | I;
%figure, imshow(B)
end
numFrames = mov1.NumberOfFrames;
[m, n ,o, p] = size(y);
B1 = im2bw(zeros(m, n ,o));
for t = 1 : numFrames-1
currFrame = read(mov1, t); %reading individual frames
currFrame1 = read(mov1, t+1);
I = abs(currFrame - currFrame1);
II = im2bw(I);
% figure, imshow(I)
B1 = B1 | II;
%figure, imshow(B1)
end
BW3 = bwmorph(B1,'skel',Inf);
B2 = BW3 & B;
BW3 = bwmorph(B2,'skel',Inf);
figure(243), imshow(BW3)
% % I = BW3;
% I = rgb2gray(I);
% [a, b] = size(I);
% I1 = uint8(zeros(a,b));
% flag =0;
%
% for i = 2:1:a-1
% flag = 0;
% for j = 2:1:b-1
% if(I(i, j) > 21 && I(i,j) < 220 )
% if(flag == 0)
% I1(i, j) = 255;
% flag =1;
% end
%
% end
% end
% end
%
% [m, n] = size(I1);
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) == 255)
% b1(x) = i;
% b1(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
% x = 1;
% y = 1;
% for i = 1:1:m
% for j = 1:1:n
% if(I1(i,j) < 255)
% b2(x) = i;
% b2(y) = j;
% end
% x = x+1;
% y = y+1;
% end
% end
%
% plot(b1, 'r-')
% % axis off
% hold on
% plot(b2, 'r-')
%
% for t = 1 : numFrames
Im1 =uint8( bwdist(BW3)) ; %reading individual frames
Im2= uint8(bwdist(BW24)) ;
hn1 = imhist(Im1)./numel(Im1);
hn2 = imhist(Im2)./numel(Im2);
D(itrw) = sum(sqrt(hn1-hn2).^2);
% end
% a = rgb2gray(imread('C:\Data\September\5\s001.png'));
% b = rgb2gray(imread('C:\Data\September\5\s0045.png'));
%
% if(D == 0)
% display('the videos have same frames')
% else
% display('the videos have diff frames')
% end
end
Val=min(abs(D))
for i=1:1:4
if(abs(D(i))==Val)
break
end
end
if(i==1)
disp('Khush');
end
if(i==2)
disp('Dukhi');
end
if(i==3)
disp('Pareshaan');
end
if(i==4)
disp('Gussa');
end
end