Example #1
0
    bool _centroidAngleTest()
    {
        cvt::Resources r;

        bool result = true;

        for( size_t i = 0; i < 360; i+=5 ){
            String fileIn( "bw" );
            fileIn += i;
            fileIn += ".png";
            //std::cout << "File : " << fileIn << std::endl;
            cvt::Image _img( r.find( fileIn ) );

            cvt::Image img;
            _img.convert( img, IFormat::GRAY_UINT8 );
            cvt::ORB orb( img, 1, 0.5f, 50 );

            cvt::Image ii;
            img.integralImage( ii );

            size_t stride;
            float * ptr = ii.map<float>( &stride );

            cvt::ORBFeature feature( img.width() / 2.0f, img.height() / 2.0f );

            orb.centroidAngle( feature, ptr, stride );

            //std::cout << "Feature Angle: " << Math::rad2Deg( feature.angle ) << std::endl;

            ii.unmap<float>( ptr );

        }

        return result;
    }
Example #2
0
/**
* Draw OpenCV matrix using QLabel
*/
void ImageApp::showImage(cv::Mat img)
{
   if (img.data) {
       QImage _img(img.data, img.cols, img.rows, QImage::Format_RGB888);
       imageLabel->setPixmap(QPixmap::fromImage(_img));
   } else {
       imageLabel->setText("Cannot load the input image!");
   }
}
Example #3
0
void SurfFD::extractKeypoints(cv::Mat* m)
{
  //memcpy( output_image_, input_image_, sizeof(input_image_) );//Replace by opencv copying

  //CvSURFParams params = cvSURFParams(500, 1);
  //CvMemStorage* storage = cvCreateMemStorage(0);
  //(*outputEK).extractKeypoints();

  CvSURFParams params = cvSURFParams(500, 0);
  CvMemStorage* storage = cvCreateMemStorage(0);

  IplImage _img(*m);
  cvExtractSURF(&_img, 0, &keypoints_, &descriptors_, storage, params);
}
void
KbfxPlasmaCanvasItem::setIconPath ( QString str )
{
	KIconLoader *iconload = KGlobal::iconLoader ();
	m_iconPath =  iconload->iconPath ( str, KIcon::Desktop, false );
//	m_icon.load(m_iconPath);
	QImage _img ( m_iconPath );

	if ( _img.height() > 128 )
	{
		_img = _img.smoothScale ( 32,32 );

	}

	m_icon.convertFromImage ( _img );

}
CUDA_TEST_P(Hog_var, HOG)
{
    cv::cuda::GpuMat _img(c_img);
    cv::cuda::GpuMat d_img;

    int win_stride_width = 8;int win_stride_height = 8;
    int win_width = 16;
    int block_width = 8;
    int block_stride_width = 4;int block_stride_height = 4;
    int cell_width = 4;
    int nbins = 9;

    Size win_stride(win_stride_width, win_stride_height);
    Size win_size(win_width, win_width * 2);
    Size block_size(block_width, block_width);
    Size block_stride(block_stride_width, block_stride_height);
    Size cell_size(cell_width, cell_width);

    cv::Ptr<cv::cuda::HOG> gpu_hog = cv::cuda::HOG::create(win_size, block_size, block_stride, cell_size, nbins);

    gpu_hog->setNumLevels(13);
    gpu_hog->setHitThreshold(0);
    gpu_hog->setWinStride(win_stride);
    gpu_hog->setScaleFactor(1.05);
    gpu_hog->setGroupThreshold(8);
    gpu_hog->compute(_img, d_img);

    vector<float> gpu_desc_vec;
    ASSERT_TRUE(gpu_desc_vec.empty());
    cv::Mat R(d_img);

    cv::HOGDescriptor cpu_hog(win_size, block_size, block_stride, cell_size, nbins);
    cpu_hog.nlevels = 13;
    vector<float> cpu_desc_vec;
    ASSERT_TRUE(cpu_desc_vec.empty());
    cpu_hog.compute(c_img, cpu_desc_vec, win_stride, Size(0,0));
}
Example #6
0
bool bowCV::train_run(const string& _filepathForSavingResult,const string& _filenameForSavingResult, cvac::ServiceManager *sman)
{
	if(!flagName)
	{
		cout << "Need to initialize detector, extractor, matcher, and so on with the function train_initialize()." << endl;	fflush(stdout);
		return false;
	}

	if(vFilenameTrain.size() < 1)
	{
		cout << "There is no training images." << endl;	fflush(stdout);
		return false;
	}
	else
	{
		cout<< "Training is started. " << endl; fflush(stdout);
	}
	//////////////////////////////////////////////////////////////////////////
	// START - Clustering (Most time-consuming step)
	//////////////////////////////////////////////////////////////////////////

	Mat _descriptorRepository;		
	Rect _rect;
	for(unsigned int k=0;k<vFilenameTrain.size();k++)
	{
		_fullFilePathImg = vFilenameTrain[k];

		_img = imread(_fullFilePathImg);
		if(_img.empty())
		{			
			cout<<"Error - no file: " << _fullFilePathImg << endl;	fflush(stdout);
			return false;
		}
        if (sman->stopRequested())
        {
            sman->stopCompleted();
            return false;
        }
		
		_rect = Rect(vBoundX[k],vBoundY[k],vBoundWidth[k],vBoundHeight[k]);
		if((_rect.width != 0) && (_rect.height != 0))
			_img = _img(_rect);

// 		imshow("Crop",_img);
// 		waitKey();

		fDetector->detect(_img, _keypoints);
		dExtractor->compute(_img, _keypoints, _descriptors);

		_descriptorRepository.push_back(_descriptors);

		cout<< "Progress of Feature Extraction: " << k+1 << "/" << vFilenameTrain.size() << '\xd';	fflush(stdout);
	}	
	cout << endl;	fflush(stdout);

	cout << "Total number of descriptors: " << _descriptorRepository.rows << endl;	fflush(stdout);

	cout << "Clustering ... It will take a time.." << std::endl;	fflush(stdout);
	BOWKMeansTrainer bowTrainer(cntCluster); 
	bowTrainer.add(_descriptorRepository);	
	mVocabulary = bowTrainer.cluster();	

	if(!train_writeVocabulary(_filepathForSavingResult + "/" + filenameVocabulary,mVocabulary))
		return false;
	//////////////////////////////////////////////////////////////////////////
	// END - Clustering (Most time-consuming step)
	//////////////////////////////////////////////////////////////////////////


	//////////////////////////////////////////////////////////////////////////
	// START - Setup Vocabulary
	//////////////////////////////////////////////////////////////////////////
	cout << "Setting Vocabulary ... " << endl;	fflush(stdout);			
	bowExtractor->setVocabulary(mVocabulary);
	//////////////////////////////////////////////////////////////////////////
	// START - End Vocabulary
	//////////////////////////////////////////////////////////////////////////


	///////////////////////////////////////////////////////////////////////////
	// START - Train Classifier (SVM)
	//////////////////////////////////////////////////////////////////////////
	cout << "Training Classifier ... " << endl;	fflush(stdout);
	
	Mat trainDescriptors;	trainDescriptors.create(0,bowExtractor->descriptorSize(),bowExtractor->descriptorType());
	Mat trainClass;	trainClass.create(0,1,CV_32FC1);
	int _classID;
	

	for(unsigned int k=0;k<vFilenameTrain.size();k++)
	{
		_fullFilePathImg = vFilenameTrain[k];
		_classID = vClassIDTrain[k];
		
		if(_classID==-1)
			continue;
        
        if (sman->stopRequested())
        {
            sman->stopCompleted();
            return false;
        }
		_img = imread(_fullFilePathImg);
		
		_rect = Rect(vBoundX[k],vBoundY[k],vBoundWidth[k],vBoundHeight[k]);
		if((_rect.width != 0) && (_rect.height != 0))
			_img = _img(_rect);
		
		fDetector->detect(_img, _keypoints);
		bowExtractor->compute(_img, _keypoints, _descriptors);
		trainDescriptors.push_back(_descriptors);
		trainClass.push_back(_classID);
	}

	//SVMTrainParamsExt svmParamsExt;
	//CvSVMParams svmParams;
	//CvMat class_wts_cv;
	//setSVMParams( svmParams, class_wts_cv, labels, true );
	//CvParamGrid c_grid, gamma_grid, p_grid, nu_grid, coef_grid, degree_grid;
	//setSVMTrainAutoParams( c_grid, gamma_grid,  p_grid, nu_grid, coef_grid, degree_grid );
	//classifierSVM[class_].train_auto( samples_32f, labels, Mat(), Mat(), svmParams, 10, c_grid, gamma_grid, p_grid, nu_grid, coef_grid, degree_grid );
	classifierSVM.train(trainDescriptors,trainClass);

	

	_fullFilePathList = _filepathForSavingResult + "/" + _filenameForSavingResult;
	ofstream ofile(_fullFilePathList.c_str());
	ofile << "# This file should includes the followings:" << std::endl;
	ofile << "# The name of Detector" << std::endl;
	ofile << "# The name of Extractor" << std::endl;
	ofile << "# The name of Matcher" << std::endl;
	ofile << "# The filename of vocabulary" << std::endl;
	ofile << "# Filenames of svm results" << std::endl;
	ofile << nameDetector << std::endl;
	ofile << nameExtractor << std::endl;
	ofile << nameMatcher << std::endl;
	ofile << filenameVocabulary << std::endl;	
	
	string _svmName = "logTrain_svm.xml.gz";
	ofile << _svmName << endl;
	_fullFilePathList = _filepathForSavingResult + "/" + _svmName;
	classifierSVM.save(_fullFilePathList.c_str());
	
	ofile.close();

	flagTrain = true;

	return true;
}
Example #7
0
bool project_state::set(project_info* p, bool current)
{
	if(!p) {
		if(active_project)
			commentary.unload_collection();
		active_project = p;
		edispatch.core_change();
		edispatch.branch_change();
		return true;
	}

	loaded_rom newrom;
	moviefile* newmovie = NULL;
	bool switched = false;
	std::set<core_sysregion*> sysregs;
	bool used = false;
	try {
		if(current)
			goto skip_rom_movie;

		sysregs = core_sysregion::find_matching(p->gametype);
		if(sysregs.empty())
			throw std::runtime_error("No core supports '" + p->gametype + "'");

		//First, try to load the ROM and the last movie file into RAM...
		if(p->rom != "") {
			rom_image_handle _img(new rom_image(p->rom, p->coreversion));
			newrom = loaded_rom(_img);
		} else {
			core_type* ctype = NULL;
			for(auto i : sysregs) {
				ctype = &i->get_type();
				if(ctype->get_core_identifier() == p->coreversion)
					break;
			}
			rom_image_handle _img(new rom_image(p->roms, ctype->get_core_identifier(), ctype->get_iname(),
				""));
			newrom = loaded_rom(_img);
		}
		if(newrom.get_core_identifier() != p->coreversion) {
			messages << "Warning: Can't find matching core, using " << newrom.get_core_identifier()
				<< std::endl;
		}
		if(p->last_save != "")
			try {
				newmovie = new moviefile(p->last_save, newrom.get_internal_rom_type());
			} catch(std::exception& e) {
				messages << "Warning: Can't load last save: " << e.what() << std::endl;
				newmovie = new moviefile();
				fill_stub_movie(*newmovie, *p, newrom.get_internal_rom_type());
			}
		else {
			newmovie = new moviefile();
			fill_stub_movie(*newmovie, *p, newrom.get_internal_rom_type());
		}
		//Okay, loaded, load into core.
		newrom.load(p->settings, p->movie_rtc_second, p->movie_rtc_subsecond);
		rom = newrom;
		do_load_state(*newmovie, LOAD_STATE_DEFAULT, used);
skip_rom_movie:
		active_project = p;
		switched = true;
		//Calculate union of old and new.
		std::set<std::string> _watches = mwatch.enumerate();
		for(auto i : p->watches) _watches.insert(i.first);

		for(auto i : _watches)
			try {
				if(p->watches.count(i))
					mwatch.set(i, p->watches[i]);
				else
					mwatch.clear(i);
			} catch(std::exception& e) {
				messages << "Can't set/clear watch '" << i << "': " << e.what() << std::endl;
			}
		commentary.load_collection(p->directory + "/" + p->prefix + ".lsvs");
		command.invoke(CLUA::reset.name);
		for(auto i : p->luascripts)
			command.invoke(CLUA::run.name + (" " + i));
		buttons.load(controls, *active_project);
	} catch(std::exception& e) {
		if(newmovie && !used)
			delete newmovie;
		platform::error_message(std::string("Can't switch projects: ") + e.what());
		messages << "Can't switch projects: " << e.what() << std::endl;
	}
	if(switched) {
		do_flush_slotinfo();
		supdater.update();
		edispatch.core_change();
		edispatch.branch_change();
	}
	return switched;
}
CUDA_TEST_P(Hog_var_cell, HOG)
{
    cv::cuda::GpuMat _img(c_img);
    cv::cuda::GpuMat _img2(c_img2);
    cv::cuda::GpuMat _img3(c_img3);
    cv::cuda::GpuMat _img4(c_img4);
    cv::cuda::GpuMat d_img;

    ASSERT_FALSE(_img.empty());
    ASSERT_TRUE(d_img.empty());

    int win_stride_width = 8;int win_stride_height = 8;
    int win_width = 48;
    int block_width = 16;
    int block_stride_width = 8;int block_stride_height = 8;
    int cell_width = 8;
    int nbins = 9;

    Size win_stride(win_stride_width, win_stride_height);
    Size win_size(win_width, win_width * 2);
    Size block_size(block_width, block_width);
    Size block_stride(block_stride_width, block_stride_height);
    Size cell_size(cell_width, cell_width);

    cv::Ptr<cv::cuda::HOG> gpu_hog = cv::cuda::HOG::create(win_size, block_size, block_stride, cell_size, nbins);

    gpu_hog->setNumLevels(13);
    gpu_hog->setHitThreshold(0);
    gpu_hog->setWinStride(win_stride);
    gpu_hog->setScaleFactor(1.05);
    gpu_hog->setGroupThreshold(8);
    gpu_hog->compute(_img, d_img);
//------------------------------------------------------------------------------
    cv::cuda::GpuMat d_img2;
    ASSERT_TRUE(d_img2.empty());

    int win_stride_width2 = 8;int win_stride_height2 = 8;
    int win_width2 = 48;
    int block_width2 = 16;
    int block_stride_width2 = 8;int block_stride_height2 = 8;
    int cell_width2 = 4;

    Size win_stride2(win_stride_width2, win_stride_height2);
    Size win_size2(win_width2, win_width2 * 2);
    Size block_size2(block_width2, block_width2);
    Size block_stride2(block_stride_width2, block_stride_height2);
    Size cell_size2(cell_width2, cell_width2);

    cv::Ptr<cv::cuda::HOG> gpu_hog2 = cv::cuda::HOG::create(win_size2, block_size2, block_stride2, cell_size2, nbins);
    gpu_hog2->setWinStride(win_stride2);
    gpu_hog2->compute(_img, d_img2);
//------------------------------------------------------------------------------
    cv::cuda::GpuMat d_img3;
    ASSERT_TRUE(d_img3.empty());

    int win_stride_width3 = 9;int win_stride_height3 = 9;
    int win_width3 = 54;
    int block_width3 = 18;
    int block_stride_width3 = 9;int block_stride_height3 = 9;
    int cell_width3 = 6;

    Size win_stride3(win_stride_width3, win_stride_height3);
    Size win_size3(win_width3, win_width3 * 2);
    Size block_size3(block_width3, block_width3);
    Size block_stride3(block_stride_width3, block_stride_height3);
    Size cell_size3(cell_width3, cell_width3);

    cv::Ptr<cv::cuda::HOG> gpu_hog3 = cv::cuda::HOG::create(win_size3, block_size3, block_stride3, cell_size3, nbins);
    gpu_hog3->setWinStride(win_stride3);
    gpu_hog3->compute(_img2, d_img3);
//------------------------------------------------------------------------------
    cv::cuda::GpuMat d_img4;
    ASSERT_TRUE(d_img4.empty());

    int win_stride_width4 = 16;int win_stride_height4 = 16;
    int win_width4 = 64;
    int block_width4 = 32;
    int block_stride_width4 = 16;int block_stride_height4 = 16;
    int cell_width4 = 8;

    Size win_stride4(win_stride_width4, win_stride_height4);
    Size win_size4(win_width4, win_width4 * 2);
    Size block_size4(block_width4, block_width4);
    Size block_stride4(block_stride_width4, block_stride_height4);
    Size cell_size4(cell_width4, cell_width4);

    cv::Ptr<cv::cuda::HOG> gpu_hog4 = cv::cuda::HOG::create(win_size4, block_size4, block_stride4, cell_size4, nbins);
    gpu_hog4->setWinStride(win_stride4);
    gpu_hog4->compute(_img3, d_img4);
//------------------------------------------------------------------------------
    cv::cuda::GpuMat d_img5;
    ASSERT_TRUE(d_img5.empty());

    int win_stride_width5 = 16;int win_stride_height5 = 16;
    int win_width5 = 64;
    int block_width5 = 32;
    int block_stride_width5 = 16;int block_stride_height5 = 16;
    int cell_width5 = 16;

    Size win_stride5(win_stride_width5, win_stride_height5);
    Size win_size5(win_width5, win_width5 * 2);
    Size block_size5(block_width5, block_width5);
    Size block_stride5(block_stride_width5, block_stride_height5);
    Size cell_size5(cell_width5, cell_width5);

    cv::Ptr<cv::cuda::HOG> gpu_hog5 = cv::cuda::HOG::create(win_size5, block_size5, block_stride5, cell_size5, nbins);
    gpu_hog5->setWinStride(win_stride5);
    gpu_hog5->compute(_img3, d_img5);
//------------------------------------------------------------------------------
}