-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathinit.m
50 lines (39 loc) · 1.94 KB
/
init.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
% Copyright 2011 Ben Pryke.
% This file is part of Ben Pryke's TLD Implementation available under the
% terms of the GNU General Public License as published by the Free Software
% Foundation. This software is provided without warranty of ANY kind.
% Opens a figure displaying a raw camera stream and allows the user to
% define a bounding-box around the object.
% Returns [stream: source video stream,
% bb: bounding box around object [x, y, width, height]
% resolution: dimensions of the video stream]
function [stream, bb, resolution] = init()
% Data source initialisation ==========================================
% Define the source as camera output
stream = videoinput('winvideo', 1, 'YUY2_320x240');
% Set some properties
set(stream, 'ReturnedColorSpace', 'grayscale');
resolution = get(stream, 'VideoResolution');
bands = get(stream, 'NumberOfBands');
sourceHandle = image(zeros(resolution(2), resolution(1), bands));
% Display the raw camera stream in a figure
preview(stream, sourceHandle);
hold on;
% Bounding-box initialisation =========================================
% Display instructions and allow the user to draw a rectangle over the
% object in the figure
msg = 'Draw a box around the object and double-click inside';
instructionsHandle = text(10, 10, msg, 'color', 'y', 'FontWeight', 'bold');
% Wait for user to double-click inside an appropriately sized rectangle
errorMsg = 'Box not large enough!';
bb = zeros(1, 4);
while (bb(3) < 40 || bb(3) >= resolution(1) || bb(4) < 40 || bb(4) >= resolution(2))
rectHandle = imrect;
bb = wait(rectHandle);
delete(rectHandle);
delete(instructionsHandle);
instructionsHandle = text(10, 10, errorMsg, 'color', 'y', 'FontWeight', 'bold');
end
% Remove the instructions from the figure
delete(instructionsHandle);
end