how to show images at a point in a plot?

조회 수: 5 (최근 30일)
Bradley
Bradley 2025년 1월 14일
댓글: Adam Danz 2025년 1월 14일
I have an autonomous vehicle with a camera that follows a predetermined path. Ive already found a way to save each frame of the video and figure out which lat and long each frame belongs to, what im having trouble with is plotting the images in a for loop. I feel like im close, below is my code:
P = uigetdir('C:\');
S1 = dir(fullfile(P,'*.png'));
n_frame = numel(S1);
LatSize = size(Lat1, 1);
LongSize = size(Long1, 1);
FrameCount = LatSize/n_frame;
Lat = Lat1(1:FrameCount:end);
Long = Long1(1:FrameCount:end);
for i = 1:n_frame
F2 = fullfile(S1(i).name);
I{i} = imread(F2(i));
plot(Long, Lat)
axes('Position', [Long(i,:) Lat(i,:) .5 .3])
imshow(I)
end
What am I missing here? I get this error when I run the code:
Unable to find file "F"
The various frames of the video are labeled Frame 0001.png, Frame 0002.png and so, there are 739 frames of the video and I want to plot each frame at the point they were recorded. My ultimate goal is to make it so you can click the plot and the picture will appear but ill deal with that part later. Any help is appreciated, thanks!

답변 (2개)

Walter Roberson
Walter Roberson 2025년 1월 14일
F2 = fullfile(S1(i).folder, S1(i).name);
I{i} = imread(F2);
Also you will probably want a pause() in the display loop. Graphics only updates when you have pause() or drawnow() or uiwait() or waitfor() or figure() or keyboard()
  댓글 수: 2
Bradley
Bradley 2025년 1월 14일
Thanks for this response! I understand why I wouldnt want that (i) after imread, it seems obvious now. However I got a different error:
Expected input number 1, I, to be one of these types:
double, single, uint8, uint16, uint32, uint64, int8, int16, int32, int64, logical
Instead its type was cell.
Would converting the image to a type double solve this issue? Its a regular .png and when I plot all of this for one image without the for loop I dont get this error. Thanks again for the help!
Adam Danz
Adam Danz 2025년 1월 14일
Try imshow(I{i})

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


KALYAN ACHARJYA
KALYAN ACHARJYA 2025년 1월 14일
편집: KALYAN ACHARJYA 2025년 1월 14일
1.This one?
I{i} = imread(F2(i));
Correct:
I{i} = imread(F2);
2. For Better Visualization
plot(Long,Lat,'r-', 'LineWidth', 3);

카테고리

Help CenterFile Exchange에서 Convert Image Type에 대해 자세히 알아보기

태그

제품


릴리스

R2024b

Community Treasure Hunt

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

Start Hunting!

Translated by