forked from jrterven/Kin2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideoDemoCollector.m
51 lines (43 loc) · 1.67 KB
/
videoDemoCollector.m
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
% VIDEODEMOCOLLECTOR Illustrates how to use the Kin2Collector class which
% is an interface for Kinect2 SDK functionality
%
% This is a rewrite of Juan's videoDemo.m to demonstrate usage of
% Kin2Collector features.
%
% Mark Tomaszewski, [email protected]
%
% Adapted from original authors:
% Juan R. Terven, [email protected]
% Diana M. Cordova, [email protected]
%
% Citation:
% J. R. Terven, D. M. Cordova, "A Kinect 2 Toolbox for MATLAB",
% https://github.com/jrterven/Kin2, 2016.
%
function videoDemoCollector()
addpath('Mex'); clear all; close all;
% Create Kin2Collector object and initialize it
k2 = Kin2Collector('color','depth','infrared');
k2.pollData(); % populates relevant <data> properties
% initialize figure with three subplots
figure('CloseRequestFcn',@(src,evt)closeRequestFcn(src,evt,k2))
subplot(2,2,[1,2]); handles.hcolor = imshow(k2.color,[]); title('Color Source');
subplot(2,2,3); handles.hdepth = imshow(k2.depth,[0 4000]); title('Depth Source'); colormap('cool'); colorbar;
subplot(2,2,4); handles.hinfrared = imshow(k2.infrared); title('Infrared Source');
% Register callback with Kin2Collecter
k2.newDataCallback = @(src,evt)updateFigure(src,evt,handles);
k2.startStreaming(); % let her rip!
end
function updateFigure(src,~,handles)
% updateFigure Called every time there's new data in Kin2Collector
set(handles.hdepth ,'CData',src.depth);
set(handles.hcolor ,'CData',src.color);
set(handles.hinfrared,'CData',imadjust(src.infrared,[],[],0.5));
drawnow; % need to flush graphics queue or it just locks up
end
function closeRequestFcn(src,~,k2)
% called when figure window is closed
k2.stopStreaming();
k2.delete();
delete(src);
end