-
大小: 73.02MB文件類(lèi)型: .rar金幣: 1下載: 0 次發(fā)布日期: 2023-06-21
- 語(yǔ)言: Matlab
- 標(biāo)簽: 三維重建??sfm??matlab??3Dreconstruc??
資源簡(jiǎn)介
這是我參考matlab案例庫(kù)編寫(xiě)的三維重建代碼,跳過(guò)稀疏重建,添加了顏色,有注釋?zhuān)軐?shí)現(xiàn)較為稠密的三維點(diǎn)云。附帶圖片。新手可以下載來(lái)看看。
代碼片段和文件信息
%%?sfm
%讀取圖像
clc;
clear?all;
imageDir?=?fullfile(‘D:‘‘picture‘‘hezi01‘);
imds?=?imageDatastore(imageDir);
load(‘calibrationSession‘);
cameraParams?=?calibrationSession.CameraParameters;
%%?創(chuàng)建圖像和追蹤
%?創(chuàng)建第一幅圖像
images?=?cell(1?numel(imds.Files));
for?i?=?1:numel(imds.Files)?%?圖片的數(shù)量
????I?=?readimage(imds?i);
????images{i}?=?rgb2gray(I);?
end
%%?稠密重建
%?遍歷圖像,在所有視圖中檢測(cè)一組密集點(diǎn)
I?=?images{1};
prevPoints?=?detectMinEigenFeatures(I?‘MinQuality‘?0.001‘FilterSize‘?3);
%?prevPoints?=?detectSURFFeatures(I‘MetricThreshold‘5‘NumScaleLevels‘6);
%?prevPoints?=?detectKAZEFeatures(I‘Diffusion‘‘region‘‘Threshold‘...
%?0.00001‘NumOctaves‘4‘NumScaleLevels‘5);
%?創(chuàng)建點(diǎn)跟蹤器對(duì)象來(lái)跟蹤視圖中的點(diǎn)。
tracker?=?vision.PointTracker(‘MaxBidirectionalError‘?1?‘NumPyramidLevels‘...
6‘BlockSize‘[3131]);
%?初始化點(diǎn)跟蹤器。
PrevPoints?=?prevPoints.Location;
initialize(tracker?PrevPoints?I);
I1?=?readimage(imds?1);%?讀取第1張圖片
I2?=?images{2};?%?用于后面顏色
[currPoints?validIdx]?=?step(tracker?I2);
matchedPoints?=?PrevPoints(validIdx?:);
%?將密集點(diǎn)存儲(chǔ)在視圖集中。
vSet?=?viewSet;
viewId?=?1;
vSet?=?addView(vSet?viewId?‘Points‘?prevPoints?‘Orientation‘?...
????eye(3?‘like‘?PrevPoints)?‘Location‘?...
????zeros(1?3?‘like‘?PrevPoints));
%?跟蹤所有視圖的要點(diǎn)
for?i?=?2:numel(images)
????%?Read?and?undistort?the?current?image.
????I?=?images{i};
????
????[currPoints?validIdx]?=?step(tracker?I);
????
????matchedPoints1?=?PrevPoints(validIdx?:);
????matchedPoints2?=?currPoints(validIdx?:);
????
????[E?epipolarInliers]?=?estimateEssentialMatrix(matchedPoints1...
????matchedPoints2cameraParams);
????%警告:已達(dá)到最大審判次數(shù)。考慮增加最大距離或降低期望的信心。
????inlierPoints1?=?matchedPoints1(epipolarInliers?:);
????inlierPoints2?=?matchedPoints2(epipolarInliers?:);
????
????[orient?loc]?=?relativeCameraPose(E?cameraParams...?
????inlierPoints1inlierPoints2);
????
????%?將當(dāng)前視圖匹配添加到視圖集
????vSet?=?addView(vSet?i?‘Points‘?currPoints);
????%?存儲(chǔ)上一個(gè)視圖和當(dāng)前視圖之間的點(diǎn)匹配。
????
????matches?=?repmat((1:size(PrevPoints?1))‘?[1?2]);
????matches?=?matches(validIdx?:);?
????vSet?=?addConnection(vSet?i-1?i?‘Matches‘matches);
????%?因?yàn)閮?chǔ)存的點(diǎn)為PrevPoints和currPoints,要變成?matchedPoints1,2的對(duì)應(yīng)關(guān)系。
????%?獲取包含前一個(gè)相機(jī)姿勢(shì)的表。
????prevPose?=?poses(vSet?i-1);
????prevOrientation?=?prevPose.Orientation{1};
????prevLocation?=?prevPose.Location{1};
????%?計(jì)算當(dāng)前相機(jī)在全局坐標(biāo)系中相對(duì)于第一個(gè)視圖的姿態(tài)。
????orientation?=?orient?*?prevOrientation;
????location????=?prevLocation?+?loc?*?prevOrientation;
????vSet?=?updateView(vSet?i?‘Orientation‘?orientation?‘Location‘?location);
????%?在所有視圖中查找軌跡
????tracks?=?findTracks(vSet);
????%?得到所有視角的相機(jī)姿態(tài)表
????camPoses?=?poses(vSet);
????
????%?確定三維世界點(diǎn)的初始位置。
????xyzPoints?=?triangulateMultiview(tracks?camPoses?cameraParams);
?????
????%?改進(jìn)三維世界點(diǎn)和相機(jī)的姿勢(shì).(光束平差法)
????[xyzPoints?camPoses?reprojectionerrors]?=?bundleAdjustment(xyzPoints?...
????????tracks?camPoses?cameraParams?‘FixedViewId‘?1?...
????????‘PointsUndistorted‘?true);
????%?保存
?屬性????????????大小?????日期????時(shí)間???名稱(chēng)
-----------?---------??----------?-----??----
?????文件????4717878??2018-11-21?10:51??box\IMG_20181119_130658.jpg
?????文件????4846307??2018-11-21?10:52??box\IMG_20181119_130659.jpg
?????文件????4793150??2018-11-21?10:51??box\IMG_20181119_130703.jpg
?????文件????4631615??2018-11-21?10:51??box\IMG_20181119_130706.jpg
?????文件????4574597??2018-11-21?10:51??box\IMG_20181119_130708.jpg
?????文件????4791546??2018-11-21?10:51??box\IMG_20181119_130711.jpg
?????文件????4426695??2018-11-21?10:51??box\IMG_20181119_130712.jpg
?????文件????4790101??2018-11-21?10:51??box\IMG_20181119_130714.jpg
?????文件????4677665??2018-11-21?10:51??box\IMG_20181119_130716.jpg
?????文件????4849614??2018-11-21?10:51??box\IMG_20181119_130720.jpg
?????文件????5214150??2018-11-21?10:51??box\IMG_20181119_130722.jpg
?????文件????5156172??2018-11-21?10:51??box\IMG_20181119_130724.jpg
?????文件????4804266??2018-11-21?10:51??box\IMG_20181119_130726.jpg
?????文件????4802396??2018-11-21?10:51??box\IMG_20181119_130728.jpg
?????文件????4868926??2018-11-21?10:51??box\IMG_20181119_130730.jpg
?????文件????4953662??2018-11-21?10:51??box\IMG_20181119_130732.jpg
?????文件???????4304??2018-12-08?13:00??sfm_ex3.m
?????目錄??????????0??2018-11-30?10:36??box
-----------?---------??----------?-----??----
?????????????76903044????????????????????18
評(píng)論
共有 條評(píng)論