danini / graph-cut-ransac

The Graph-Cut RANSAC algorithm proposed in paper: Daniel Barath and Jiri Matas; Graph-Cut RANSAC, Conference on Computer Vision and Pattern Recognition, 2018. It is available at http://openaccess.thecvf.com/content_cvpr_2018/papers/Barath_Graph-Cut_RANSAC_CVPR_2018_paper.pdf

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

The return value problem of Sample() function in GCoptimization.h for linux version code

wangmaoCS opened this issue · comments

sorry for trouble!
I have configure the code in Linux OS.

However, I have found the function Sample() in file GCoptimization.h may have a problem when running the code. There is no return value, which may result in a bug in the while loop in function Run().

template <class ModelEstimator, class Model>
bool GCRANSAC<ModelEstimator, Model>::Sample(const cv::Mat &points, std::vector<int> &pool, const std::vector<std::vector<cv::DMatch>> &neighbors, int sample_number, int *sample)
{
	// TODO: replacable sampler
	for (int i = 0; i < sample_number; ++i)
	{
		int idx = (pool.size() - 1) * static_cast<float>(rand()) / RAND_MAX;
		sample[i] = pool[idx];
		pool.erase(pool.begin() + idx);
	}

	pool.reserve(pool.size() + sample_number);
	for (int i = 0; i < sample_number; ++i)
		pool.push_back(sample[i]);
}

	while (1) // Sample while needed
	{
		if (!Sample(points, pool, neighbours, sample_number, sample)) // Sampling
			continue;
		 
		if (estimator.EstimateModel(points, sample, &models)) // Estimate (and validate) models using the current sample
			break; 
	}  

``

I find my code will run in the while(1) loop and never end!
Is this a problem for my modified Linux version.

Nice, it did not even give me a warning :)
I updated it and fixed things which threw warnings.

Thanks!
The updated code is OK!