@
adjusted 举个栗子,毕设中的几行代码
tubes是这么一货:
vector<vector<vector<vector<Point>>>> tubes;
脑补python这么写。。。。
results = [drawContours(result, contours, -1, Scalar(0), 2) for contours in tube for tube in tubes]
results2 = [drawContours(result, contours, -1, Scalar(0), 2) for contours in tube for tube in zip(tubes)]
用c++迭代器直译:
vector<vector<vector<vector<Point>>>::const_iterator> tube_iterator;
for (vector<vector<vector<vector<Point>>>>::const_iterator tubes_iterator = tubes.begin(); tubes_iterator != tubes.end(); tubes_iterator++)
{
tube_iterator.push_back(tubes_iterator->begin());
}
for (vector<vector<vector<vector<Point>>>::const_iterator>::const_iterator it = tube_iterator.begin(); it != tube_iterator.end() && !finshed; it++)
{
我TM不写了。。。
当然事后发现使用下标还是给人写的,以下是类似生成results2 的c++代码
bool finshed = false;
for (int i = 0; finshed != true; i++){
finshed = true;
Mat result(frame_size, CV_8U, Scalar(255));
for (int n = 0; n<tubes.size(); n++){
if (tubes[n].size() > i){
drawContours(result, tubes[n][i], -1, Scalar(0), 2);
finshed = false;
}
}
}