主函数里声明一个变量
vector<vector<cv::Mat>> map(bottom[0]->num(), vector<cv::Mat>(bottom[0]->channels(), cv::Mat(bottom[0]->height(), bottom[0]->width(), CV_32S, cv::Scalar(0))));
BlobToMat(*bottom[0], map);
template <typename Dtype>
void BlobToMat(const Blob<Dtype>& blob, vector<vector<cv::Mat>>& map) {
CHECK_EQ(blob.num(),1)<<"Phase:TEST, batch_size should be 1.";
const int batch_size = blob.num();
const int channel = blob.channels();
const int height = blob.height();
const int width = blob.width();
for(int i=0; i<batch_size; ++i)
for(int j=0; j<channel; ++j)
for(int m=0; m<height; ++m)
for(int n=0; n<width; ++n) {
map[i][j].at<int>(m,n) = (int)(blob.cpu_data()[((i*channel+j)*height+m)*width+n]);
}
for(int i=0; i<batch_size; ++i)
for(int j=0; j<channel; ++j) {
cv::imshow("test", map[i][j]*255*255);
cv::waitKey(0);
}
}
之后的结果与预期不符,channel循环的时候,第i个Mat的值会变成第i+1个Mat的值?很奇怪?正确方法该如何使用呢?
我得到的结果如图:
所有图像都变成一样的了,即最后一个Mat的图像,这个问题困惑我很久了,这是为什么呢?