Post date: Jul 31, 2016 4:5:17 AM
Take this code in Eigen,
Eigen::VectorXf p(3);
Eigen::VectorXf ptr;
for (int i = 0; i < 10; i++)
{
generate_random_point(p, 3);
if (i == 0)
{
ptr = p;
}
std::cout << "i: " << i << " p: " << std::endl << p << std::endl << std::endl;
}
std::cout << "ptr" << std::endl << ptr << std::endl << std::endl;
Then this code in OpenCV
cv::Mat p(3, 1, CV_32F);
cv::Mat ptr;
for (int i = 0; i < 10; i++)
{
generate_random_point(p, 3);
if (i == 0)
{
ptr = p;
}
std::cout << "i: " << i << " p: " << std::endl << p << std::endl << std::endl;
}
std::cout << "ptr" << std::endl << ptr << std::endl << std::endl;
The output for the Eigen code is
i: 0 p:
9574.87
232.567
1422.92
.
.
.
i: 9 p:
2141.65
366.478
4404.84
ptr
9574.87
232.567
1422.92
but the output for the OpenCV code is
i: 0 p:
[5887.8213;
9288.8535;
9736.665]
'
'
'
i: 9 p:
[5662.7578;
8560.1592;
604.42267]
ptr
[5662.7578;
8560.1592;
604.42267]
As you can see, for Eigen, the matrix ptr stays to the first assignment. Whereas for OpenCV, the matrix ptr is constantly updated to reflect the assignment.
There is an explanation if you think about it but it is kind of hard to get down in words without being targeted as a heretic! So I will let the evidence speak for itself.