clc;    % Clear the command window.
clear all;
close all;

workspace;  % Make sure the workspace panel is showing.

format short g;
format compact;
fontSize = 15;
fprintf('Beginning to run %s.m ...\n', mfilename);

imaqhwinfo
info = imaqhwinfo('kinect');
vid = videoinput('kinect',1,'RGB_640x480');

rgbImage = getsnapshot(vid);
subplot(2, 2, 1);
imshow(rgbImage);
axis('on', 'image');
title('Original RGB Image');


vid2 = videoinput('kinect',2,'Depth_640x480');

pause(20)
imgDepth = getsnapshot(vid2);


subplot(2, 2, 2);
imshow(imgDepth, []);
impixelinfo
title('Depth Image');

subplot(2, 2, 3);
histogram(imgDepth);
grid on;
title('Histogram of Depth Image');

% Threshold da imagem
binaryImage = imgDepth > 3500 & imgDepth < 4000;
% Fill holes
binaryImage = imfill(binaryImage, 'holes');
% Take largest blob.
binaryImage = bwareafilt(binaryImage, 1);
subplot(2, 2, 4);
imshow(binaryImage, []);
impixelinfo
title('Binary Image');
% fprintf('Done running %s.m ...\n', mfilename);