Why does not line appear over plot

조회 수: 9 (최근 30일)
Andrés Méndez
Andrés Méndez 2017년 10월 16일
댓글: OCDER 2017년 10월 17일
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!

답변 (2개)

OCDER
OCDER 2017년 10월 16일
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
Walter Roberson
Walter Roberson 2017년 10월 17일
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 2017년 10월 17일
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

댓글을 달려면 로그인하십시오.


Andrés Méndez
Andrés Méndez 2017년 10월 16일
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!

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by