Esempio n. 1
0
void ParallelMultiply(int msize, TYPE a[][NUM], TYPE b[][NUM], TYPE c[][NUM], TYPE t[][NUM])
{
	int NTHREADS = MAXTHREADS;
	int MSIZE = NUM;

	GetModelParams(&NTHREADS, &MSIZE, 0);

	MULTIPLY(MSIZE, NTHREADS, 0, a, b, c, t);
}
Esempio n. 2
0
void ParallelMultiply(int msize, TYPE a[][NUM], TYPE b[][NUM], TYPE c[][NUM], TYPE t[][NUM])
{
	int NTHREADS = MAXTHREADS;
	int MSIZE = NUM;

	GetModelParams(&NTHREADS, &MSIZE, 0);
	if(strncmp(xstr(MULTIPLY), "multiply5", 16) != 0)
	{
		printf("===== Error: Change matrix kernel to 'multiply5' for compilation with MKL =====\n"); fflush(stdout);
		return;
	}
	MULTIPLY(MSIZE, NTHREADS, 0, a, b, c, t);
}
Esempio n. 3
0
void ParallelMultiply(int msize, TYPE a[][NUM], TYPE b[][NUM], TYPE c[][NUM], TYPE t[][NUM])
{
	int NTHREADS = MAXTHREADS;
	int MSIZE = NUM;

#ifdef WIN32
	HANDLE ht[MAXTHREADS];
	DWORD tid[MAXTHREADS];
#else 
	pthread_t ht[MAXTHREADS];
	int tret[MAXTHREADS]; 
	int rc; 
	void* status;
#endif
	_tparam par[MAXTHREADS];
	int tidx;

	GetModelParams(&NTHREADS, &MSIZE, 0);

	for (tidx=0; tidx<NTHREADS; tidx++)
	{
		par[tidx].msize = MSIZE;
		par[tidx].numt = NTHREADS;
		par[tidx].tidx = tidx;
		par[tidx].a = a;
		par[tidx].b = b;
		par[tidx].c = c;
		par[tidx].t = t;
#ifdef WIN32		
		ht[tidx] = (HANDLE)CreateThread(NULL, 0, ThreadFunction, &par[tidx], 0, &tid[tidx]);
#else
		tret[tidx] = pthread_create( &ht[tidx], NULL, (void*)ThreadFunction, (void*) &par[tidx]);
#endif
	}
#ifdef WIN32
	WaitForMultipleObjects(NTHREADS, ht, TRUE, INFINITE);
#else // Pthreads
	for (tidx=0; tidx<NTHREADS; tidx++)
	{
	//	printf("Enter join\n"); fflush(stdout);
		rc = pthread_join(ht[tidx], (void **)&status);
	//	printf("Exit join\n"); fflush(stdout);
	}
#endif

}
Esempio n. 4
0
int main(int argc, char * argv[])
{
    if(argc != 1 && argc != 3)
    {
	std::cout << "[ USAGE ]: " << argv[0] << " [<Image Size> = 1000] [<nPoints> = 500]" << std::endl;
	return -1;
    }

    int Side = 1000;
    int nPoints = 500;
    if(argc == 3)
    {
	Side = std::atoi(argv[1]);
	nPoints = std::atoi(argv[2]);
    }

    cv::Mat Canvas(Side, Side, CV_8UC3);
    Canvas.setTo(255);

    // Randomly generate points in a 2D plane roughly aligned in a line for testing
    std::random_device SeedDevice;
    std::mt19937 RNG = std::mt19937(SeedDevice());

    std::uniform_int_distribution<int> UniDist(0, Side-1); // [Incl, Incl]
    int Perturb = 25;
    std::normal_distribution<GRANSAC::VPFloat> PerturbDist(0, Perturb);

    std::vector<std::shared_ptr<GRANSAC::AbstractParameter>> CandPoints;
    for(int i = 0; i < nPoints; ++i)
    {
	int Diag = UniDist(RNG);
	cv::Point Pt(floor(Diag + PerturbDist(RNG)), floor(Diag + PerturbDist(RNG)));
	cv::circle(Canvas, Pt, floor(Side / 100), cv::Scalar(0, 0, 0), -1);

	std::shared_ptr<GRANSAC::AbstractParameter> CandPt = std::make_shared<Point2D>(Pt.x, Pt.y);
	CandPoints.push_back(CandPt);
    }

    GRANSAC::RANSAC<Line2DModel, 2> Estimator;
    Estimator.Initialize(20, 100); // Threshold, iterations
    int start = cv::getTickCount();
    Estimator.Estimate(CandPoints);
    int end = cv::getTickCount();
    std::cout << "RANSAC took: " << GRANSAC::VPFloat(end-start) / GRANSAC::VPFloat(cv::getTickFrequency()) * 1000.0 << " ms." << std::endl;

    auto BestInliers = Estimator.GetBestInliers();
    if(BestInliers.size() > 0)
    {
	for(auto& Inlier : BestInliers)
	{
	    auto RPt = std::dynamic_pointer_cast<Point2D>(Inlier);
	    cv::Point Pt(floor(RPt->m_Point2D[0]), floor(RPt->m_Point2D[1]));
	    cv::circle(Canvas, Pt, floor(Side / 100), cv::Scalar(0, 255, 0), -1);
	}
    }

    auto BestLine = Estimator.GetBestModel();
    if(BestLine)
    {
	auto BestLinePt1 = std::dynamic_pointer_cast<Point2D>(BestLine->GetModelParams()[0]);
	auto BestLinePt2 = std::dynamic_pointer_cast<Point2D>(BestLine->GetModelParams()[1]);
	if(BestLinePt1 && BestLinePt2)
	{
	    cv::Point Pt1(BestLinePt1->m_Point2D[0], BestLinePt1->m_Point2D[1]);
	    cv::Point Pt2(BestLinePt2->m_Point2D[0], BestLinePt2->m_Point2D[1]);
	    DrawFullLine(Canvas, Pt1, Pt2, cv::Scalar(0, 0, 255), 2);
	}
    }

    while(true)
    {
	cv::imshow("RANSAC Example", Canvas);

	char Key = cv::waitKey(1);
	if(Key == 27)
	    return 0;
	if(Key == ' ')
	    cv::imwrite("LineFitting.png", Canvas);
    }

    return 0;
}