void MainWindow::RANSAC() { int numIterations = ui->iterationsBox->value(); double inlierThreshold = ui->RANSACThresSpinBox->value(); m_InImage1Display = m_InImage1.copy(); m_InImage2Display = m_InImage2.copy(); RANSAC(m_Matches, m_NumMatches, numIterations, inlierThreshold, m_Hom, m_HomInv, m_InImage1Display, m_InImage2Display); DrawDisplayImage(); }
void process( FrameData &frameData ) { vector< SP_Image > &images = frameData.images; vector< vector< FrameData::Match > > &matches = frameData.matches; vector< vector< FrameData::Cluster > >&clusters = frameData.clusters; vector< vector< LmData > > lmData; lmData.reserve(1000); preprocessAllMatches( lmData, matches, images ); vector< pair<int,int> > tasks; tasks.reserve(1000); for(int model=0; model<(int)clusters.size(); model++ ) for(int cluster=0; cluster<(int)clusters[model].size(); cluster++ ) tasks.push_back( make_pair(model, cluster) ); #pragma omp parallel for for(int task=0; task<(int)tasks.size(); task++) { int model=tasks[task].first; int cluster=tasks[task].second; vector<LmData *> cl; foreach( point, clusters[model][cluster] ) cl.push_back( & lmData[model][ point ] ); Pose pose; bool found = RANSAC( pose, cl, MaxObjectsXCluster ); if( found ) #pragma omp critical(POSE_PROCESS) { SP_Object obj(new Object); frameData.objects->push_back(obj); obj->pose = pose; obj->model = (*models)[model]; } } }
MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) { ui->setupUi(this); connect(ui->openButton, SIGNAL(clicked()), this, SLOT(OpenImage())); connect(ui->saveButton, SIGNAL(clicked()), this, SLOT(SaveImage())); connect(ui->harrisButton, SIGNAL(clicked()), this, SLOT(HarrisCornerImage())); connect(ui->matchButton, SIGNAL(clicked()), this, SLOT(MatchImages())); connect(ui->RANSACButton, SIGNAL(clicked()), this, SLOT(RANSAC())); connect(ui->stitchButton, SIGNAL(clicked()), this, SLOT(StitchImages())); ui->harrisSpinBox->setValue(2.0); ui->harrisThresSpinBox->setValue(50.0); ui->RANSACThresSpinBox->setValue(5.0); ui->iterationsBox->setValue(200); ui->tabWidget->setCurrentIndex(0); }
/* //------------------ //--- MAIN (MEX) --- //------------------ */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs,const mxArray *prhs[]) { /*Structs*/ struct matrixM A_in = {0,NULL,NULL,0,0,0,0}; struct matrixM B_in = {0,NULL,NULL,0,0,0,0}; struct matrixM error_out = {0,NULL,NULL,0,0,0,0}; struct matrixM M_in = {0,NULL,NULL,0,0,0,0}; struct matrixM M_out = {0,NULL,NULL,0,0,0,0}; float err_thr; float min_set_size; float iter; mwSize temp[2] = {0, 1}; /* //------------------------------------------ //--- CHECK FOR CORRECT INPUT PARAMETERS --- //------------------------------------------ */ /* Check for proper number of arguments. */ if (nrhs != 6) { mexErrMsgTxt("SurfaceEquation error: wrong number of input parameters!"); } /* //--------------- //--- A_in --- //--------------- */ /* A_in must be a noncomplex matrix. */ if (!mxIsSingle(prhs[0])){ mexErrMsgTxt("SurfaceEquation error: 'A_in' must be a noncomplex single-valued matrix."); } /*Get number of dimensions and elements per dimension */ A_in.ndims = mxGetNumberOfDimensions(prhs[0]); A_in.dimElems = mxGetDimensions(prhs[0]); A_in.data = (float*)mxGetPr( prhs[0] ); /* //--------------- //--- B_in --- //--------------- */ /* B_in must be a noncomplex matrix. */ if (!mxIsSingle(prhs[1])){ mexErrMsgTxt("SurfaceEquation error: 'B_in' must be a noncomplex single-valued matrix."); } /*Get number of dimensions and elements per dimension */ B_in.ndims = mxGetNumberOfDimensions(prhs[1]); B_in.dimElems = mxGetDimensions(prhs[1]); B_in.data = (float*)mxGetPr( prhs[1] ); /* //------------ //--- M in --- //------------ */ /* M_in must be a noncomplex matrix. */ if (!mxIsSingle(prhs[2])){ mexErrMsgTxt("SurfaceEquation error: 'M_in' must be a noncomplex single-valued matrix."); } /*Get number of dimensions and elements per dimension */ M_in.ndims = mxGetNumberOfDimensions(prhs[2]); M_in.dimElems = mxGetDimensions(prhs[2]); M_in.data = (float*)mxGetPr( prhs[2] ); /* //----------------------- //--- Error threshold --- //----------------------- */ /* err_thr must be a noncomplex scalar. */ if (!mxIsSingle(prhs[3])){ mexErrMsgTxt("SurfaceEquation error: 'err_thr' must be a noncomplex, single-type scalar"); } err_thr = *((float*)mxGetPr( prhs[3] ) ); /* //------------------------ //--- Minimum set size --- //------------------------ */ /* min_set_size must be a noncomplex scalar. */ if (!mxIsSingle(prhs[4])){ mexErrMsgTxt("SurfaceEquation error: 'min_set_size' must be a noncomplex, single-type scalar"); } min_set_size = *((float*)mxGetPr( prhs[4] ) ); /* //----------------------------------- //--- Number of iterations --- //----------------------------------- */ /* min_set_size must be a noncomplex scalar. */ if (!mxIsSingle(prhs[5])){ mexErrMsgTxt("SurfaceEquation error: 'iter' must be a noncomplex, single-type scalar"); } iter = *((float*)mxGetPr( prhs[5] ) ); /*INPUT VALIDITY CHECKING*/ if( M_in.data != NULL ) { if( A_in.dimElems[1] != M_in.dimElems[0] ) { mexErrMsgTxt("SurfaceEquation error: M_in is a column vector with as many row elements as A_in has columns!"); } } if( A_in.dimElems[0] != B_in.dimElems[0] ) mexErrMsgTxt("SurfaceEquation error: A_in and B_in have to have same amount of rows!"); switch( A_in.dimElems[1] ) { case 3: temp[0] = 3; break; case 6: temp[0] = 6; break; default: mexPrintf("A_in.dimElems[0]:%d, A_in.dimElems[1]:%d\n",A_in.dimElems[0], A_in.dimElems[1]); mexErrMsgTxt("SurfaceEquation error: only 1st and 2nd order polynomials are implemented!"); } if( nlhs<2 ) { mexErrMsgTxt("SurfaceEquation error: insufficient number of outputs. Outputs from this function is 'M_out' and 'error_out'"); }else{ if( (plhs[0] = mxCreateNumericArray(2, temp, mxSINGLE_CLASS, mxREAL))==NULL ) mexErrMsgTxt("SurfaceEquation error: error reserving space for output variable 'M_out'"); if( (M_out.data = (float *)mxGetPr( plhs[0] ))==NULL ) mexErrMsgTxt("SurfaceEquation error: error obtaining pointer to output variable 'M_out'"); M_out.ndims = mxGetNumberOfDimensions(plhs[0]); M_out.dimElems = mxGetDimensions(plhs[0]); temp[0] = A_in.dimElems[0]; if( (plhs[1] = mxCreateNumericArray(2, temp, mxSINGLE_CLASS, mxREAL))==NULL ) mexErrMsgTxt("SurfaceEquation error: error reserving space for output variable 'M_out'"); if( (error_out.data = (float *)mxGetPr( plhs[1] ))==NULL ) mexErrMsgTxt("SurfaceEquation error: error obtaining pointer to output variable 'error_out'"); error_out.ndims = mxGetNumberOfDimensions(plhs[1]); error_out.dimElems = mxGetDimensions(plhs[1]); } RANSAC( &A_in, /*Homogeneous coordinate matrix (e.g [X Y 1] or [X^2 Y^2 XY X Y 1])*/ &B_in, /*Surface 'height' [Z]*/ &M_out, /*The best model found by RANSAC*/ &M_in, /*The best model found by RANSAC*/ &error_out, /*Residual (or fitting error) of each data for the best model*/ &mvarPolynomial, err_thr, /*Error threshold for determining if the data fits the model*/ min_set_size, /*Minimum number of close data (percentage; 0.0-1.0) values required to assert that a model fits well to data*/ (unsigned int)iter, /*Number of iterations*/ (unsigned int)M_out.dimElems[0]+1 ); /*Number of data used for generating the model*/ }