Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

https://doi.org/10.5201/ipol.2019.248
27 December 2020, 17:01:59 UTC
  • Code
  • Branches (1)
  • Releases (0)
  • Visits
    • Branches
    • Releases
    • HEAD
    • 7f5192441640a25324f222b6a645fd78a34d2526
    No releases to show
  • 1c5ff6b
  • /
  • orthoPose_1.0
  • /
  • mainPoseEstimation.m
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
  • revision
  • snapshot
origin badgecontent badge
swh:1:cnt:d682bac0e65ccfa566dac10e3ad84881c883a84e
origin badgedirectory badge
swh:1:dir:3721c3d9cff046076f23cfd48ae7998c36ec5dbf
origin badgerevision badge
swh:1:rev:7f5192441640a25324f222b6a645fd78a34d2526
origin badgesnapshot badge
swh:1:snp:005e9571a84f7af1f965d2734db3d4b25ea21904

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
  • revision
  • snapshot
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
Tip revision: 7f5192441640a25324f222b6a645fd78a34d2526 authored by Software Heritage on 01 July 2019, 00:00:00 UTC
ipol: Deposit 1351 in collection ipol
Tip revision: 7f51924
mainPoseEstimation.m
% SPDX-License-Identifier: GPL-3.0-or-later
% Copyright (c) 2017 Laura F. Julia <laura.fernandez-julia@enpc.fr>

function mainPoseEstimation(focal)
% focal must be the focal length in pixels of the camera.

im_path='data/';
image_names={'input_0.png','input_1.png','input_2.png'};
corresp_files={'01.txt','12.txt','02.txt'};

info=imfinfo(strcat(im_path,image_names{1}));
imsize=[info.Width;info.Height];
if ~isa(focal,'double')
    focal=str2double(focal);
end
CalM=repmat([focal,0,imsize(1)/2;0,focal,imsize(2)/2;0,0,1],3,1);

%% Read matches from files %%%

% read matches between image 1 and image 2
dataFile = fopen(strcat(im_path,corresp_files{1}),'r');
corresp12 = fscanf(dataFile,'%f');
fclose(dataFile);
corresp12=reshape(corresp12,4,[]);

% read matches between image 2 and image 3
dataFile = fopen(strcat(im_path,corresp_files{2}),'r');
corresp23 = fscanf(dataFile,'%f');
fclose(dataFile);
corresp23=reshape(corresp23,4,[]);

% read matches between image 1 and image 3 (optional)
dataFile = fopen(strcat(im_path,corresp_files{3}),'r');
corresp13 = fscanf(dataFile,'%f');
fclose(dataFile);
corresp13=reshape(corresp13,4,[]);


%% Compute tracks %%%
Corresp=matches2triplets(corresp12,corresp23,corresp13);
fprintf('%d tracks between the three images.\n',size(Corresp,2));


%% A C RANSAC with Orthographic model %%%
[inliers,Sol,ransac_th]=AC_RANSAC_Orthographic(Corresp,CalM,imsize);
fprintf('%d inliers were found by AC-RANSAC.\n',length(inliers));

%% Orthographic model with all inliers %%%
[Sol1,Sol2]=OrthographicPoseEstimation(Corresp(:,inliers),CalM);

%% B A for both possible solutions %%%
R_t_0=[Sol1{1},Sol1{2}]; Reconst0=Sol1{3};
[R_t_1,Reconst1,iter1,repr_err1]=BundleAdjustment(CalM,R_t_0,Corresp(:,inliers),Reconst0);
fprintf('Minimum reached for first solution with %d iterations. ',iter1);
fprintf('Final reprojection error is %f.\n',repr_err1);

R_t_0=[Sol2{1},Sol2{2}]; Reconst0=Sol2{3};
[R_t_2,Reconst2,iter2,repr_err2]=BundleAdjustment(CalM,R_t_0,Corresp(:,inliers),Reconst0);
fprintf('Minimum reached for second solution with %d iterations. ',iter2);
fprintf('Final reprojection error is %f.\n',repr_err2);

%% Choose solution with less repr. err. %%%
if repr_err1<repr_err2
    Solution=R_t_1;
    Reconst=Reconst1;
else
    Solution=R_t_2;
    Reconst=Reconst2;
end

%% Orientations %%%
R2=Solution(4:6,1:3); t2=Solution(4:6,4);
R3=Solution(7:9,1:3); t3=Solution(7:9,4);


%% PLY file %%%
Color=paintReconstruction(Corresp(1:2,:),strcat(im_path,image_names{1}));
writePLYreconstruction('data/reconstruction.ply',CalM,Solution,Reconst,Color);
writeOrientations('data/orientations.txt',Solution);
dlmwrite('data/tracks.txt',Corresp.','delimiter',' ');
dlmwrite('data/inliers.txt',Corresp(:,inliers).','delimiter',' ');

outnames={'output_0.png','output_1.png','output_2.png'};
for i=1:3
    image=imread(strcat(im_path,image_names{i}));
    co = Corresp(2*i-1:2*i,:)';
    in = Corresp(2*i-1:2*i,inliers)';
    if exist('OCTAVE_VERSION', 'builtin')
        out = drawCircles(image,co,[255 0 0]);
        out = drawCircles(out,in,[0 255 0]);
    else
        out=insertMarker(image,co,'o','color','red');
        out=insertMarker(out,in,'o','color','green');
    end
    imwrite(out,strcat(im_path,outnames{i}));
end

end

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API