Monday, October 2, 2017

Structure from Motion using video from my phone camera

Introduction. In my last post, I showed how I had extracted frames from satellite-derived video to build a 3D model of a mine from space. In this post, I show a similar workflow for phone camera: take a video of an object (some times a lot easier than numerous frames although lower quality) and make a 3D model using Agisoft Photoscan.

Video to images. (this part is repeated from the last post). The main generic challenge for SfM from video is to extract the video frames and prepare them for the SfM. The SfM part is no different from what my group has been doing for a while with Agisoft Photoscan. I used MATLAB to do the video processing. The script is here: readplanetvid.m. The main code bits include:
PlanetObj = VideoReader(videoname); %make a video object from an MP4 file
vidWidth = PlanetObj.Width; %get the width
vidHeight = PlanetObj.Height; %and height

mov = struct('cdata',zeros(vidHeight,vidWidth,3,'uint8'),...
'colormap',[]); %set up a MATLAB structure to contain the video

k = 1;
while hasFrame(PlanetObj)
mov(k).cdata = readFrame(PlanetObj); %pull out the frames one at a time from the MP4 object and put them in the mov
k = k+1;
end

step = floor(k/number_of_frames) %determine how many frames to skip each time to get the desired number
for i = 1:step:(k-1)
framepart = sprintf('_frame_%06d.png', i);
filename = strcat(foldername,'/',projectname,framepart);
imwrite(mov(i).cdata, filename) %easy to write the frame out as a png file
end

Video of a rock sample in my backyard. I took a short video of a piece of obsidian on a table with my Samsung J3. The nice thing about it was that I could gather a large number of views around the sample with relative ease. From that video, I extracted 150 frames, for example see below



I ran the files through the Agisoft Photoscan sequence of alignment (high), build dense cloud (medium), build mesh (medium), and build texture (medium). Here are a few screen captures of the result:

This one shows a somewhat complex background, but nicely indicates the path of the camera too.

And here it is with a trim to only show the sample on the table:

1 comment:

  1. Assalamualaikum wrb,saya Rahman saputrah, niat saya hanya ingin berbagi kebaikan khusus kepada orang yang mengalami kesusahan,percaya tidak percaya semua kembali pada pembaca postingan saya, awalnya saya seorang pengusaha yang bisa dibilang sukses, tapi banyak yang tidak suka kalau saya sukses,dan akhirnya bisnis saya bangkrut dan saya sempat jadi Pengangguran kurang lebih 1tahun saya punya anak 3 dan masih kecil2,saya sempat putus asa dan tidak tau mau berbuat apa, tapi setiap saya melihat anak saya, Saya merasa kasian, dan kemarin tampa disengaja ada Teman saya memberi saran dia menyarangkan saya untuk menghubungi Mbah jonoseuh, beliau memberikan bantuan Pesugihan, awalnya sih saya ragu tapi mau nggak mau saya beranikan diri mencoba bantuan dari Mbah jonoseuh. syukur Alhamdulillah dengan bantuan pesugihan beliau saya sekarang sukses kembali dan saya bisa biayai sekolah anak saya sampai selesai,terimah kasih Mbah berkat Mbah saya bisa sukses kembali,ini pengalaman pribadi saya khusus bagi teman2 yang sempat baca dan punya masalah silahkan hub Mbah jonoseuh di nomor 082344445588 dan pasti beliau bisa meringankan semuah permasalahan yang anda hadapi untuk saat ini, Dan terimah kasih kepada yang punya room ini karna saya sempat berbagi pengalaman dan mudah2han bisa membantu,

    ReplyDelete