## "Fossies" - the Fresh Open Source Software Archive

### Member "sip-0.12.1/macros/KRC_from_P.sci" (31 Oct 2015, 1858 Bytes) of package /linux/privat/sip-0.12.1.tar.gz:

As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Scilab source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "KRC_from_P.sci": 0.5.6_vs_0.12.1.

1 function [K, R, C] = KRC_from_P(P, noscale)
2 //
3 // Decompose a 3x4 camera matrix P into intrinsic parameters K, rotation R, and
4 // center of projection C.
5 //
6 // AUTHOR
7 //    Ricardo Fabbri  <rfabbri@(not this part) gmail d0t com>
8 //
9 // REFERENCE
10 //    Oxford's Visual geometry group matlab toolbox
11 //
12 // \$Revision: 1.1 \$ \$Date: 2010-10-09 14:46:33 \$
13 //
14
15 N = size(P,1);
16 H = P(:,1:N);
17
18 [K,R] = sip_rq(H);
19
20 if argn(2) < 2
21   K = K / K(N,N);
22 //  if K(1,1) < 0
23 //    D = diag([-1 -1 ones(1,N-2)]);
24 //    K = K * D;
25 //    R = D * R;
26
27 //    test = K*R;
28 //    vgg_assert0(test/test(1,1) - H/H(1,1), 1e-07)
29 //  end
30   // from http://ksimek.github.io/2012/08/14/decompose/
31   // make diagonal of K positive
32   sg = diag(sign(diag(K)));
33
34   K = K * sg;
35   R = sg * R;
36   // det(R) negative, just invert - the proj equation remains same:
37   R = -R
38 end
39
40
41
42 if argn(1) > 2
43   C = -P(:,1:N)\P(:,\$);
44 end
45 endfunction
46 //
47 // -------------------------------------------------------------------------
48 // SIP - Scilab Image Processing toolbox
49 // Copyright (C) 2002-2010  Ricardo Fabbri
50 //
51 // This program is free software; you can redistribute it and/or modify
52 // it under the terms of the GNU General Public License as published by
53 // the Free Software Foundation; either version 2 of the License, or
54 // (at your option) any later version.
55 //
56 // This program is distributed in the hope that it will be useful,
57 // but WITHOUT ANY WARRANTY; without even the implied warranty of
58 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
59 // GNU General Public License for more details.
60 //
61 // You should have received a copy of the GNU General Public License
62 // along with this program; if not, write to the Free Software
63 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
64 // -------------------------------------------------------------------------
65 //