Implemented read/write methods for FlannBasedMatcher; fixed features2d wrappers for java
This commit is contained in:
@@ -23,7 +23,80 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
|
||||
DescriptorMatcher matcher;
|
||||
int matSize;
|
||||
DMatch[] truth;
|
||||
|
||||
static final String ymlParamsDefault = "%YAML:1.0\n"
|
||||
+ "indexParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: algorithm\n"
|
||||
+ " type: 23\n"
|
||||
+ " value: 1\n"
|
||||
+ " -\n"
|
||||
+ " name: trees\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 4\n"
|
||||
+ "searchParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: checks\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 32\n"
|
||||
+ " -\n"
|
||||
+ " name: eps\n"
|
||||
+ " type: 5\n"
|
||||
+ " value: 0.\n"
|
||||
+ " -\n"
|
||||
+ " name: sorted\n"
|
||||
+ " type: 15\n"
|
||||
+ " value: 1\n";
|
||||
|
||||
static final String xmlParamsDefault = "<?xml version=\"1.0\"?>\n"
|
||||
+ "<opencv_storage>\n"
|
||||
+ "<indexParams>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>algorithm</name>\n"
|
||||
+ " <type>23</type>\n"
|
||||
+ " <value>1</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>trees</name>\n"
|
||||
+ " <type>4</type>\n"
|
||||
+ " <value>4</value></_></indexParams>\n"
|
||||
+ "<searchParams>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>checks</name>\n"
|
||||
+ " <type>4</type>\n"
|
||||
+ " <value>32</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>eps</name>\n"
|
||||
+ " <type>5</type>\n"
|
||||
+ " <value>0.</value></_>\n"
|
||||
+ " <_>\n"
|
||||
+ " <name>sorted</name>\n"
|
||||
+ " <type>15</type>\n"
|
||||
+ " <value>1</value></_></searchParams>\n"
|
||||
+ "</opencv_storage>\n";
|
||||
|
||||
static final String ymlParamsModified = "%YAML:1.0\n"
|
||||
+ "indexParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: algorithm\n"
|
||||
+ " type: 23\n"
|
||||
+ " value: 6\n"//this line is changed
|
||||
+ " -\n"
|
||||
+ " name: trees\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 4\n"
|
||||
+ "searchParams:\n"
|
||||
+ " -\n"
|
||||
+ " name: checks\n"
|
||||
+ " type: 4\n"
|
||||
+ " value: 32\n"
|
||||
+ " -\n"
|
||||
+ " name: eps\n"
|
||||
+ " type: 5\n"
|
||||
+ " value: 0.\n"
|
||||
+ " -\n"
|
||||
+ " name: sorted\n"
|
||||
+ " type: 15\n"
|
||||
+ " value: 1\n";
|
||||
protected void setUp() throws Exception {
|
||||
matcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
|
||||
matSize = 100;
|
||||
@@ -91,6 +164,39 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
private Mat getBriefTrainImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Core.line(img, new Point(40, 40), new Point(matSize - 40, matSize - 40), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
private Mat getBriefQueryImg() {
|
||||
Mat img = new Mat(matSize, matSize, CvType.CV_8U, new Scalar(255));
|
||||
Core.line(img, new Point(40, matSize - 40), new Point(matSize - 50, 50), new Scalar(0), 8);
|
||||
return img;
|
||||
}
|
||||
|
||||
private Mat getBriefTestDescriptors(Mat img) {
|
||||
List<KeyPoint> keypoints = new ArrayList<KeyPoint>();
|
||||
Mat descriptors = new Mat();
|
||||
|
||||
FeatureDetector detector = FeatureDetector.create(FeatureDetector.FAST);
|
||||
DescriptorExtractor extractor = DescriptorExtractor.create(DescriptorExtractor.BRIEF);
|
||||
|
||||
detector.detect(img, keypoints);
|
||||
extractor.compute(img, keypoints, descriptors);
|
||||
|
||||
return descriptors;
|
||||
}
|
||||
|
||||
private Mat getBriefQueryDescriptors() {
|
||||
return getBriefTestDescriptors(getBriefQueryImg());
|
||||
}
|
||||
|
||||
private Mat getBriefTrainDescriptors() {
|
||||
return getBriefTestDescriptors(getBriefTrainImg());
|
||||
}
|
||||
|
||||
public void testAdd() {
|
||||
matcher.add(Arrays.asList(new Mat()));
|
||||
@@ -200,12 +306,21 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testRead() {
|
||||
fail("https://code.ros.org/trac/opencv/ticket/1253");
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
writeFile(filename, "%YAML:1.0\n");
|
||||
|
||||
writeFile(filename, ymlParamsModified);
|
||||
|
||||
matcher.read(filename);
|
||||
assertTrue(true);
|
||||
|
||||
Mat train = getBriefTrainDescriptors();
|
||||
Mat query = getBriefQueryDescriptors();
|
||||
List<DMatch> matches = new ArrayList<DMatch>();
|
||||
|
||||
matcher.match(query, train, matches);
|
||||
|
||||
assertListDMatchEquals(Arrays.asList(new DMatch (0, 0, 0, 0),
|
||||
new DMatch (1, 2, 0, 0),
|
||||
new DMatch (2, 1, 0, 0),
|
||||
new DMatch (3, 3, 0, 0)), matches, EPS);
|
||||
}
|
||||
|
||||
public void testTrain() {
|
||||
@@ -224,13 +339,19 @@ public class FlannBasedDescriptorMatcherTest extends OpenCVTestCase {
|
||||
}
|
||||
|
||||
public void testWrite() {
|
||||
fail("https://code.ros.org/trac/opencv/ticket/1253");
|
||||
String filename = OpenCVTestRunner.getTempFileName("xml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
assertEquals(xmlParamsDefault, readFile(filename));
|
||||
}
|
||||
|
||||
public void testWriteYml() {
|
||||
String filename = OpenCVTestRunner.getTempFileName("yml");
|
||||
|
||||
matcher.write(filename);
|
||||
|
||||
String truth = "%YAML:1.0\n!!!!!";
|
||||
assertEquals(truth, readFile(filename));
|
||||
assertEquals(ymlParamsDefault, readFile(filename));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -245,6 +245,7 @@ public:
|
||||
|
||||
OPPONENTEXTRACTOR = 1000,
|
||||
|
||||
|
||||
OPPONENT_SIFT = OPPONENTEXTRACTOR + SIFT,
|
||||
OPPONENT_SURF = OPPONENTEXTRACTOR + SURF,
|
||||
OPPONENT_ORB = OPPONENTEXTRACTOR + ORB,
|
||||
@@ -313,27 +314,27 @@ public:
|
||||
CV_WRAP virtual void clear();
|
||||
CV_WRAP virtual bool isMaskSupported();
|
||||
CV_WRAP virtual void train();
|
||||
CV_WRAP void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints ) const;
|
||||
CV_WRAP void classify( const Mat& queryImage, vector<KeyPoint>& queryKeypoints );
|
||||
CV_WRAP void classify( const Mat& queryImage, CV_IN_OUT vector<KeyPoint>& queryKeypoints );
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_OUT vector<DMatch>& matches, const Mat& mask=Mat() ) const;
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
vector<vector<DMatch> >& matches, int k,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
const Mat& trainImage, vector<KeyPoint>& trainKeypoints,
|
||||
vector<vector<DMatch> >& matches, float maxDistance,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const Mat& mask=Mat(), bool compactResult=false ) const;
|
||||
CV_WRAP void match( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
vector<DMatch>& matches, const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_OUT vector<DMatch>& matches, const vector<Mat>& masks=vector<Mat>() );
|
||||
CV_WRAP void knnMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
vector<vector<DMatch> >& matches, int k,
|
||||
CV_OUT vector<vector<DMatch> >& matches, int k,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP void radiusMatch( const Mat& queryImage, vector<KeyPoint>& queryKeypoints,
|
||||
vector<vector<DMatch> >& matches, float maxDistance,
|
||||
CV_OUT vector<vector<DMatch> >& matches, float maxDistance,
|
||||
const vector<Mat>& masks=vector<Mat>(), bool compactResult=false );
|
||||
CV_WRAP virtual bool empty() const;
|
||||
#endif
|
||||
@@ -411,7 +412,7 @@ CV_EXPORTS_W void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoint
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
const vector<char>& matchesMask=vector<char>(), int flags=0 );
|
||||
|
||||
CV_EXPORTS_W void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
CV_EXPORTS_AS(drawMatches2) void drawMatches( const Mat& img1, const vector<KeyPoint>& keypoints1,
|
||||
const Mat& img2, const vector<KeyPoint>& keypoints2,
|
||||
const vector<vector<DMatch> >& matches1to2, Mat& outImg,
|
||||
const Scalar& matchColor=Scalar::all(-1), const Scalar& singlePointColor=Scalar::all(-1),
|
||||
|
||||
Reference in New Issue
Block a user