Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save MareArts/905bb9a38ae94943496cd1fef062d687 to your computer and use it in GitHub Desktop.
Save MareArts/905bb9a38ae94943496cd1fef062d687 to your computer and use it in GitHub Desktop.
Extract the value of interest rows and copy that to new Mat
cout << "origin\n";
Mat a = (Mat_<int>(5, 5) << 1, 2, 3, 4, 5,
7, 8, 9, 10, 11,
12, 13, 14, 15, 16,
17, 18, 19, 20, 21,
22, 23, 24, 25, 26);
cout << a << endl;
cout << "\ninterest index of row - 0,3\n";
vector< int> row_index_interest;
row_index_interest.push_back(0);
row_index_interest.push_back(3);
cout << "\ncopy interest rows to new Mat\n";
Mat b;
for (auto it: row_index_interest)
{
cout << a.row(it) << endl;
b.push_back(a.row(it));
}
cout << "\nnew Mat\n";
cout << b << endl;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment