Skip to content

Commit e0f083a

Browse files
committed
hopefully fixed failure in opencv_test_tracking
1 parent 7b7ad1e commit e0f083a

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

modules/tracking/src/twist.cpp

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,53 @@ namespace detail
99
inline namespace tracking
1010
{
1111

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)
1313
{
1414
CV_Assert(uv.cols == depths.cols);
1515
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);
1717

1818
J.create(depths.cols * 2, 6, CV_32F);
1919
J.setTo(0);
2020

21-
cv::Mat Kinv;
22-
cv::invert(K, Kinv);
21+
Matx33f K, Kinv;
22+
K_.copyTo(K);
23+
Kinv = K.inv();
2324

24-
cv::Mat xy(3, 1, CV_32F);
25-
cv::Mat Jp(2, 6, CV_32F);
2625
for (int i = 0; i < uv.cols; i++)
2726
{
2827
const float z = depths.at<float>(i);
2928
// skip points with zero depth
3029
if (cv::abs(z) < 0.001f)
3130
continue;
3231

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);
3433

3534
// 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;
3940

4041
// 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;
5354

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;
5556

5657
// 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)));
5859
}
5960
}
6061

0 commit comments

Comments
 (0)