return 值 "res" 是如何更新的? (ConcativeMat Con NN)
How does the return value "res" is updated? (ConcativeMat Con NN)
我对 for 循环及其 return 值有疑问。这是 C++ 代码,我使用的是 openCV 2.4V。
此函数的输入是 600 张带池化图像的最大值。
600 张图像 << 池化 << 最大值点。
"res" 矩阵的大小为 600x128,vec.size() = 600。
对我来说,在 for 循环中,res 永远不会更新,但是 return 值不为零。
我怀疑
"ptmat.copyTo(subView)"
因为,我认为那不是必要的行。然而,当我把它拿出来时,res 没有得到更新(像初始 Mat 一样为零)。谁能解释一下 res 值是如何更新的?
还有为什么这个函数叫做concatenate..?
Mat
concatenateMat(vector<vector<Mat> > &vec) {
int subFeatures = vec[0][0].rows * vec[0][0].cols;
int height = vec[0].size() * subFeatures;
int width = vec.size();
Mat res = Mat::zeros(height, width, CV_64FC1);
for (int i = 0; i<vec.size(); i++) {
for (int j = 0; j<vec[i].size(); j++) {
Rect roi = Rect(i, j * subFeatures, 1, subFeatures);
Mat subView = res(roi);
Mat ptmat = vec[i][j].reshape(0, subFeatures);
ptmat.copyTo(subView);
}
}
return res;
}
根据OpenCV documentation,Mat::operator() 不会复制矩阵数据,因此循环中对 subView 矩阵对象的任何更改也会反映在 res 矩阵对象中。那就是你提到的行:
ptmat.copyTo(subView);
之所以称为连接,是因为它将 Mat 对象的二维向量连接成一个。
我对 for 循环及其 return 值有疑问。这是 C++ 代码,我使用的是 openCV 2.4V。
此函数的输入是 600 张带池化图像的最大值。 600 张图像 << 池化 << 最大值点。 "res" 矩阵的大小为 600x128,vec.size() = 600。
对我来说,在 for 循环中,res 永远不会更新,但是 return 值不为零。
我怀疑
"ptmat.copyTo(subView)"
因为,我认为那不是必要的行。然而,当我把它拿出来时,res 没有得到更新(像初始 Mat 一样为零)。谁能解释一下 res 值是如何更新的?
还有为什么这个函数叫做concatenate..?
Mat
concatenateMat(vector<vector<Mat> > &vec) {
int subFeatures = vec[0][0].rows * vec[0][0].cols;
int height = vec[0].size() * subFeatures;
int width = vec.size();
Mat res = Mat::zeros(height, width, CV_64FC1);
for (int i = 0; i<vec.size(); i++) {
for (int j = 0; j<vec[i].size(); j++) {
Rect roi = Rect(i, j * subFeatures, 1, subFeatures);
Mat subView = res(roi);
Mat ptmat = vec[i][j].reshape(0, subFeatures);
ptmat.copyTo(subView);
}
}
return res;
}
根据OpenCV documentation,Mat::operator() 不会复制矩阵数据,因此循环中对 subView 矩阵对象的任何更改也会反映在 res 矩阵对象中。那就是你提到的行:
ptmat.copyTo(subView);
之所以称为连接,是因为它将 Mat 对象的二维向量连接成一个。