Java Code Examples for org.opencv.features2d.DescriptorMatcher

The following are top voted examples for showing how to use org.opencv.features2d.DescriptorMatcher. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: zooracle   File: KMeansMatcher.java   Source Code and License 5 votes vote down vote up
public KMeansMatcher()
{
	model = null;
	featureDetector = FeatureDetector.create(FeatureDetector.PYRAMID_ORB);
	descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
	matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_SL2);
}
 
Example 2
Project: second_eyes   File: ExtractPath.java   Source Code and License 5 votes vote down vote up
public ExtractPath() {
    super();

    mKeyPointsPrev = new MatOfKeyPoint();
    // set up feature detection
    try {
        mFeatureDectector = FeatureDetector.create(FeatureDetector.FAST);
    } catch (UnsatisfiedLinkError err) {
        Log.e(TAG, "Feature detector failed with");
        err.printStackTrace();
    }
    // set up description detection
    mDescExtractor = DescriptorExtractor.create(DescriptorExtractor.BRISK);
    mDescMatcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

    mPrevFrame = new Mat();
    prevKeyPoints = new MatOfKeyPoint();
    RGBFrame = new Mat();
    mForeGroundMask = new Mat();
    mContours = new ArrayList<MatOfPoint>();
    //creates a new BackgroundSubtractorMOG class with the arguments
    mBackgroundSub = Video.createBackgroundSubtractorMOG2(50, 0, true);
}
 
Example 3
Project: SmartObjectRecognition   File: SmartObjectRecognitionActivity.java   Source Code and License 5 votes vote down vote up
public int getDescriptorMatcherType(String matcherName){
		
	if(matcherName.equals("BruteForce")){
		return DescriptorMatcher.BRUTEFORCE;
	}else if(matcherName.equals("BruteForce-L1")){
		return DescriptorMatcher.BRUTEFORCE_L1;
	}else if(matcherName.equals("BruteForce-Hamming")){
		return DescriptorMatcher.BRUTEFORCE_HAMMING;
	}else if(matcherName.equals("FlannBased")){
		return DescriptorMatcher.FLANNBASED;
	}else if(matcherName.equals("BruteForche-Hamming LUT")){
		return DescriptorMatcher.BRUTEFORCE_HAMMINGLUT;			
	}else  if(matcherName.equals("BruteForce SL2")){
		return DescriptorMatcher.BRUTEFORCE_SL2;			
	} else {
		return 0;
	}
	
}
 
Example 4
Project: StormCV   File: FeatureMatcherOp.java   Source Code and License 5 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
protected void prepareOpenCVOp(Map conf, TopologyContext context) throws Exception {
	this.connectorHolder = new ConnectorHolder(conf);
	matcher = DescriptorMatcher.create( matcherType );
	prototypes = new HashMap<Mat, String>();
	
	for(String location : protoLocations){
		FileConnector fc = connectorHolder.getConnector(location);
		fc.setExtensions(ext);
		fc.moveTo(location);
		List<String> images = fc.list();
		for(String img : images){
			fc.moveTo(img);
			File imageFile = fc.getAsFile();
			Mat proto = calculateDescriptors(ImageIO.read(imageFile));
			prototypes.put(proto, img.substring(img.lastIndexOf('/')+1));
			logger.info("Prototype "+img+" loaded and prepared for matching");
			if(!(fc instanceof LocalFileConnector)) imageFile.delete();
		}
	}
}
 
Example 5
Project: enchantment   File: ImageMatcher.java   Source Code and License 5 votes vote down vote up
public static MatchData findMatches(FeatureData referenceData,
		FeatureData actualData) {
	DescriptorMatcher matcher = DescriptorMatcher
			.create(DescriptorMatcher.BRUTEFORCE);
	List<MatOfDMatch> matches = new ArrayList<MatOfDMatch>();
	matcher.knnMatch(referenceData.descriptors, actualData.descriptors,
			matches, 2);
	ArrayList<KeyPoint> objectPoints = new ArrayList<KeyPoint>(), imagePoints = new ArrayList<KeyPoint>();
	for (MatOfDMatch match : matches) {
		DMatch[] dmatches = match.toArray();
		if (dmatches.length == 2
				&& dmatches[0].distance < dmatches[1].distance * 0.75) {
			imagePoints
					.add(referenceData.keypoints.toArray()[dmatches[0].queryIdx]);
			objectPoints
					.add(actualData.keypoints.toArray()[dmatches[0].trainIdx]);
		}
	}
	float ratio = ((float) objectPoints.size())
			/ ((float) actualData.keypoints.size().width);
	return new MatchData(objectPoints, imagePoints, ratio);
}
 
Example 6
Project: RobotIGS   File: ObjectDetection.java   Source Code and License 4 votes vote down vote up
/**
 * Instantiate an object detector based on the FAST, BRIEF, and BRUTEFORCE_HAMMING algorithms
 */
public ObjectDetection() {
    detector = FeatureDetector.create(FeatureDetectorType.FAST.val());
    extractor = DescriptorExtractor.create(DescriptorExtractorType.BRIEF.val());
    matcher = DescriptorMatcher.create(DescriptorMatcherType.BRUTEFORCE_HAMMING.val());
}
 
Example 7
Project: OpencvAndroid   File: MainActivity.java   Source Code and License 4 votes vote down vote up
private void initializeOpenCVDependencies() throws IOException {
    mOpenCvCameraView.enableView();
    detector = FeatureDetector.create(FeatureDetector.ORB);
    descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);
    img1 = new Mat();
    AssetManager assetManager = getAssets();
    InputStream istr = assetManager.open("a.jpeg");
    Bitmap bitmap = BitmapFactory.decodeStream(istr);
    Utils.bitmapToMat(bitmap, img1);
    Imgproc.cvtColor(img1, img1, Imgproc.COLOR_RGB2GRAY);
    img1.convertTo(img1, 0); //converting the image to match with the type of the cameras image
    descriptors1 = new Mat();
    keypoints1 = new MatOfKeyPoint();
    detector.detect(img1, keypoints1);
    descriptor.compute(img1, keypoints1, descriptors1);

}
 
Example 8
Project: 2016-FTC   File: ObjectDetection.java   Source Code and License 4 votes vote down vote up
/**
 * Instantiate an object detector based on the FAST, BRIEF, and BRUTEFORCE_HAMMING algorithms
 */
public ObjectDetection() {
    detector = FeatureDetector.create(FeatureDetectorType.FAST.val());
    extractor = DescriptorExtractor.create(DescriptorExtractorType.BRIEF.val());
    matcher = DescriptorMatcher.create(DescriptorMatcherType.BRUTEFORCE_HAMMING.val());
}
 
Example 9
Project: OpenCVTour   File: ImageDetector.java   Source Code and License 4 votes vote down vote up
public ImageDetector() {
	this(FeatureDetector.ORB, DescriptorExtractor.ORB, DescriptorMatcher.BRUTEFORCE_HAMMINGLUT);
}
 
Example 10
Project: OpenCVTour   File: ImageDetector.java   Source Code and License 4 votes vote down vote up
public ImageDetector(int detector_type, int extractor_type, int matcher_type)
{
	fDetector = FeatureDetector.create
			(detector_type);
	dExtractor = DescriptorExtractor.create
			(extractor_type);
	dMatcher= DescriptorMatcher.create
			(matcher_type);
	training_library= new ArrayList<TrainingImage>();
	
	// Specific values selected after experimenting with different data sets
	max_side = 300;
	filter_ratio = 5;
	distance_bound = 50;
}
 
Example 11
Project: FTCVision   File: ObjectDetection.java   Source Code and License 4 votes vote down vote up
/**
 * Instantiate an object detector based on the FAST, BRIEF, and BRUTEFORCE_HAMMING algorithms
 */
public ObjectDetection() {
    detector = FeatureDetector.create(FeatureDetectorType.FAST.val());
    extractor = DescriptorExtractor.create(DescriptorExtractorType.BRIEF.val());
    matcher = DescriptorMatcher.create(DescriptorMatcherType.BRUTEFORCE_HAMMING.val());
}
 
Example 12
Project: StormCV   File: PartialMatcher.java   Source Code and License 4 votes vote down vote up
@SuppressWarnings("rawtypes")
@Override
protected void prepareOpenCVOp(Map conf, TopologyContext context) throws Exception {
	this.connectorHolder = new ConnectorHolder(conf);
	matcher = DescriptorMatcher.create( matcherType );
	prototypes = new HashMap<Integer, String>();
	
	int nrTasks = context.getComponentTasks(context.getThisComponentId()).size();
	int taskIndex = context.getThisTaskIndex();
	
	List<String> original = new ArrayList<String>();
	original.addAll(protoLocations);
	protoLocations.clear();
	for(String dir : original){
		protoLocations.addAll(expand(dir));
	}
	
	FileConnector fc = null;
	List<Mat> training = new ArrayList<Mat>();
	for(int i=taskIndex; i<protoLocations.size(); i+=nrTasks){
		String imgFile = protoLocations.get(i);
		fc = connectorHolder.getConnector(imgFile);
		fc.moveTo(imgFile);
		File imageFile = fc.getAsFile();
		BufferedImage img = ImageIO.read(imageFile);
		if(img == null) continue;
		Mat proto = calculateDescriptors(img);
		prototypes.put(training.size(), imgFile.substring(imgFile.lastIndexOf('/')+1));
		training.add(proto);
		logger.info(this.getClass().getName()+"["+taskIndex+"] "+imgFile+" loaded and prepared for matching");
		if(!(fc instanceof LocalFileConnector)) imageFile.delete();
	}
	matcher.add(training);
	matcher.train();
}
 
Example 13
Project: FTC2016   File: ObjectDetection.java   Source Code and License 3 votes vote down vote up
/**
 * Instantiate an object detector based on the FAST, BRIEF, and BRUTEFORCE_HAMMING algorithms
 */
public ObjectDetection() {
    detector = FeatureDetector.create(FeatureDetectorType.FAST.val());
    extractor = DescriptorExtractor.create(DescriptorExtractorType.BRIEF.val());
    matcher = DescriptorMatcher.create(DescriptorMatcherType.BRUTEFORCE_HAMMING.val());
}
 
Example 14
Project: FTC2016   File: ObjectDetection.java   Source Code and License 3 votes vote down vote up
/**
 * Instantiate an object detector based on custom algorithms
 *
 * @param detector  Keypoint detection algorithm
 * @param extractor Keypoint descriptor extractor
 * @param matcher   Descriptor matcher
 */
public ObjectDetection(FeatureDetectorType detector, DescriptorExtractorType extractor, DescriptorMatcherType matcher) {
    this.detector = FeatureDetector.create(detector.val());
    this.extractor = DescriptorExtractor.create(extractor.val());
    this.matcher = DescriptorMatcher.create(matcher.val());
}
 
Example 15
Project: RobotIGS   File: ObjectDetection.java   Source Code and License 2 votes vote down vote up
/**
 * Instantiate an object detector based on custom algorithms
 *
 * @param detector  Keypoint detection algorithm
 * @param extractor Keypoint descriptor extractor
 * @param matcher   Descriptor matcher
 */
public ObjectDetection(FeatureDetectorType detector, DescriptorExtractorType extractor, DescriptorMatcherType matcher) {
    this.detector = FeatureDetector.create(detector.val());
    this.extractor = DescriptorExtractor.create(extractor.val());
    this.matcher = DescriptorMatcher.create(matcher.val());
}
 
Example 16
Project: 2016-FTC   File: ObjectDetection.java   Source Code and License 2 votes vote down vote up
/**
 * Instantiate an object detector based on custom algorithms
 *
 * @param detector  Keypoint detection algorithm
 * @param extractor Keypoint descriptor extractor
 * @param matcher   Descriptor matcher
 */
public ObjectDetection(FeatureDetectorType detector, DescriptorExtractorType extractor, DescriptorMatcherType matcher) {
    this.detector = FeatureDetector.create(detector.val());
    this.extractor = DescriptorExtractor.create(extractor.val());
    this.matcher = DescriptorMatcher.create(matcher.val());
}
 
Example 17
Project: FTCVision   File: ObjectDetection.java   Source Code and License 2 votes vote down vote up
/**
 * Instantiate an object detector based on custom algorithms
 *
 * @param detector  Keypoint detection algorithm
 * @param extractor Keypoint descriptor extractor
 * @param matcher   Descriptor matcher
 */
public ObjectDetection(FeatureDetectorType detector, DescriptorExtractorType extractor, DescriptorMatcherType matcher) {
    this.detector = FeatureDetector.create(detector.val());
    this.extractor = DescriptorExtractor.create(extractor.val());
    this.matcher = DescriptorMatcher.create(matcher.val());
}