Specify maximum number of sides in impoly

1 visualizzazione (ultimi 30 giorni)
Gee
Gee il 8 Giu 2016
I'm trying to draw a polygon on a figure with a maximum of 4 sides per polygon, but I'm not sure how to limit the number of sides a polygon can be. Also, if the user draws 4 lines but the 4th doesn't connect to the beginning of the 1st line, is it possible to automatically connect the two lines? Does anyone know how these two things could be done?
This is what I've got so far:
vidObj = VideoReader('final1.mp4');
vidHeight = vidObj.Height;
vidWidth = vidObj.Width;
s = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]);
k = 1;
while hasFrame(vidObj)
s(k).cdata = readFrame(vidObj);
k = k+1;
end
% select ROI
figure('Name','Please Click to Select ROI');
imshow(s(1).cdata)
l = 1;
numBoxes = 4;
h = zeros(4,2,numBoxes);
pos = zeros(4,2,l);
C = {'b','r','g','y'}; % Cell array of colros.
while l <= numBoxes
api = iptgetapi(h(:,:,l));
api.setColor(C(l));
api.addNewPositionCallback(@(p) title(['Draw ROI for box ' l]));
h(l) = impoly();
pos(:,:,l) = ceil(getPosition(h(l)));
l = l + 1;
end

Risposte (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by