CV_IMPL void cvFindStereoCorrespondenceGC(const CvArr* _left, const CvArr* _right, CvArr* _dispLeft, CvArr* _dispRight, CvStereoGCState* state, int useDisparityGuess) { CvStereoGCState2 state2; state2.orphans = 0; state2.maxOrphans = 0; CvMat lstub, *left = cvGetMat(_left, &lstub); CvMat rstub, *right = cvGetMat(_right, &rstub); CvMat dlstub, *dispLeft = cvGetMat(_dispLeft, &dlstub); CvMat drstub, *dispRight = cvGetMat(_dispRight, &drstub); CvSize size; int iter, i, nZeroExpansions = 0; CvRNG rng = cvRNG(-1); int* disp; CvMat _disp; int64 E; CV_Assert(state != 0); CV_Assert(CV_ARE_SIZES_EQ(left, right) && CV_ARE_TYPES_EQ(left, right) && CV_MAT_TYPE(left->type) == CV_8UC1); CV_Assert(!dispLeft || (CV_ARE_SIZES_EQ(dispLeft, left) && CV_MAT_CN(dispLeft->type) == 1)); CV_Assert(!dispRight || (CV_ARE_SIZES_EQ(dispRight, left) && CV_MAT_CN(dispRight->type) == 1)); size = cvGetSize(left); if (!state->left || state->left->width != size.width || state->left->height != size.height) { int pcn = (int)(sizeof(GCVtx*) / sizeof(int)); int vcn = (int)(sizeof(GCVtx) / sizeof(int)); int ecn = (int)(sizeof(GCEdge) / sizeof(int)); cvReleaseMat(&state->left); cvReleaseMat(&state->right); cvReleaseMat(&state->ptrLeft); cvReleaseMat(&state->ptrRight); cvReleaseMat(&state->dispLeft); cvReleaseMat(&state->dispRight); state->left = cvCreateMat(size.height, size.width, CV_8UC3); state->right = cvCreateMat(size.height, size.width, CV_8UC3); state->dispLeft = cvCreateMat(size.height, size.width, CV_16SC1); state->dispRight = cvCreateMat(size.height, size.width, CV_16SC1); state->ptrLeft = cvCreateMat(size.height, size.width, CV_32SC(pcn)); state->ptrRight = cvCreateMat(size.height, size.width, CV_32SC(pcn)); state->vtxBuf = cvCreateMat(1, size.height * size.width * 2, CV_32SC(vcn)); state->edgeBuf = cvCreateMat(1, size.height * size.width * 12 + 16, CV_32SC(ecn)); } if (!useDisparityGuess) { cvSet(state->dispLeft, cvScalarAll(OCCLUDED)); cvSet(state->dispRight, cvScalarAll(OCCLUDED)); } else { CV_Assert(dispLeft && dispRight); cvConvert(dispLeft, state->dispLeft); cvConvert(dispRight, state->dispRight); } state2.Ithreshold = state->Ithreshold; state2.interactionRadius = state->interactionRadius; state2.lambda = cvRound(state->lambda * DENOMINATOR); state2.lambda1 = cvRound(state->lambda1 * DENOMINATOR); state2.lambda2 = cvRound(state->lambda2 * DENOMINATOR); state2.K = cvRound(state->K * DENOMINATOR); icvInitStereoConstTabs(); icvInitGraySubpix(left, right, state->left, state->right); disp = (int*)cvStackAlloc(state->numberOfDisparities * sizeof(disp[0])); _disp = cvMat(1, state->numberOfDisparities, CV_32S, disp); cvRange(&_disp, state->minDisparity, state->minDisparity + state->numberOfDisparities); cvRandShuffle(&_disp, &rng); if (state2.lambda < 0 && (state2.K < 0 || state2.lambda1 < 0 || state2.lambda2 < 0)) { float L = icvComputeK(state) * 0.2f; state2.lambda = cvRound(L * DENOMINATOR); } if (state2.K < 0) { state2.K = state2.lambda * 5; } if (state2.lambda1 < 0) { state2.lambda1 = state2.lambda * 3; } if (state2.lambda2 < 0) { state2.lambda2 = state2.lambda; } icvInitStereoTabs(&state2); E = icvComputeEnergy(state, &state2, !useDisparityGuess); for (iter = 0; iter < state->maxIters; iter++) { for (i = 0; i < state->numberOfDisparities; i++) { int alpha = disp[i]; int64 Enew = icvAlphaExpand(E, -alpha, state, &state2); if (Enew < E) { nZeroExpansions = 0; E = Enew; } else if (++nZeroExpansions >= state->numberOfDisparities) { break; } } } if (dispLeft) { cvConvert(state->dispLeft, dispLeft); } if (dispRight) { cvConvert(state->dispRight, dispRight); } cvFree(&state2.orphans); }
void cveRange(CvArr* mat, double start, double end) { cvRange(mat, start, end); }