Why does not line appear over plot

9 Ansichten (letzte 30 Tage)
Andrés Méndez
Andrés Méndez am 16 Okt. 2017
Kommentiert: OCDER am 17 Okt. 2017
I am trying to draw a skeleton over an RGB image. pos2D is a cell which holds the x,y coordinates of the body.
for w= 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
c.im = imshow(color,[]);
%set(c.im,'CData',color);
skeleton = pos2D{1,w};
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
line(X1,Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
end
Outside the loop it works perfecty, i.e. if i change the w index by hand and do step by step, the line appears. However, when I do these nested loops it does not work. It only appears in the last frame before closing the loop. I tried hold on and off several times. What am I missing?
Thanks!

Antworten (2)

OCDER
OCDER am 16 Okt. 2017
Using imshow will replace the current axes and everything drawn on that axes, including the lines. To fix, use imshow once and then change CData of that image handle. This way, your lines are not deleted.
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1
c.im = imshow(color, []);
else
c.im.CData = color;
end
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
line(X1,Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
end
  3 Kommentare
Walter Roberson
Walter Roberson am 17 Okt. 2017
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1
c.im = imshow(color, []);
c.lh = line(nan, nan, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+' 'Color', 'r');
else
c.im.CData = color;
end
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
set(c.lh, 'XData', X1, 'YData', Y1);
drawnow()
end
end
OCDER
OCDER am 17 Okt. 2017
Hi Andrés, Walter answered your next question. What you want to do is the first loop w = 1, do imshow and draw your 19 lines. In all other loop w > 1, adjust the data in imshow and line.
for w = 1:10
color = imresize(Foto(:,:,w),COL_SCALE);
skeleton = pos2D{1,w};
if w == 1 %First time, make image and 19 lines
c.im = imshow(color, []);
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
c.lh(m) = line(X1, Y1, 'LineWidth', 1.5, 'LineStyle', '-', 'Marker', '+', 'Color', 'r');
end
else %All other times, adjust image and 19 lines position
c.im.CData = color;
for m = 1:19
X1 = [skeleton(SkeletonConnectionMap(m,1),1) skeleton(SkeletonConnectionMap(m,2),1)];
Y1 = [skeleton(SkeletonConnectionMap(m,1),2) skeleton(SkeletonConnectionMap(m,2),2)];
set(c.lh(m), 'XData', X1, 'YData', Y1);
drawnow()
end
end
end

Melden Sie sich an, um zu kommentieren.


Andrés Méndez
Andrés Méndez am 16 Okt. 2017
Donald,
There seems to be something about timing. If I do the CData, i just get a final black background with all the skeleton on top, no video with RGB sequence...
Things change if i put a pause(0.01) in the loop Then I see the image sequence with the skeleton drawn on top (why is this?)...however, the skeleton appears and disappears with the imshow...if I do what you suggest (c.im.CData) i can see the image sequence but the skeleton do not disappear and add one on top of each other. how do i erase the skeleton to update it with the next?
Thanks!

Kategorien

Mehr zu Loops and Conditional Statements finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by