How do you create a panorama with multiple images?
조회 수: 12 (최근 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!