Why does not line appear over plot
조회 수: 9 (최근 30일)
이전 댓글 표시
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!
댓글 수: 0
답변 (2개)
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
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
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
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!