@@ -9,52 +9,53 @@ namespace detail
9
9
inline namespace tracking
10
10
{
11
11
12
- void computeInteractionMatrix (const cv::Mat& uv, const cv::Mat& depths, const cv::Mat& K , cv::Mat& J)
12
+ void computeInteractionMatrix (const cv::Mat& uv, const cv::Mat& depths, const cv::Mat& K_ , cv::Mat& J)
13
13
{
14
14
CV_Assert (uv.cols == depths.cols );
15
15
CV_Assert (depths.type () == CV_32F);
16
- CV_Assert (K .cols == 3 && K .rows == 3 );
16
+ CV_Assert (K_ .cols == 3 && K_ .rows == 3 && K_. type () == CV_32F );
17
17
18
18
J.create (depths.cols * 2 , 6 , CV_32F);
19
19
J.setTo (0 );
20
20
21
- cv::Mat Kinv;
22
- cv::invert (K, Kinv);
21
+ Matx33f K, Kinv;
22
+ K_.copyTo (K);
23
+ Kinv = K.inv ();
23
24
24
- cv::Mat xy (3 , 1 , CV_32F);
25
- cv::Mat Jp (2 , 6 , CV_32F);
26
25
for (int i = 0 ; i < uv.cols ; i++)
27
26
{
28
27
const float z = depths.at <float >(i);
29
28
// skip points with zero depth
30
29
if (cv::abs (z) < 0 .001f )
31
30
continue ;
32
31
33
- const cv::Point3f p (uv.at <float >(0 , i), uv.at <float >(1 , i), 1.0 );
32
+ const cv::Matx31f p (uv.at <float >(0 , i), uv.at <float >(1 , i), 1.0 );
34
33
35
34
// convert to normalized image-plane coordinates
36
- xy = Kinv * cv::Mat (p);
37
- float x = xy.at <float >(0 );
38
- float y = xy.at <float >(1 );
35
+ Matx31f xy = Kinv * p;
36
+ float x = xy (0 ,0 );
37
+ float y = xy (1 ,0 );
38
+
39
+ Matx<float , 2 , 6 > Jp;
39
40
40
41
// 2x6 Jacobian for this point
41
- Jp. at < float > (0 , 0 ) = -1 / z;
42
- Jp. at < float > (0 , 1 ) = 0.0 ;
43
- Jp. at < float > (0 , 2 ) = x / z;
44
- Jp. at < float > (0 , 3 ) = x * y;
45
- Jp. at < float > (0 , 4 ) = -(1 + x * x);
46
- Jp. at < float > (0 , 5 ) = y;
47
- Jp. at < float > (1 , 0 ) = 0.0 ;
48
- Jp. at < float > (1 , 1 ) = -1 / z;
49
- Jp. at < float > (1 , 2 ) = y / z;
50
- Jp. at < float > (1 , 3 ) = 1 + y * y;
51
- Jp. at < float > (1 , 4 ) = -x * y;
52
- Jp. at < float > (1 , 5 ) = -x;
42
+ Jp (0 , 0 ) = -1 / z;
43
+ Jp (0 , 1 ) = 0.0 ;
44
+ Jp (0 , 2 ) = x / z;
45
+ Jp (0 , 3 ) = x * y;
46
+ Jp (0 , 4 ) = -(1 + x * x);
47
+ Jp (0 , 5 ) = y;
48
+ Jp (1 , 0 ) = 0.0 ;
49
+ Jp (1 , 1 ) = -1 / z;
50
+ Jp (1 , 2 ) = y / z;
51
+ Jp (1 , 3 ) = 1 + y * y;
52
+ Jp (1 , 4 ) = -x * y;
53
+ Jp (1 , 5 ) = -x;
53
54
54
- Jp = K ( cv::Rect ( 0 , 0 , 2 , 2 )) * Jp;
55
+ Jp = Matx22f ( K ( 0 , 0 ), K ( 0 , 1 ), K ( 1 , 0 ), K ( 1 , 1 )) * Jp;
55
56
56
57
// push into Jacobian
57
- Jp .copyTo (J (cv::Rect (0 , 2 * i, 6 , 2 )));
58
+ Mat ( 2 , 6 , CV_32F, Jp. val ) .copyTo (J (cv::Rect (0 , 2 * i, 6 , 2 )));
58
59
}
59
60
}
60
61
0 commit comments