Mat::push_back corrupts data (Bug #4421)
Description
#include "opencv2/opencv.hpp" bool all_ones(const cv::Mat& m) { for (int i = 0; i < m.rows; ++i) { for (int j = 0; j < m.cols; ++j) { if (m.at<int>(i, j) != 1) { return false; } } } return true; } int main(int argc, char** argv) { cv::Mat data = cv::Mat::zeros(0, 128, cv::DataType<int>::type); for (int i = 0; i < 4; ++i) { printf("Iteration %d\n", i); cv::Mat to_append = cv::Mat::ones(3750000, 128, cv::DataType<int>::type); data.push_back(to_append); if (!all_ones(data)) { fprintf(stderr, "Error: not all elements are == 1.\n"); exit(-1); } } return 0; }
All elements of data should be equal to 1, but some elements become not equal to 1 after a few push_backs.
Output:
Iteration 0 Iteration 1 Iteration 2 Iteration 3 Error: not all elements are == 1.
History
Updated by Maksim Shabunin over 9 years ago
Can you, please, check whether the PR (https://github.com/Itseez/opencv/pull/4148) fixes your problem?
- Assignee changed from Vadim Pisarevsky to Maksim Shabunin
- Pull request set to https://github.com/Itseez/opencv/pull/4148
Updated by Maksim Shabunin over 9 years ago
Should be fixed by PR https://github.com/Itseez/opencv/pull/4158
- Target version set to 3.1
- Status changed from New to Done
- Pull request changed from https://github.com/Itseez/opencv/pull/4148 to https://github.com/Itseez/opencv/pull/4158