cv::FeatureDetector * Settings::createFeaturesDetector()
{
	cv::FeatureDetector * detector = 0;
	QString str = getFeature2D_1Detector();
	QStringList split = str.split(':');
	if(split.size()==2)
	{
		bool ok = false;
		int index = split.first().toInt(&ok);
		if(ok)
		{
			QStringList strategies = split.last().split(';');
			if(strategies.size() == 9 && index>=0 && index<9)
			{
				switch(index)
				{
				case 0:
					if(strategies.at(index).compare("Dense") == 0)
					{
						detector = new cv::DenseFeatureDetector(
								getFeature2D_Dense_initFeatureScale(),
								getFeature2D_Dense_featureScaleLevels(),
								getFeature2D_Dense_featureScaleMul(),
								getFeature2D_Dense_initXyStep(),
								getFeature2D_Dense_initImgBound(),
								getFeature2D_Dense_varyXyStepWithScale(),
								getFeature2D_Dense_varyImgBoundWithScale());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Dense");
					}
					break;
				case 1:
					if(strategies.at(index).compare("Fast") == 0)
					{
						detector = new cv::FastFeatureDetector(
								getFeature2D_Fast_threshold(),
								getFeature2D_Fast_nonmaxSuppression());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Fast");
					}
					break;
				case 2:
					if(strategies.at(index).compare("GFTT") == 0)
					{
						detector = new cv::GFTTDetector(
								getFeature2D_GFTT_maxCorners(),
								getFeature2D_GFTT_qualityLevel(),
								getFeature2D_GFTT_minDistance(),
								getFeature2D_GFTT_blockSize(),
								getFeature2D_GFTT_useHarrisDetector(),
								getFeature2D_GFTT_k());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "GFTT");
					}
					break;
				case 3:
					if(strategies.at(index).compare("MSER") == 0)
					{
						detector = new cv::MSER(
								getFeature2D_MSER_delta(),
								getFeature2D_MSER_minArea(),
								getFeature2D_MSER_maxArea(),
								getFeature2D_MSER_maxVariation(),
								getFeature2D_MSER_minDiversity(),
								getFeature2D_MSER_maxEvolution(),
								getFeature2D_MSER_areaThreshold(),
								getFeature2D_MSER_minMargin(),
								getFeature2D_MSER_edgeBlurSize());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "MSER");
					}
					break;
				case 4:
					if(strategies.at(index).compare("ORB") == 0)
					{
						detector = new cv::ORB(
								getFeature2D_ORB_nFeatures(),
								getFeature2D_ORB_scaleFactor(),
								getFeature2D_ORB_nLevels(),
								getFeature2D_ORB_edgeThreshold(),
								getFeature2D_ORB_firstLevel(),
								getFeature2D_ORB_WTA_K(),
								getFeature2D_ORB_scoreType(),
								getFeature2D_ORB_patchSize());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "ORB");
					}
					break;
				case 5:
					if(strategies.at(index).compare("SIFT") == 0)
					{
						detector = new cv::SIFT(
								getFeature2D_SIFT_nfeatures(),
								getFeature2D_SIFT_nOctaveLayers(),
								getFeature2D_SIFT_contrastThreshold(),
								getFeature2D_SIFT_edgeThreshold(),
								getFeature2D_SIFT_sigma());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "SIFT");
					}
					break;
				case 6:
					if(strategies.at(index).compare("Star") == 0)
					{
						detector = new cv::StarFeatureDetector(
								getFeature2D_Star_maxSize(),
								getFeature2D_Star_responseThreshold(),
								getFeature2D_Star_lineThresholdProjected(),
								getFeature2D_Star_lineThresholdBinarized(),
								getFeature2D_Star_suppressNonmaxSize());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "Star");
					}
					break;
				case 7:
					if(strategies.at(index).compare("SURF") == 0)
					{
						detector = new cv::SURF(
								getFeature2D_SURF_hessianThreshold(),
								getFeature2D_SURF_nOctaves(),
								getFeature2D_SURF_nOctaveLayers(),
								getFeature2D_SURF_extended(),
								getFeature2D_SURF_upright());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "SURF");
					}
					break;
				case 8:
					if(strategies.at(index).compare("BRISK") == 0)
					{
						detector = new cv::BRISK(
								getFeature2D_BRISK_thresh(),
								getFeature2D_BRISK_octaves(),
								getFeature2D_BRISK_patternScale());
						if(VERBOSE)printf("Settings::createFeaturesDetector() type=%s\n", "BRISK");
					}
					break;
				default:
					break;
				}
			}
		}
	}
	if(!detector)
	{
		printf("ERROR: detector strategy not found !? Using default SURF...\n");
		detector = new cv::SURF();
	}
	return detector;
}
示例#2
0
KeypointDetector * Settings::createKeypointDetector()
{
	cv::FeatureDetector * detector = 0;
	GPUFeature2D * detectorGPU = 0;
	QString str = getFeature2D_1Detector();
	QStringList split = str.split(':');
	if(split.size()==2)
	{
		bool ok = false;
		int index = split.first().toInt(&ok);
		if(ok)
		{
			QStringList strategies = split.last().split(';');
			if(strategies.size() == 9 && index>=0 && index<9)
			{
				switch(index)
				{
				case 0:
					if(strategies.at(index).compare("Dense") == 0)
					{
						detector = new cv::DenseFeatureDetector(
								getFeature2D_Dense_initFeatureScale(),
								getFeature2D_Dense_featureScaleLevels(),
								getFeature2D_Dense_featureScaleMul(),
								getFeature2D_Dense_initXyStep(),
								getFeature2D_Dense_initImgBound(),
								getFeature2D_Dense_varyXyStepWithScale(),
								getFeature2D_Dense_varyImgBoundWithScale());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				case 1:
					if(strategies.at(index).compare("Fast") == 0)
					{
						if(getFeature2D_Fast_gpu() && cv::gpu::getCudaEnabledDeviceCount())
						{
							detectorGPU = new GPUFAST(
									getFeature2D_Fast_threshold(),
									getFeature2D_Fast_nonmaxSuppression());
							UDEBUG("type=%s GPU", strategies.at(index).toStdString().c_str());
						}
						else
						{
							detector = new cv::FastFeatureDetector(
									getFeature2D_Fast_threshold(),
									getFeature2D_Fast_nonmaxSuppression());
							UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
						}
					}
					break;
				case 2:
					if(strategies.at(index).compare("GFTT") == 0)
					{
						detector = new cv::GFTTDetector(
								getFeature2D_GFTT_maxCorners(),
								getFeature2D_GFTT_qualityLevel(),
								getFeature2D_GFTT_minDistance(),
								getFeature2D_GFTT_blockSize(),
								getFeature2D_GFTT_useHarrisDetector(),
								getFeature2D_GFTT_k());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				case 3:
					if(strategies.at(index).compare("MSER") == 0)
					{
						detector = new cv::MSER(
								getFeature2D_MSER_delta(),
								getFeature2D_MSER_minArea(),
								getFeature2D_MSER_maxArea(),
								getFeature2D_MSER_maxVariation(),
								getFeature2D_MSER_minDiversity(),
								getFeature2D_MSER_maxEvolution(),
								getFeature2D_MSER_areaThreshold(),
								getFeature2D_MSER_minMargin(),
								getFeature2D_MSER_edgeBlurSize());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				case 4:
					if(strategies.at(index).compare("ORB") == 0)
					{
						if(getFeature2D_ORB_gpu() && cv::gpu::getCudaEnabledDeviceCount())
						{
							detectorGPU = new GPUORB(
									getFeature2D_ORB_nFeatures(),
									getFeature2D_ORB_scaleFactor(),
									getFeature2D_ORB_nLevels(),
									getFeature2D_ORB_edgeThreshold(),
									getFeature2D_ORB_firstLevel(),
									getFeature2D_ORB_WTA_K(),
									getFeature2D_ORB_scoreType(),
									getFeature2D_ORB_patchSize(),
									getFeature2D_Fast_threshold(),
									getFeature2D_Fast_nonmaxSuppression());
							UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
						}
						else
						{
							detector = new cv::ORB(
									getFeature2D_ORB_nFeatures(),
									getFeature2D_ORB_scaleFactor(),
									getFeature2D_ORB_nLevels(),
									getFeature2D_ORB_edgeThreshold(),
									getFeature2D_ORB_firstLevel(),
									getFeature2D_ORB_WTA_K(),
									getFeature2D_ORB_scoreType(),
									getFeature2D_ORB_patchSize());
							UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
						}
					}
					break;
				case 5:
					if(strategies.at(index).compare("SIFT") == 0)
					{
						detector = new cv::SIFT(
								getFeature2D_SIFT_nfeatures(),
								getFeature2D_SIFT_nOctaveLayers(),
								getFeature2D_SIFT_contrastThreshold(),
								getFeature2D_SIFT_edgeThreshold(),
								getFeature2D_SIFT_sigma());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				case 6:
					if(strategies.at(index).compare("Star") == 0)
					{
						detector = new cv::StarFeatureDetector(
								getFeature2D_Star_maxSize(),
								getFeature2D_Star_responseThreshold(),
								getFeature2D_Star_lineThresholdProjected(),
								getFeature2D_Star_lineThresholdBinarized(),
								getFeature2D_Star_suppressNonmaxSize());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				case 7:
					if(strategies.at(index).compare("SURF") == 0)
					{
						if(getFeature2D_SURF_gpu() && cv::gpu::getCudaEnabledDeviceCount())
						{
							detectorGPU = new GPUSURF(
									getFeature2D_SURF_hessianThreshold(),
									getFeature2D_SURF_nOctaves(),
									getFeature2D_SURF_nOctaveLayers(),
									getFeature2D_SURF_extended(),
									getFeature2D_SURF_keypointsRatio(),
									getFeature2D_SURF_upright());
							UDEBUG("type=%s (GPU)", strategies.at(index).toStdString().c_str());
						}
						else
						{
							detector = new cv::SURF(
								getFeature2D_SURF_hessianThreshold(),
								getFeature2D_SURF_nOctaves(),
								getFeature2D_SURF_nOctaveLayers(),
								getFeature2D_SURF_extended(),
								getFeature2D_SURF_upright());
							UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
						}
					}
					break;
				case 8:
					if(strategies.at(index).compare("BRISK") == 0)
					{
						detector = new cv::BRISK(
								getFeature2D_BRISK_thresh(),
								getFeature2D_BRISK_octaves(),
								getFeature2D_BRISK_patternScale());
						UDEBUG("type=%s", strategies.at(index).toStdString().c_str());
					}
					break;
				default:
					break;
				}
			}
		}
	}

	Q_ASSERT(detectorGPU!=0 || detector!=0);
	if(detectorGPU)
	{
		return new KeypointDetector(detectorGPU);
	}
	else
	{
		return new KeypointDetector(detector);
	}
}