diff --git a/examples/matching_to_many_images.rb b/examples/matching_to_many_images.rb index b96b652..301570d 100644 --- a/examples/matching_to_many_images.rb +++ b/examples/matching_to_many_images.rb @@ -9,7 +9,7 @@ image_files = ['1.png', '2.png', '3.png'].map{|f| File.join(data, 'train', f)} images = image_files.map{|f| IplImage.load f, CV_LOAD_IMAGE_GRAYSCALE} -matchs = query.match_descriptors("SURF", "SURF", "FlannBased", images) +matchs = query.match_descriptors(images) match_index, count = matchs.max_by {|image_index, count| count} diff --git a/ext/opencv/cvmat.cpp b/ext/opencv/cvmat.cpp index 621725e..c0cce91 100644 --- a/ext/opencv/cvmat.cpp +++ b/ext/opencv/cvmat.cpp @@ -5333,21 +5333,34 @@ rb_match_shapes(int argc, VALUE *argv, VALUE self) /** * Port from OpenCV sample: matching_to_many_images.cpp * call-seq: - * match_descriptors(detector_type, descriptor_type, matcher_type, images) -> Hash + * match_descriptors(images[, detector_type="SURF"][, descriptor_type="SURF"][, matcher_type="FlannBased"]) -> Hash * - * Matching descriptors detected on one image to descriptors detected in image set. + * Matching descriptors detected on one image to descriptors detected in image array. * Returns a Hash contains match count of each image index. + * For example, a Hash {0 => 5, 2 => 10} means the images[0] has 5 key points matched, images[2] has 10 key points matched, + * and all of other images in the images array have no key point matched. + * Hence images[2] is the best match in general. * - * detector_type is a string, options: "SURF" - * descriptor_type is a string, options: "SURF" - * matcher_type is a string, options: "FlannBased" * images is an array of CvMat objects. + * detector_type is a string, default is "SURF", options: "SURF", "FAST", "SIFT", "STAR" + * descriptor_type is a string, default is "SURF", options: "SURF", "SIFT", "BRIEF" + * matcher_type is a string, default is "FlannBased", options: "FlannBased", "BruteForce" */ VALUE rb_match_descriptors(int argc, VALUE *argv, VALUE self) { - VALUE detectorType, descriptorType, matcherType, images; - rb_scan_args(argc, argv, "40", &detectorType, &descriptorType, &matcherType, &images); + VALUE images, detector_type, descriptor_type, matcher_type; + rb_scan_args(argc, argv, "13", &images, &detector_type, &descriptor_type, &matcher_type); + + if (NIL_P(detector_type)) { + detector_type = rb_str_new2("SURF"); + } + if (NIL_P(descriptor_type)) { + descriptor_type = rb_str_new2("SURF"); + } + if (NIL_P(matcher_type)) { + matcher_type = rb_str_new2("FlannBased"); + } cv::Mat queryImage = CVMAT(self); std::vector trainImages; @@ -5356,9 +5369,9 @@ rb_match_descriptors(int argc, VALUE *argv, VALUE self) } // todo: validation - cv::Ptr featureDetector = cv::FeatureDetector::create(RSTRING_PTR(detectorType)); - cv::Ptr descriptorExtractor = cv::DescriptorExtractor::create(RSTRING_PTR(descriptorType)); - cv::Ptr descriptorMatcher = cv::DescriptorMatcher::create(RSTRING_PTR(matcherType)); + cv::Ptr featureDetector = cv::FeatureDetector::create(RSTRING_PTR(detector_type)); + cv::Ptr descriptorExtractor = cv::DescriptorExtractor::create(RSTRING_PTR(descriptor_type)); + cv::Ptr descriptorMatcher = cv::DescriptorMatcher::create(RSTRING_PTR(matcher_type)); std::vector queryKeypoints; std::vector > trainKeypoints;