source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/image3dstiching/useful/recoverAlphasFromU.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 4.2 KB
Line 
1% *  This code was used in the following articles:
2% *  [1] Learning 3-D Scene Structure from a Single Still Image,
3% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
4% *      In ICCV workshop on 3D Representation for Recognition (3dRR-07), 2007.
5% *      (best paper)
6% *  [2] 3-D Reconstruction from Sparse Views using Monocular Vision,
7% *      Ashutosh Saxena, Min Sun, Andrew Y. Ng,
8% *      In ICCV workshop on Virtual Representations and Modeling
9% *      of Large-scale environments (VRML), 2007.
10% *  [3] 3-D Depth Reconstruction from a Single Still Image,
11% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
12% *      International Journal of Computer Vision (IJCV), Aug 2007.
13% *  [6] Learning Depth from Single Monocular Images,
14% *      Ashutosh Saxena, Sung H. Chung, Andrew Y. Ng.
15% *      In Neural Information Processing Systems (NIPS) 18, 2005.
16% *
17% *  These articles are available at:
18% *  http://make3d.stanford.edu/publications
19% *
20% *  We request that you cite the papers [1], [3] and [6] in any of
21% *  your reports that uses this code.
22% *  Further, if you use the code in image3dstiching/ (multiple image version),
23% *  then please cite [2].
24% * 
25% *  If you use the code in third_party/, then PLEASE CITE and follow the
26% *  LICENSE OF THE CORRESPONDING THIRD PARTY CODE.
27% *
28% *  Finally, this code is for non-commercial use only.  For further
29% *  information and to obtain a copy of the license, see
30% *
31% *  http://make3d.stanford.edu/publications/code
32% *
33% *  Also, the software distributed under the License is distributed on an
34% * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
35% *  express or implied.   See the License for the specific language governing
36% *  permissions and limitations under the License.
37% *
38% */
39function [alphas] = recoverAlphasFromU(R)
40%[alphaOut, alphaUp, alphaRight, q] = recoverAlphas(cameraLoc, cameraAt, cameraUp, gripperOut, gripperUp)
41
42%up, right, out
43
44if size(R,2) == 9       %rotation matrix
45       
46        R = reshape(R, 3,3);
47        displayFlag = 0;
48
49% Calculates the rotation about the three camera vectors: out, up, and right
50
51R = R';  % Makes rotation from image frame to gripper frame.
52
53q       = [(sqrt( max( 0, 1 + R(1,1) + R(2,2) + R(3,3) ) ) / 2);
54           (sqrt( max( 0, 1 + R(1,1) - R(2,2) - R(3,3) ) ) / 2);
55           (sqrt( max( 0, 1 - R(1,1) + R(2,2) - R(3,3) ) ) / 2);
56           (sqrt( max( 0, 1 - R(1,1) - R(2,2) + R(3,3) ) ) / 2)];
57signMat = -1 + 2*(0 <= [1                ;
58                        (R(3,2) - R(2,3));
59                                (R(1,3) - R(3,1));
60                                (R(2,1) - R(1,2))]);
61q = q .* signMat;
62
63test = q(2)*q(3) + q(4)*q(1);
64if (test > 0.499) %% singularity at north pole
65        alphaOut = -2 * atan2(q(2),q(1));
66        alphaUp = -pi/2;
67        alphaRight = 0;
68elseif (test < -0.499) %% singularity at south pole
69        alphaOut = 2 * atan2(q(2),q(1));
70        alphaUp = pi/2;
71        alphaRight = 0;
72else
73        sqx = q(2)*q(2);    sqy = q(3)*q(3);    sqz = q(4)*q(4);
74        alphaRight = -atan2(2*q(3)*q(1)-2*q(2)*q(4) , 1 - 2*sqy - 2*sqz);
75        alphaUp = -asin(2*test);
76        alphaOut = -atan2(2*q(2)*q(1)-2*q(3)*q(4) , 1 - 2*sqx - 2*sqz);
77        alphas = [alphaOut, alphaUp, alphaRight];
78end
79
80elseif size(R,2) == 3
81        alphaOut = acos( R(1));
82        alphaRight = asin(R(2) / sqrt(1-R(1)^2));
83        alphaUp = acos(R(3) / sqrt(1-R(1)^2));
84
85elseif size(R,2) == 1
86        alphaOut = zeros(size(R,1),1);
87        alphaRight = zeros(size(R,1),1);
88        alphaUp = zeros(size(R,1),1);
89
90elseif size(R,2) == 4
91        q = R;
92        test = q(2)*q(3) + q(4)*q(1);
93        if (test > 0.499) %% singularity at north pole
94                alphaOut = -2 * atan2(q(2),q(1));
95                alphaUp = -pi/2;
96                alphaRight = 0;
97        elseif (test < -0.499) %% singularity at south pole
98                alphaOut = 2 * atan2(q(2),q(1));
99                alphaUp = pi/2;
100                alphaRight = 0;
101        else
102                sqx = q(2)*q(2);    sqy = q(3)*q(3);    sqz = q(4)*q(4);
103                alphaRight = -atan2(2*q(3)*q(1)-2*q(2)*q(4) , 1 - 2*sqy - 2*sqz);
104                alphaUp = -asin(2*test);
105                alphaOut = -atan2(2*q(2)*q(1)-2*q(3)*q(4) , 1 - 2*sqx - 2*sqz);
106                alphas = [alphaOut, alphaUp, alphaRight];
107        end
108
109        alphaOut = acos( R(1));
110        alphaRight = asin(R(2) / sqrt(1-R(1)^2));
111        alphaUp = acos(R(3) / sqrt(1-R(1)^2));
112
113end;
114
115alphas = [alphaOut, alphaUp, alphaRight];
116return;
117
118
Note: See TracBrowser for help on using the repository browser.