Example usage for org.opencv.core MatOfDMatch fromArray

List of usage examples for org.opencv.core MatOfDMatch fromArray

Introduction

In this page you can find the example usage for org.opencv.core MatOfDMatch fromArray.

Prototype

public void fromArray(DMatch... a) 

Source Link

Usage

From source file:Recognizer.Recognizer.java

public void SIFT(Image imQ, Image imDB) {
    Mat Q = imQ.Image1CtoMat_CV();
    Mat DB = imDB.Image1CtoMat_CV();

    Mat matQ = new Mat();
    Mat matDB = new Mat();

    Q.convertTo(matQ, CvType.CV_8U);/*from   w  w  w.  j a v  a  2 s. co m*/
    DB.convertTo(matDB, CvType.CV_8U);

    FeatureDetector siftDet = FeatureDetector.create(FeatureDetector.SIFT);
    DescriptorExtractor siftExt = DescriptorExtractor.create(DescriptorExtractor.SIFT);

    MatOfKeyPoint kpQ = new MatOfKeyPoint();
    MatOfKeyPoint kpDB = new MatOfKeyPoint();

    siftDet.detect(matQ, kpQ);
    siftDet.detect(matDB, kpDB);

    Mat matDescriptorQ = new Mat(matQ.rows(), matQ.cols(), matQ.type());
    Mat matDescriptorDB = new Mat(matDB.rows(), matDB.cols(), matDB.type());

    siftExt.compute(matQ, kpQ, matDescriptorQ);
    siftExt.compute(matDB, kpDB, matDescriptorDB);

    MatOfDMatch matchs = new MatOfDMatch();

    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE);

    matcher.match(matDescriptorQ, matDescriptorDB, matchs);

    int N = 10;

    DMatch[] tmp01 = matchs.toArray();
    DMatch[] tmp02 = new DMatch[N];

    for (int i = 0; i < tmp02.length; i++) {
        tmp02[i] = tmp01[i];
    }

    matchs.fromArray(tmp02);

    Mat matchedImage = new Mat(matQ.rows(), matQ.cols() * 2, matQ.type());
    Features2d.drawMatches(matQ, kpQ, matDB, kpDB, matchs, matchedImage);

    Highgui.imwrite("./descriptedImageBySIFT.jpg", matchedImage);

}