void match2ind(int maxNum, const Matching& matches, Mat_i& indices) { assert(maxNum > 0); indices.resize(maxNum, 1); indices.fill(-1); for (int i = 0; i < matches.num; i++) { int idx1 = matches[i].idx1; int idx2 = matches[i].idx2; indices.data[idx1] = idx2; } }
void getMatchIndices(Matching& matches, int maxInd, Mat_i& ind, bool inverse) { ind.resize(maxInd, 1); ind.fill(-1); if (!inverse) { for (int i = 0; i < matches.num; i++) { int idx1 = matches[i].idx1; int idx2 = matches[i].idx2; ind.data[idx1] = idx2; } } else { for (int i = 0; i < matches.num; i++) { int idx1 = matches[i].idx1; int idx2 = matches[i].idx2; ind.data[idx2] = idx1; } } }
void selectCameraOrder(int camNum, const int* distMat, Mat_i& order) { int maxVal = 0; int iMax = -1, jMax = -1; const int* pDistMat = distMat; // find the max value in the distMat at (iMax, jMax) for (int i = 0; i < camNum; i++) { for (int j = i; j < camNum; j++) { if (pDistMat[j] > maxVal) { maxVal = pDistMat[j]; iMax = i; jMax = j; } } pDistMat += camNum; } Mat_uc flag(camNum, 1); flag.fill(0); flag[iMax] = 1; flag[jMax] = 1; std::list<int> cams; cams.push_back(iMax); cams.push_back(jMax); while (maxVal > 0) { int iHead = cams.front(); int iTail = cams.back(); int iMaxHead = -1; int maxValHead = 0; pDistMat = distMat + camNum * iHead; for (int j = 0; j < camNum; j++) { if (flag[j] > 0) continue; else if (maxValHead < pDistMat[j]) { maxValHead = pDistMat[j]; iMaxHead = j; } } int iMaxTail = -1; int maxValTail = 0; pDistMat = distMat + camNum * iTail; for (int j = 0; j < camNum; j++) { if (flag[j] > 0) continue; else if (maxValTail < pDistMat[j]) { maxValTail = pDistMat[j]; iMaxTail = j; } } if (iMaxHead < 0 && iMaxTail < 0) { break; } if (maxValHead > maxValTail) { cams.push_front(iMaxHead); flag[iMaxHead] = 1; } else if (maxValHead < maxValTail) { cams.push_back(iMaxTail); flag[iMaxTail] = 1; } } order.resize(cams.size(), 1); int k = 0; std::list<int>::iterator iter; for (iter = cams.begin(); iter != cams.end(); iter++) { order.data[k++] = *iter; } order.rows = k; if (order.rows != camNum) { repErr("selectCameraOrder - not all camera have the intersection of views"); } }