according to c++ reference calling push_back
appends elements to the vector so it increases the size from the end
so you have size of at least 2*cols
. you should either initialize an empty vector . or use the []
operator .
题
I have a cv::Mat named myImage which I want to save to an std::vector > named savedVec. This is the code I have written:
for (int i = 0; i < myImage.rows; ++i)
{
std::vector<int> row(myImage.cols);
for (int j = 0; j < myImage.cols; ++j)
{
row.push_back(Play::getInstance()->getFinder()->getImage().at<uchar>(i, j));
}
savedVec.push_back(row);
}
My problem now is that somehow savedVec[0].size()
yields twice the size of myImage.cols, but as they should be the same, shouldn't they?
Please tell me what I am doing wrong.
解决方案
according to c++ reference calling push_back
appends elements to the vector so it increases the size from the end
so you have size of at least 2*cols
. you should either initialize an empty vector . or use the []
operator .