voidlabelComponents(int row, int col){ // use std::queue std::vector std::deque will slow the program down greatly float d1, d2, alpha, angle; int fromIndX, fromIndY, thisIndX, thisIndY; bool lineCountFlag[N_SCAN] = {false};
queueIndX[0] = row; queueIndY[0] = col; int queueSize = 1; int queueStartInd = 0; int queueEndInd = 1;
allPushedIndX[0] = row; allPushedIndY[0] = col; int allPushedIndSize = 1;
while(queueSize > 0){ // Pop point fromIndX = queueIndX[queueStartInd]; fromIndY = queueIndY[queueStartInd]; --queueSize; ++queueStartInd; // 标记要pop的点的label labelMat.at<int>(fromIndX, fromIndY) = labelCount; // Loop through all the neighboring grids of popped grid for (auto iter = neighborIterator.begin(); iter != neighborIterator.end(); ++iter){ // new index thisIndX = fromIndX + (*iter).first; thisIndY = fromIndY + (*iter).second; // index should be within the boundary if (thisIndX < 0 || thisIndX >= N_SCAN) continue; // at range image margin (left or right side) if (thisIndY < 0) thisIndY = Horizon_SCAN - 1; if (thisIndY >= Horizon_SCAN) thisIndY = 0; // prevent infinite loop (caused by put already examined point back) if (labelMat.at<int>(thisIndX, thisIndY) != 0) continue;
// 点数少于30的类被认为无效 bool feasibleSegment = false; if (allPushedIndSize >= 30) feasibleSegment = true; elseif (allPushedIndSize >= segmentValidPointNum){ int lineCount = 0; for (size_t i = 0; i < N_SCAN; ++i) if (lineCountFlag[i] == true) ++lineCount; if (lineCount >= segmentValidLineNum) feasibleSegment = true; } // segment is valid, mark these points if (feasibleSegment == true){ ++labelCount; }else{ // segment is invalid, mark these points for (size_t i = 0; i < allPushedIndSize; ++i){ labelMat.at<int>(allPushedIndX[i], allPushedIndY[i]) = 999999; } } }