예제 #1
0
void wordQuery::getQResult(string &in,q_Result& qResult)
{
	char ihead=' ';
	char irear=' ';
	int qwordlength=0;
	input=in;
	//q_Result tresult;
	//loadIndex();
	refineInput();
	ihead=input.at(0)-'a';
	irear=input.at(input.length()-1)-'a';
	qwordlength=input.length();
	dataUnit temp;

	//search in corresponding speed-up block
	int i;
	for(i=0;i<wddb[ihead][irear].size();i++)
	{
		temp=wddb[ihead][irear].at(i);
		if(temp.word.length()<=qwordlength&&isContainedWord(input,temp.word))
		{
			//restoration
			if(cap_flag==1)
				temp.word.at(0)-=32;
			if(cap_flag==2)
			{
				for(int j=0;j<temp.word.length();j++)
					temp.word.at(j)-=32;
			}
			qResult.push_back(temp);
		}
	}
	//check results
	/*
	for(int i=0;i<qResult.size();i++)
	{
		cout<<qResult.at(i).word<<"	"<<qResult.at(i).freq<<endl;
	}*/
}
void BundleRTS::run(int nPtsCon, int nCamsCon, int maxIter) {
    refineInput(_mapPts);

    numPtsCon = nPtsCon;
    numCamsCon = nCamsCon;

    compressMeasurements();

    const int cnp = 11; //5:intrinsic parameters 6:extrinsic parameters
    const int pnp = 3;
    const int mnp = 2;

    m_globs.cnp = cnp;
    m_globs.pnp = pnp;
    m_globs.mnp = mnp;

    if (m_globs.rot0params) {
        delete[] m_globs.rot0params;
    }
    m_globs.rot0params = new double[FULLQUATSZ * numCams];

    //set initial camera parameters
    for (int i = 0; i < numCams; ++i) {
        mat2quat(Rs + 9 * i, m_globs.rot0params + 4 * i);
    }

    m_globs.intrcalib = 0;
    m_globs.nccalib = 5;

    m_globs.camparams = 0;
    m_globs.ptparams = 0;

    /* call sparse LM routine */
    double opts[SBA_OPTSSZ];
    opts[0] = SBA_INIT_MU * 1E-4;
    opts[1] = SBA_STOP_THRESH;
    opts[2] = SBA_STOP_THRESH;
    opts[3] = 0; //0.05 * numMeas; // uncomment to force termination if the average reprojection error drops below 0.05
    opts[4] = 1E-16; // uncomment to force termination if the relative reduction in the RMS reprojection error drops below 1E-05

    if (m_paramVec)
        delete[] m_paramVec;
    m_paramVec = new double[numCams * cnp + numPts * pnp];

    double * pParamVec = m_paramVec;
    double* pKs = Ks.data;
    double* pTs = Ts.data;
    for (int i = 0; i < numCams; ++i) {
        pParamVec[0] = pKs[0];
        pParamVec[1] = pKs[2];
        pParamVec[2] = pKs[5];
        pParamVec[3] = pKs[4] / pKs[0];
        pParamVec[4] = pKs[1];

        pParamVec[5] = 0;
        pParamVec[6] = 0;
        pParamVec[7] = 0;
        pParamVec[8] = pTs[0];
        pParamVec[9] = pTs[1];
        pParamVec[10] = pTs[2];

        pParamVec += cnp;
        pKs += 9;
        pTs += 3;
    }
    double* pParamPoints = m_paramVec + numCams * cnp;
    memcpy(pParamPoints, Ms.data, numPts * 3 * sizeof(double));

    double sbaInfo[SBA_INFOSZ];
    if (sba_motstr_levmar_x(numPts, numPtsCon, numCams, numCamsCon, vmask,
                            m_paramVec, cnp, pnp, ms.data, 0, mnp, img_projsKRTS_x,
                            img_projsKRTS_jac_x, (void *) (&m_globs), maxIter, 0, opts,
                            sbaInfo) == SBA_ERROR) {
        //for debug
        //save the bundle data for debug


        repErr("bundle adjustment failed!\n");
    }
    //test
    logInfo(
        "initial error:%lf, final error:%lf #iterations:%lf stop reason:%lf\n",
        sqrt(sbaInfo[0] / numMeas), sqrt(sbaInfo[1] / numMeas), sbaInfo[5],
        sbaInfo[6]);
}