Updated by Marina Kolpakova almost 13 years ago
I have the following code that performs a column assignment to a matrix, but does not work as expected
<pre><code class="cpp">
#include <iostream>
#include <opencv2/core/core.hpp>
using namespace std;
int main()
{
cv::Mat X = cv::Mat::zeros(3,4,CV_64F);
cv::Mat A = cv::Mat::ones(3,1,CV_64F);
// This does not work as expected
X(cv::Range::all(), cv::Range(3,4)) = A;
cout << X << endl;
cout << endl;
// This works, but why?
X(cv::Range::all(), cv::Range(3,4)) = A*1;
cout << X << endl;
return 0;
}
</code></pre>
The output is:
[0, 0, 0, 0;
0, 0, 0, 0;
0, 0, 0, 0]
[0, 0, 0, 1;
0, 0, 0, 1;
0, 0, 0, 1]
<pre><code class="cpp">
#include <iostream>
#include <opencv2/core/core.hpp>
using namespace std;
int main()
{
cv::Mat X = cv::Mat::zeros(3,4,CV_64F);
cv::Mat A = cv::Mat::ones(3,1,CV_64F);
// This does not work as expected
X(cv::Range::all(), cv::Range(3,4)) = A;
cout << X << endl;
cout << endl;
// This works, but why?
X(cv::Range::all(), cv::Range(3,4)) = A*1;
cout << X << endl;
return 0;
}
</code></pre>
The output is:
[0, 0, 0, 0;
0, 0, 0, 0;
0, 0, 0, 0]
[0, 0, 0, 1;
0, 0, 0, 1;
0, 0, 0, 1]