File: transformEssentials.m

package info (click to toggle)
opengv 1.0%2B1git91f4b1-7
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,480 kB
  • sloc: cpp: 45,813; python: 152; makefile: 17; xml: 13; sh: 4
file content (53 lines) | stat: -rw-r--r-- 1,491 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
function Rs = transformEssentials(Es)

    temp = size(size(Es));
    numberSolutions = 1;
    if temp(1,2) == 3
        temp2 = size(Es);
        numberSolutions = temp2(1,3);
    end
    
    if numberSolutions == 1
        
        Rs = zeros(3,3,2);
        [U,~,V] = svd(Es);
        W = [0 -1 0; 1 0 0; 0 0 1];
        Rs(1:3,1:3) = U * W * V';
        Rs(1:3,4:6) = U * W' * V';
        
        if( det(Rs(1:3,1:3)) < 0 )
            Rs(1:3,1:3) = -Rs(1:3,1:3);
        end
        if( det(Rs(1:3,4:6)) < 0 )
            Rs(1:3,4:6) = -Rs(1:3,4:6);
        end
        
    else
        
        Rs_temp = zeros(3,3,2*numberSolutions);
        index = 0;
        
        for i=1:numberSolutions
            
            %Check if there is any Nan
            if ~isnan(Es(1,1,i))
                [U,~,V] = svd(Es(:,:,i));
                W = [0 -1 0; 1 0 0; 0 0 1];
                index = index + 1;
                Rs_temp( :,:, index ) = U * W * V';
                if(det(Rs_temp( :,:, index )) < 0)
                    Rs_temp( :,:, index ) = -Rs_temp( :,:, index );
                end
                index = index + 1;
                Rs_temp( :,:, index ) = U * W' * V';
                if(det(Rs_temp( :,:, index )) < 0)
                    Rs_temp( :,:, index ) = -Rs_temp( :,:, index );
                end
            end
        end
        
        Rs = Rs_temp(:,:,1:index);
        
    end
                
end