Simple example code.
using push_back
#gistcode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
#end code
using concate
#start code
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//using concate | |
cout << "\ncopy interest rows to new Mat using concate\n"; | |
Mat c; | |
for (auto it : row_index_interest) | |
{ | |
if (c.empty()) | |
{ | |
c = a.row(it); | |
continue; | |
}else{ | |
//cout << a.row(it) << endl; | |
vconcat(c, a(Range(it, it+1), Range::all()), c); | |
/* //or | |
Mat t; | |
vconcat(c, a(Range(it, it+1), Range::all()), t); | |
c = t; | |
*/ | |
} | |
} | |
cout << "\nnew Mat\n"; | |
cout << c << endl; |
#end code
No comments:
Post a Comment