Ejemplo n.º 1
0
int main(){
    int counter=MAX;
    int wincount(0);
    int a[3];
    int select(-1);
    int doorNumber[3];
    while(counter--){
        randomGenerate(a,counter);
        //std::cout<<"Choice door = ?\n";
        srandom(counter+5);
        select=random()%3;
        //std::cin>>select;
        int looper=0;
        if(select==0||select==1||select==2){
            for(int i=0;i<3;i++){
                if(i==select){doorNumber[2]=select;}
                else{doorNumber[looper++]=i;}
            }
            int hostTell=doorNumber[rndOpenDoor(a,doorNumber)];
            //std::cout<<"I'd select="<<select<<'\t'<<"hostTell=["<<hostTell<<"]\t";
        }else{break;}
        //std::cout<<a[0]<<'\t'<<a[1]<<'\t'<<a[2]<<'\n';
        if(a[select]){wincount++;}
    }
    std::cout<<"Total Exp Rounds="<<MAX<<"\nAlwaysNoChange,Win="<<wincount<<'\n';
    return 0;
}
Ejemplo n.º 2
0
// Use RANSAC to compute H without openCV function
Mat Assignment2::computeRANSAC(Assignment2 &m2)  
{
	vector< DMatch > matches = this->FindMatchesEuclidian(m2); // find matches based on euclidian distances

	// Create vectors for storing Points
	vector<Point2f> query(matches.size());
	vector<Point2f> train(matches.size());
	
	//cout << matches.size() << " " << keypoints.size() << endl;
	
	// Assign points to that declared array
	for(unsigned int i=0;i<(matches.size());i++)
	{
		query[i]=this->keypoints[matches[i].queryIdx].pt; 
		train[i]=m2.keypoints[matches[i].trainIdx].pt; 
	}

	// define parameters for RANSAC algorithm
	int iterations=0;
	double inlierThresh=0.90;
	double inlierPerc=0;
	Mat H;
	Mat Hbest;
	double inlierbest=0;
	
	// do while loop for 3000 iterations
	do
	{
		int N=matches.size();
		int M=4;
		vector<Point2f> queryH(M);  // take 4 points
		vector<Point2f> trainH(M);
		vector<int> randVecId=randomGenerate(N,M);

		for(int i=0;i<M;i++)
		{
			queryH[i]=query[randVecId[i]]; // take 4 points randomly
			trainH[i]=train[randVecId[i]];
		}
		
		H = computeH(queryH, trainH);  // Compute H based on the that 4 points

		double inliners = computeInliers(train, query, H, 3);  // calculate inliners for that H

		if(inliners>inlierbest)
		{
			inlierbest=inliners;
			Hbest=H.clone();
		}

		inlierPerc=inliners/(double)N;

		iterations++;

	} while(iterations<3000);//&&inlierPerc<inlierThresh);
	
	normalizeH(Hbest);  // normalize Hbest

	return Hbest;
}