How do you create a panorama with multiple images?

32 ビュー (過去 30 日間)
Alexander Walsh
Alexander Walsh 2020 年 3 月 30 日
編集済み: Divya Yerraguntla 2020 年 4 月 2 日
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.

回答 (1 件)

Divya Yerraguntla
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!

カテゴリ

Help Center および File ExchangeRun on Target Hardware についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by