How do you create a panorama with multiple images?
33 次查看(过去 30 天)
显示 更早的评论
I have a script that is connected to a raspberry pi with pan/tilt servos on a webcam. I am attempting to create a panorama by taking images and using the subplot command, but there is the blank space between the images.
function takePano(rpi, s1, s2)
%rpi is a raspberry pi, and s1/s2 are servos.
index=0;
for ii=0:2
for jj=0:2
%These 2 lines move the camera to the correct orientation.
writePosition(s1, 180-(90*jj))
writePosition(s2, 90*ii)
pause(0.5)
%These 2 lines take the picture and transfer it to my computer.
system(rpi, 'fswebcam -r 1920x1080 --no-banner pano_rpi.png')
getFile(rpi, '/home/pi/pano_rpi.png')
index=index+1;
%This line creates the pano one image at a time (per iteration).
subplot(3,3,index), imshow('pano_rpi.png')
disp(index)
end
end
%These 2 lines zero the camera position after it is done.
writePosition(s1, 90)
writePosition(s2, 90)
end
Is there a way to eliminate this blank space or a better way to do this?
NOTE: every time the raspberry pi takes a new picture it over-writes the previous one using the same file name.
0 个评论
回答(1 个)
Divya Yerraguntla
2020-4-2
编辑:Divya Yerraguntla
2020-4-2
Hi Alexander,
You could use the imread and montage functions from Image Processing Toolbox to accomplish your task instead of using subplots. Have a look at a modified version of your code below:
function takePano(rpi, s1, s2)
%rpi is a raspberry pi, and s1/s2 are servos.
index=0;
for ii=0:2
for jj=0:2
%These 2 lines move the camera to the correct orientation.
writePosition(s1, 180-(90*jj))
writePosition(s2, 90*ii)
pause(0.5)
%These 2 lines take the picture and transfer it to my computer.
system(rpi, 'fswebcam -r 1920x1080 --no-banner pano_rpi.png')
getFile(rpi, '/home/pi/pano_rpi.png')
index=index+1;
allimages(:,:,:,index) = imread('pano_rpi.png') % All the images are written to
% variable allimages by the end of the loop
imshow('pano_rpi.png')
disp(index)
end
end
montage(allimages); % displays all your images without space
%These 2 lines zero the camera position after it is done.
writePosition(s1, 90)
writePosition(s2, 90)
end
Hope it helps!
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Run on Target Hardware 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!