Initialisering

Off[Solve::"ifun"]; Off[InverseFunction::"ifun"];

Kameraoplysninger

(Pleft = {{792.982, 0, 525.823,  0}, {0, 794.305, 395.317, 0}, {0, 
              0, 1, 0}}) // MatrixForm

(Pright = {{791.157,  -0.736741,  
              525.519, -95318.2}, {-0.602951, 794.96, 
              395.32, -396.947}, {-0.00388324, 0.000370433, 0.999992, 
              0.1468}}) // MatrixForm

Cright = (NullSpace[Pright][[1]])

Cleft = (NullSpace[Pleft][[1]])

CrightNorm = (Cright/(Cright[[4]]))

CleftNorm = (Cleft/(Cleft[[4]]))

Decomposition

(M = Pright . {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}, {0, 0, 0}}) // 
      MatrixForm

Det[M]

(Qx = {{1, 0, 0}, {0, Cos[ϕ], -Sin[ϕ]}, {0, 
                Sin[ϕ], Cos[ϕ]}}) // 
        MatrixForm;
(Qy = {{Cos[ϕ], 0, Sin[ϕ]}, {0, 1, 0}, {-Sin[ϕ], 
                0, Cos[ϕ]}}) // 
        MatrixForm;
(Qz = {{Cos[ϕ], -Sin[ϕ], 0}, {Sin[ϕ], 
                Cos[ϕ], 0}, {0, 0, 1}}) // MatrixForm;

(Ax = M . Qx) // MatrixForm;
Solve[
        Ax[[3, 2]] == 0, ϕ];
ϕx = Solve[
          Ax[[3, 2]] == 
            0, ϕ][[1]]
(Qxsolve = Qx /. ϕx) // 
      MatrixForm

    
(Ay = M . Qxsolve . Qy) // 
        MatrixForm;
Solve[
        Ay[[3, 1]] == 0, ϕ];
ϕy = Solve[
          Ay[[3, 1]] == 0, ϕ][[1]]
(Qysolve = Qy /. ϕy) // 
      MatrixForm

    
(Az = M . Qxsolve . Qysolve . Qz) // MatrixForm;
ϕz = Solve[
          Az[[2, 1]] == 0, ϕ][[1]]
(Qzsolve = Qz /. ϕz) // 
      MatrixForm

    
(K = M . Qxsolve . Qysolve . Qzsolve) // 
      MatrixForm

    
(R = Inverse[K] . M) // MatrixForm

    
(M - K . R) // MatrixForm;

Qxsolve . Qysolve . Qzsolve

Epipolar geometri

func[
        a_List] := {{0, -a[[3]], a[[2]]}, {a[[3]], 
          0, -a[[1]]}, {-a[[2]], a[[1]], 0}}

func[{a1, a2, a3}] . {b1, b2, b3} // MatrixForm

Cross[{a1, a2, a3}, {b1, b2, b3}]

Epipole e for left image

epi1norm = ({Pleft . Cright/(Pleft . Cright)[[3]]} // 
          Transpose)

Epipole e'for right image

epi2norm = ({Pright . Cleft/(Pright . Cleft)[[3]]} // 
          Transpose)

Beregning af fundementalmatricen

(Fleft = 
          func[epi2norm // Flatten] . Pright . PseudoInverse[Pleft]) // 
      MatrixForm

Funktioner

Parameterisering af venstre kamera

homogenous2d[
        point2d_List] := {{point2d[[1]], point2d[[2]], 1}}

Xleft[λ_, 
        point2d_List] := (PseudoInverse[Pleft] . 
            Transpose[homogenous2d[point2d]] + λ*
            CleftNorm)

Xleftnorm[λ_, point2d_List] := 
      Xleft[λ, 
          point2d]/(Xleft[λ, point2d][[4, 1]])

Parameterisering af højrekamera

Xright[λ_, 
        point2d_List] := (PseudoInverse[Pright] . 
            Transpose[homogenous2d[point2d]] + λ*
            CrightNorm)

Xrightnorm[λ_, point2d_List] := 
      Xright[λ, 
          point2d]/(Xright[λ, point2d][[4, 
              1]])

Analyse af billeder

Billede 8 (inkl beregning af epipolær geometri)

Koordinateradr

fRedLeft = {596, 332};
fRedRight = {363, 331};

fGreenLeft = {691, 333};
fGreenRight = {466, 332};

fBlueLeft = {637, 245}
fBlueRight = {411, 244};

Beregning  af epipolær geometri

y = y1 + [(y2 - y1) / (x2 - x1)]·(x - x1),

linefunc[P1_, P2_, x_] := 
      P1[[2]] + ((P2[[2]] - P1[[2]])/(P2[[1]] - 
                  P1[[1]]))*(x - P1[[1]])

sol = 
      NullSpace[
        homogenous2d[fBlueLeft] . (Fleft // Transpose)]

v1 = sol[[1]]/sol[[1, 3]]
v2 = sol[[2]]/sol[[2, 3]]

((v2[[2]] - v1[[2]])/(v2[[1]] - 
            v1[[1]]))

Point slope form of the line P(x1 , y1) with slope m is given by  :   y - y1 = m(x - x1)

linefunc[v1, v2, x]
linefunc[v1, v2, x] // Simplify
linefunc[v1, v2, 411]

Rød

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fRedLeft] - 
            Xrightnorm[λ2, 
              fRedRight]], {λ1, λ2}]

(redleft = Xleftnorm[λ1, fRedLeft] /. sol[[2]]) // 
        MatrixForm;
(redright = Xrightnorm[λ2, fRedRight] /. sol[[2]]) // 
        MatrixForm;
(redmean = (redleft + redright)/2) // MatrixForm

Grøn

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fGreenLeft] - 
            Xrightnorm[λ2, 
              fGreenRight]], {λ1, λ2}]

(greenleft = Xleftnorm[λ1, fGreenLeft] /. sol[[2]]) // 
        MatrixForm;
(greenright = 
            Xrightnorm[λ2, fGreenRight] /. sol[[2]]) // 
        MatrixForm;
(greenmean = (greenleft + greenright)/2) // 
      MatrixForm

Blå

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fBlueLeft] - 
            Xrightnorm[λ2, 
              fBlueRight]], {λ1, λ2}]

(blueleft = Xleftnorm[λ1, fBlueLeft] /. sol[[2]]) // 
        MatrixForm;
(blueright = Xrightnorm[λ2, fBlueRight] /. sol[[2]]) // 
        MatrixForm;
(bluemean = (blueleft + blueright)/2) // MatrixForm

Billede 9

Koordinater

fRedLeft = {450, 335};
fRedRight = {205, 333};

fGreenLeft = {555, 336};
fGreenRight = {320, 335};

fBlueLeft = {498, 243};
fBlueRight = {260, 242};

Rød

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fRedLeft] - 
            Xrightnorm[λ2, 
              fRedRight]], {λ1, λ2}]

(redleft = Xleftnorm[λ1, fRedLeft] /. sol[[2]]) // 
        MatrixForm;
(redright = Xrightnorm[λ2, fRedRight] /. sol[[2]]) // 
        MatrixForm;
(redmean = (redleft + redright)/2) // MatrixForm

Grøn

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fGreenLeft] - 
            Xrightnorm[λ2, 
              fGreenRight]], {λ1, λ2}]

(greenleft = Xleftnorm[λ1, fGreenLeft] /. sol[[2]]) // 
        MatrixForm;
(greenright = 
            Xrightnorm[λ2, fGreenRight] /. sol[[2]]) // 
        MatrixForm;
(greenmean = (greenleft + greenright)/2) // 
      MatrixForm

Blå

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fBlueLeft] - 
            Xrightnorm[λ2, 
              fBlueRight]], {λ1, λ2}]

(blueleft = Xleftnorm[λ1, fBlueLeft] /. sol[[2]]) // 
        MatrixForm;
(blueright = Xrightnorm[λ2, fBlueRight] /. sol[[2]]) // 
        MatrixForm;
(bluemean = (blueleft + blueright)/2) // MatrixForm

Billede 10

Koordinater

fRedLeft = {473, 327};
fRedRight = {234, 326};

fGreenLeft = {578, 348};
fGreenRight = {336, 347};

fBlueLeft = {543, 248};
fBlueRight = {307, 246};

Rød

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fRedLeft] - 
            Xrightnorm[λ2, 
              fRedRight]], {λ1, λ2}]

(redleft = Xleftnorm[λ1, fRedLeft] /. sol[[2]]) // 
        MatrixForm;
(redright = Xrightnorm[λ2, fRedRight] /. sol[[2]]) // 
        MatrixForm;
(redmean = (redleft + redright)/2) // MatrixForm

Grøn

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fGreenLeft] - 
            Xrightnorm[λ2, 
              fGreenRight]], {λ1, λ2}]

(greenleft = Xleftnorm[λ1, fGreenLeft] /. sol[[2]]) // 
        MatrixForm;
(greenright = 
            Xrightnorm[λ2, fGreenRight] /. sol[[2]]) // 
        MatrixForm;
(greenmean = (greenleft + greenright)/2) // 
      MatrixForm

Blå

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fBlueLeft] - 
            Xrightnorm[λ2, 
              fBlueRight]], {λ1, λ2}]

(blueleft = Xleftnorm[λ1, fBlueLeft] /. sol[[2]]) // 
        MatrixForm;
(blueright = Xrightnorm[λ2, fBlueRight] /. sol[[2]]) // 
        MatrixForm;
(bluemean = (blueleft + blueright)/2) // MatrixForm

Billede 11

Koordinater

fRedLeft = {418, 294};
fRedRight = {198, 293};

fGreenLeft = {514, 311};
fGreenRight = {292, 311};

fBlueLeft = {482, 220};
fBlueRight = {265, 219};

Rød

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fRedLeft] - 
            Xrightnorm[λ2, 
              fRedRight]], {λ1, λ2}]

(redleft = Xleftnorm[λ1, fRedLeft] /. sol[[2]]) // 
        MatrixForm;
(redright = Xrightnorm[λ2, fRedRight] /. sol[[2]]) // 
        MatrixForm;
(redmean = (redleft + redright)/2) // MatrixForm

Grøn

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fGreenLeft] - 
            Xrightnorm[λ2, 
              fGreenRight]], {λ1, λ2}]

(greenleft = Xleftnorm[λ1, fGreenLeft] /. sol[[2]]) // 
        MatrixForm;
(greenright = 
            Xrightnorm[λ2, fGreenRight] /. sol[[2]]) // 
        MatrixForm;
(greenmean = (greenleft + greenright)/2) // 
      MatrixForm

Blå

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fBlueLeft] - 
            Xrightnorm[λ2, 
              fBlueRight]], {λ1, λ2}]

(blueleft = Xleftnorm[λ1, fBlueLeft] /. sol[[2]]) // 
        MatrixForm;
(blueright = Xrightnorm[λ2, fBlueRight] /. sol[[2]]) // 
        MatrixForm;
(bluemean = (blueleft + blueright)/2) // MatrixForm

Billede 12

Koordinater

fRedLeft = {424, 194};
fRedRight = {182, 191};

fGreenLeft = {485, 283};
fGreenRight = {251, 282};

fBlueLeft = {527, 187};
fBlueRight = {296, 186};

Rød

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fRedLeft] - 
            Xrightnorm[λ2, 
              fRedRight]], {λ1, λ2}]

(redleft = Xleftnorm[λ1, fRedLeft] /. sol[[2]]) // 
        MatrixForm;
(redright = Xrightnorm[λ2, fRedRight] /. sol[[2]]) // 
        MatrixForm;
(redmean = (redleft + redright)/2) // MatrixForm

Grøn

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fGreenLeft] - 
            Xrightnorm[λ2, 
              fGreenRight]], {λ1, λ2}]

(greenleft = Xleftnorm[λ1, fGreenLeft] /. sol[[2]]) // 
        MatrixForm;
(greenright = 
            Xrightnorm[λ2, fGreenRight] /. sol[[2]]) // 
        MatrixForm;
(greenmean = (greenleft + greenright)/2) // 
      MatrixForm

Blå

sol = 
      NMinimize[
        Norm[Xleftnorm[λ1, fBlueLeft] - 
            Xrightnorm[λ2, 
              fBlueRight]], {λ1, λ2}]

(blueleft = Xleftnorm[λ1, fBlueLeft] /. sol[[2]]) // 
        MatrixForm;
(blueright = Xrightnorm[λ2, fBlueRight] /. sol[[2]]) // 
        MatrixForm;
(bluemean = (blueleft + blueright)/2) // MatrixForm