📄 test.m
字号:
% test program for 'imgProcSilent', colour file: 'testcolors.txt'
function test(varargin)
% Ensure that colour definition file exists
colour_def = 'testcolors.txt'; % don't modify this filename (hard coded in imgProc.dll) -- FW-05-03
cdef = dir(colour_def);
if(isempty(cdef))
error(['The required colour definition file ' colour_def ' could not be found\n']);
else
% determine the number of colours to be scanned for
h = fopen(colour_def);
nCDef = 0;
while(~feof(h))
myline = fgetl(h);
if(strcmpi(myline, '[thresholds]'))
break;
end
if(strcmpi(myline, '[colors]'))
nCDef = 0;
elseif(~strcmp(myline, ''))
nCDef = nCDef + 1;
%disp(['(' num2str(nCDef) ') : ' myline]);
%pause
end
end
fclose(h);
end
% check inputs of function 'test'
if(isempty(varargin))
% check if we're running with live images or not
try
% try to capture a frame...
rgb = capImage(2);
scan4col = [1:nCDef];
catch
% no camera - run of a prerecorded avi movie
fname = 'testimages/testimageYUYVrgb.mat';
disp(['No image file specified; using default ' fname]);
eval(['load ' fname]);
scan4col = [1:nCDef];
end
elseif(nargin == 2) % two input arguments -> file name and colour vector
fname = varargin{1};
eval(['load ' fname]);
scan4col = varargin{2};
else
fname = varargin{1}; % one input argument -> file name
eval(['load ' fname]);
scan4col = [1:nCDef];
end
% % process frame...
% out = imgProcSilent(rgb, colour_def, scan4col);
%
% % display image
% image(rgb);
% axis image;
myImage = rgb(20:200, 50:150, :);
out = imgProcSilent(myImage, colour_def, scan4col);
% display image
image(myImage);
axis image;
% % debug... test
% rr = 255*[1 0 0 0; ...
% 1 0 0 0; ...
% 1 0 0 0];
% gg = 255*[0 1 0 1; ...
% 0 1 0 1; ...
% 0 1 0 1];
% bb = 255*[0 0 1 1; ...
% 0 0 1 1; ...
% 0 0 1 1];
% myImage(:,:,1) = uint8(rr);
% myImage(:,:,2) = uint8(gg);
% myImage(:,:,3) = uint8(bb);
% out = imgProcSilent(myImage, colour_def, scan4col);
%
% figure
% image(myImage)
% axis image
% process frame...
nvr = [out(:).nRegions]; % number of valid regions per colour
if(any(nvr)) % any valid regions at all?
hold on;
for(j = 1:length(nvr))
kk = out(j).nRegions;
col = out(j).Colour;
while(kk)
cx = out(j).Regions(1, kk); % centroid
cy = out(j).Regions(2, kk);
x1 = out(j).Regions(3, kk); % boundary box
y1 = out(j).Regions(4, kk);
x2 = out(j).Regions(5, kk);
y2 = out(j).Regions(6, kk);
ll = plot([x1 x2 x2 x1 x1], [y1 y1 y2 y2 y1]);
set(ll, 'Color', [1 1 1] - col);
ll = plot(cx, cy, 'x');
set(ll, 'Color', [1 1 1] - col);
kk = kk - 1;
end
end
hold off
end
axis ij;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -