diff --git a/modules/xfeatures2d/doc/xfeatures2d.bib b/modules/xfeatures2d/doc/xfeatures2d.bib index 7d3f146cb94..82836369ea3 100644 --- a/modules/xfeatures2d/doc/xfeatures2d.bib +++ b/modules/xfeatures2d/doc/xfeatures2d.bib @@ -172,4 +172,23 @@ @inproceedings{winder2007learning booktitle= {Computer Vision and Pattern Recognition}, pages={1--8}, year={2007}, +} + +@incollection{ABD12, + author = {Alcantarilla, Pablo Fern{\'a}ndez and Bartoli, Adrien and Davison, Andrew J}, + title = {KAZE features}, + booktitle = {Computer Vision--ECCV 2012}, + year = {2012}, + pages = {214--227}, + publisher = {Springer}, + url = {https://www.doc.ic.ac.uk/~ajd/Publications/alcantarilla_etal_eccv2012.pdf} +} + +@inproceedings{LCS11, + author = {Leutenegger, Stefan and Chli, Margarita and Siegwart, Roland Yves}, + title = {BRISK: Binary robust invariant scalable keypoints}, + booktitle = {Computer Vision (ICCV), 2011 IEEE International Conference on}, + year = {2011}, + pages = {2548--2555}, + publisher = {IEEE} } \ No newline at end of file diff --git a/modules/xfeatures2d/misc/objc/gen_dict.json b/modules/xfeatures2d/misc/objc/gen_dict.json index bcc66bc6980..f8fc4d4f1c4 100644 --- a/modules/xfeatures2d/misc/objc/gen_dict.json +++ b/modules/xfeatures2d/misc/objc/gen_dict.json @@ -15,7 +15,6 @@ } }, "enum_fix" : { - "FastFeatureDetector" : { "DetectorType": "FastDetectorType" }, "AgastFeatureDetector" : { "DetectorType": "AgastDetectorType" } } } diff --git a/modules/xfeatures2d/samples/AKAZE_match.cpp b/modules/xfeatures2d/samples/AKAZE_match.cpp deleted file mode 100644 index 353135740e0..00000000000 --- a/modules/xfeatures2d/samples/AKAZE_match.cpp +++ /dev/null @@ -1,99 +0,0 @@ -#include -#include "opencv2/xfeatures2d.hpp" -#include -#include -#include - -using namespace std; -using namespace cv; - -const float inlier_threshold = 2.5f; // Distance threshold to identify inliers with homography check -const float nn_match_ratio = 0.8f; // Nearest neighbor matching ratio - -int main(int argc, char* argv[]) -{ - //! [load] - CommandLineParser parser(argc, argv, - "{@img1 | graf1.png | input image 1}" - "{@img2 | graf3.png | input image 2}" - "{@homography | H1to3p.xml | homography matrix}"); - Mat img1 = imread( samples::findFile( parser.get("@img1") ), IMREAD_GRAYSCALE); - Mat img2 = imread( samples::findFile( parser.get("@img2") ), IMREAD_GRAYSCALE); - - Mat homography; - FileStorage fs( samples::findFile( parser.get("@homography") ), FileStorage::READ); - fs.getFirstTopLevelNode() >> homography; - //! [load] - - //! [AKAZE] - vector kpts1, kpts2; - Mat desc1, desc2; - - Ptr akaze = xfeatures2d::AKAZE::create(); - akaze->detectAndCompute(img1, noArray(), kpts1, desc1); - akaze->detectAndCompute(img2, noArray(), kpts2, desc2); - //! [AKAZE] - - //! [2-nn matching] - BFMatcher matcher(NORM_HAMMING); - vector< vector > nn_matches; - matcher.knnMatch(desc1, desc2, nn_matches, 2); - //! [2-nn matching] - - //! [ratio test filtering] - vector matched1, matched2; - for(size_t i = 0; i < nn_matches.size(); i++) { - DMatch first = nn_matches[i][0]; - float dist1 = nn_matches[i][0].distance; - float dist2 = nn_matches[i][1].distance; - - if(dist1 < nn_match_ratio * dist2) { - matched1.push_back(kpts1[first.queryIdx]); - matched2.push_back(kpts2[first.trainIdx]); - } - } - //! [ratio test filtering] - - //! [homography check] - vector good_matches; - vector inliers1, inliers2; - for(size_t i = 0; i < matched1.size(); i++) { - Mat col = Mat::ones(3, 1, CV_64F); - col.at(0) = matched1[i].pt.x; - col.at(1) = matched1[i].pt.y; - - col = homography * col; - col /= col.at(2); - double dist = sqrt( pow(col.at(0) - matched2[i].pt.x, 2) + - pow(col.at(1) - matched2[i].pt.y, 2)); - - if(dist < inlier_threshold) { - int new_i = static_cast(inliers1.size()); - inliers1.push_back(matched1[i]); - inliers2.push_back(matched2[i]); - good_matches.push_back(DMatch(new_i, new_i, 0)); - } - } - //! [homography check] - - //! [draw final matches] - Mat res; - drawMatches(img1, inliers1, img2, inliers2, good_matches, res); - imwrite("akaze_result.png", res); - - double inlier_ratio = inliers1.size() / (double) matched1.size(); - cout << "A-KAZE Matching Results" << endl; - cout << "*******************************" << endl; - cout << "# Keypoints 1: \t" << kpts1.size() << endl; - cout << "# Keypoints 2: \t" << kpts2.size() << endl; - cout << "# Matches: \t" << matched1.size() << endl; - cout << "# Inliers: \t" << inliers1.size() << endl; - cout << "# Inliers Ratio: \t" << inlier_ratio << endl; - cout << endl; - - imshow("result", res); - waitKey(); - //! [draw final matches] - - return 0; -} diff --git a/modules/xfeatures2d/samples/java/tutorial_code/akaze_matching/AKAZEMatchDemo.java b/modules/xfeatures2d/samples/java/tutorial_code/akaze_matching/AKAZEMatchDemo.java deleted file mode 100644 index 818ad73de3d..00000000000 --- a/modules/xfeatures2d/samples/java/tutorial_code/akaze_matching/AKAZEMatchDemo.java +++ /dev/null @@ -1,163 +0,0 @@ -import java.io.File; -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import javax.xml.parsers.ParserConfigurationException; - -import org.opencv.core.Core; -import org.opencv.core.CvType; -import org.opencv.core.DMatch; -import org.opencv.core.KeyPoint; -import org.opencv.core.Mat; -import org.opencv.core.MatOfDMatch; -import org.opencv.core.MatOfKeyPoint; -import org.opencv.core.Scalar; -import org.opencv.xfeatures2d.AKAZE; -import org.opencv.features2d.DescriptorMatcher; -import org.opencv.features2d.Features2d; -import org.opencv.highgui.HighGui; -import org.opencv.imgcodecs.Imgcodecs; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -class AKAZEMatch { - public void run(String[] args) { - //! [load] - String filename1 = args.length > 2 ? args[0] : "../data/graf1.png"; - String filename2 = args.length > 2 ? args[1] : "../data/graf3.png"; - String filename3 = args.length > 2 ? args[2] : "../data/H1to3p.xml"; - Mat img1 = Imgcodecs.imread(filename1, Imgcodecs.IMREAD_GRAYSCALE); - Mat img2 = Imgcodecs.imread(filename2, Imgcodecs.IMREAD_GRAYSCALE); - if (img1.empty() || img2.empty()) { - System.err.println("Cannot read images!"); - System.exit(0); - } - - File file = new File(filename3); - DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance(); - DocumentBuilder documentBuilder; - Document document; - Mat homography = new Mat(3, 3, CvType.CV_64F); - double[] homographyData = new double[(int) (homography.total()*homography.channels())]; - try { - documentBuilder = documentBuilderFactory.newDocumentBuilder(); - document = documentBuilder.parse(file); - String homographyStr = document.getElementsByTagName("data").item(0).getTextContent(); - String[] splited = homographyStr.split("\\s+"); - int idx = 0; - for (String s : splited) { - if (!s.isEmpty()) { - homographyData[idx] = Double.parseDouble(s); - idx++; - } - } - } catch (ParserConfigurationException e) { - e.printStackTrace(); - System.exit(0); - } catch (SAXException e) { - e.printStackTrace(); - System.exit(0); - } catch (IOException e) { - e.printStackTrace(); - System.exit(0); - } - homography.put(0, 0, homographyData); - //! [load] - - //! [AKAZE] - AKAZE akaze = AKAZE.create(); - MatOfKeyPoint kpts1 = new MatOfKeyPoint(), kpts2 = new MatOfKeyPoint(); - Mat desc1 = new Mat(), desc2 = new Mat(); - akaze.detectAndCompute(img1, new Mat(), kpts1, desc1); - akaze.detectAndCompute(img2, new Mat(), kpts2, desc2); - //! [AKAZE] - - //! [2-nn matching] - DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING); - List knnMatches = new ArrayList<>(); - matcher.knnMatch(desc1, desc2, knnMatches, 2); - //! [2-nn matching] - - //! [ratio test filtering] - float ratioThreshold = 0.8f; // Nearest neighbor matching ratio - List listOfMatched1 = new ArrayList<>(); - List listOfMatched2 = new ArrayList<>(); - List listOfKeypoints1 = kpts1.toList(); - List listOfKeypoints2 = kpts2.toList(); - for (int i = 0; i < knnMatches.size(); i++) { - DMatch[] matches = knnMatches.get(i).toArray(); - float dist1 = matches[0].distance; - float dist2 = matches[1].distance; - if (dist1 < ratioThreshold * dist2) { - listOfMatched1.add(listOfKeypoints1.get(matches[0].queryIdx)); - listOfMatched2.add(listOfKeypoints2.get(matches[0].trainIdx)); - } - } - //! [ratio test filtering] - - //! [homography check] - double inlierThreshold = 2.5; // Distance threshold to identify inliers with homography check - List listOfInliers1 = new ArrayList<>(); - List listOfInliers2 = new ArrayList<>(); - List listOfGoodMatches = new ArrayList<>(); - for (int i = 0; i < listOfMatched1.size(); i++) { - Mat col = new Mat(3, 1, CvType.CV_64F); - double[] colData = new double[(int) (col.total() * col.channels())]; - colData[0] = listOfMatched1.get(i).pt.x; - colData[1] = listOfMatched1.get(i).pt.y; - colData[2] = 1.0; - col.put(0, 0, colData); - - Mat colRes = new Mat(); - Core.gemm(homography, col, 1.0, new Mat(), 0.0, colRes); - colRes.get(0, 0, colData); - Core.multiply(colRes, new Scalar(1.0 / colData[2]), col); - col.get(0, 0, colData); - - double dist = Math.sqrt(Math.pow(colData[0] - listOfMatched2.get(i).pt.x, 2) + - Math.pow(colData[1] - listOfMatched2.get(i).pt.y, 2)); - - if (dist < inlierThreshold) { - listOfGoodMatches.add(new DMatch(listOfInliers1.size(), listOfInliers2.size(), 0)); - listOfInliers1.add(listOfMatched1.get(i)); - listOfInliers2.add(listOfMatched2.get(i)); - } - } - //! [homography check] - - //! [draw final matches] - Mat res = new Mat(); - MatOfKeyPoint inliers1 = new MatOfKeyPoint(listOfInliers1.toArray(new KeyPoint[listOfInliers1.size()])); - MatOfKeyPoint inliers2 = new MatOfKeyPoint(listOfInliers2.toArray(new KeyPoint[listOfInliers2.size()])); - MatOfDMatch goodMatches = new MatOfDMatch(listOfGoodMatches.toArray(new DMatch[listOfGoodMatches.size()])); - Features2d.drawMatches(img1, inliers1, img2, inliers2, goodMatches, res); - Imgcodecs.imwrite("akaze_result.png", res); - - double inlierRatio = listOfInliers1.size() / (double) listOfMatched1.size(); - System.out.println("A-KAZE Matching Results"); - System.out.println("*******************************"); - System.out.println("# Keypoints 1: \t" + listOfKeypoints1.size()); - System.out.println("# Keypoints 2: \t" + listOfKeypoints2.size()); - System.out.println("# Matches: \t" + listOfMatched1.size()); - System.out.println("# Inliers: \t" + listOfInliers1.size()); - System.out.println("# Inliers Ratio: \t" + inlierRatio); - - HighGui.imshow("result", res); - HighGui.waitKey(); - //! [draw final matches] - - System.exit(0); - } -} - -public class AKAZEMatchDemo { - public static void main(String[] args) { - // Load the native OpenCV library - System.loadLibrary(Core.NATIVE_LIBRARY_NAME); - - new AKAZEMatch().run(args); - } -} diff --git a/modules/xfeatures2d/samples/planar_tracking.cpp b/modules/xfeatures2d/samples/planar_tracking.cpp deleted file mode 100644 index 10e3b00c943..00000000000 --- a/modules/xfeatures2d/samples/planar_tracking.cpp +++ /dev/null @@ -1,214 +0,0 @@ -#include -#include "opencv2/xfeatures2d.hpp" -#include -#include -#include -#include //for imshow -#include -#include -#include - -#include "stats.h" // Stats structure definition -#include "utils.h" // Drawing and printing functions - -using namespace std; -using namespace cv; - -const double akaze_thresh = 3e-4; // AKAZE detection threshold set to locate about 1000 keypoints -const double ransac_thresh = 2.5f; // RANSAC inlier threshold -const double nn_match_ratio = 0.8f; // Nearest-neighbour matching ratio -const int bb_min_inliers = 100; // Minimal number of inliers to draw bounding box -const int stats_update_period = 10; // On-screen statistics are updated every 10 frames - -namespace example { -class Tracker -{ -public: - Tracker(Ptr _detector, Ptr _matcher) : - detector(_detector), - matcher(_matcher) - {} - - void setFirstFrame(const Mat frame, vector bb, string title, Stats& stats); - Mat process(const Mat frame, Stats& stats); - Ptr getDetector() { - return detector; - } -protected: - Ptr detector; - Ptr matcher; - Mat first_frame, first_desc; - vector first_kp; - vector object_bb; -}; - -void Tracker::setFirstFrame(const Mat frame, vector bb, string title, Stats& stats) -{ - cv::Point *ptMask = new cv::Point[bb.size()]; - const Point* ptContain = { &ptMask[0] }; - int iSize = static_cast(bb.size()); - for (size_t i=0; i(bb[i].x); - ptMask[i].y = static_cast(bb[i].y); - } - first_frame = frame.clone(); - cv::Mat matMask = cv::Mat::zeros(frame.size(), CV_8UC1); - cv::fillPoly(matMask, &ptContain, &iSize, 1, cv::Scalar::all(255)); - detector->detectAndCompute(first_frame, matMask, first_kp, first_desc); - stats.keypoints = (int)first_kp.size(); - drawBoundingBox(first_frame, bb); - putText(first_frame, title, Point(0, 60), FONT_HERSHEY_PLAIN, 5, Scalar::all(0), 4); - object_bb = bb; - delete[] ptMask; -} - -Mat Tracker::process(const Mat frame, Stats& stats) -{ - TickMeter tm; - vector kp; - Mat desc; - - tm.start(); - detector->detectAndCompute(frame, noArray(), kp, desc); - stats.keypoints = (int)kp.size(); - - vector< vector > matches; - vector matched1, matched2; - matcher->knnMatch(first_desc, desc, matches, 2); - for(unsigned i = 0; i < matches.size(); i++) { - if(matches[i][0].distance < nn_match_ratio * matches[i][1].distance) { - matched1.push_back(first_kp[matches[i][0].queryIdx]); - matched2.push_back( kp[matches[i][0].trainIdx]); - } - } - stats.matches = (int)matched1.size(); - - Mat inlier_mask, homography; - vector inliers1, inliers2; - vector inlier_matches; - if(matched1.size() >= 4) { - homography = findHomography(Points(matched1), Points(matched2), - RANSAC, ransac_thresh, inlier_mask); - } - tm.stop(); - stats.fps = 1. / tm.getTimeSec(); - - if(matched1.size() < 4 || homography.empty()) { - Mat res; - hconcat(first_frame, frame, res); - stats.inliers = 0; - stats.ratio = 0; - return res; - } - for(unsigned i = 0; i < matched1.size(); i++) { - if(inlier_mask.at(i)) { - int new_i = static_cast(inliers1.size()); - inliers1.push_back(matched1[i]); - inliers2.push_back(matched2[i]); - inlier_matches.push_back(DMatch(new_i, new_i, 0)); - } - } - stats.inliers = (int)inliers1.size(); - stats.ratio = stats.inliers * 1.0 / stats.matches; - - vector new_bb; - perspectiveTransform(object_bb, new_bb, homography); - Mat frame_with_bb = frame.clone(); - if(stats.inliers >= bb_min_inliers) { - drawBoundingBox(frame_with_bb, new_bb); - } - Mat res; - drawMatches(first_frame, inliers1, frame_with_bb, inliers2, - inlier_matches, res, - Scalar(255, 0, 0), Scalar(255, 0, 0)); - return res; -} -} - -int main(int argc, char **argv) -{ - CommandLineParser parser(argc, argv, "{@input_path |0|input path can be a camera id, like 0,1,2 or a video filename}"); - parser.printMessage(); - string input_path = parser.get(0); - string video_name = input_path; - - VideoCapture video_in; - - if ( ( isdigit(input_path[0]) && input_path.size() == 1 ) ) - { - int camera_no = input_path[0] - '0'; - video_in.open( camera_no ); - } - else { - video_in.open(video_name); - } - - if(!video_in.isOpened()) { - cerr << "Couldn't open " << video_name << endl; - return 1; - } - - Stats stats, akaze_stats, orb_stats; - Ptr akaze = xfeatures2d::AKAZE::create(); - akaze->setThreshold(akaze_thresh); - Ptr orb = ORB::create(); - Ptr matcher = DescriptorMatcher::create("BruteForce-Hamming"); - example::Tracker akaze_tracker(akaze, matcher); - example::Tracker orb_tracker(orb, matcher); - - Mat frame; - namedWindow(video_name, WINDOW_NORMAL); - cout << "\nPress any key to stop the video and select a bounding box" << endl; - - while ( waitKey(1) < 1 ) - { - video_in >> frame; - cv::resizeWindow(video_name, frame.size()); - imshow(video_name, frame); - } - - vector bb; - cv::Rect uBox = cv::selectROI(video_name, frame); - bb.push_back(cv::Point2f(static_cast(uBox.x), static_cast(uBox.y))); - bb.push_back(cv::Point2f(static_cast(uBox.x+uBox.width), static_cast(uBox.y))); - bb.push_back(cv::Point2f(static_cast(uBox.x+uBox.width), static_cast(uBox.y+uBox.height))); - bb.push_back(cv::Point2f(static_cast(uBox.x), static_cast(uBox.y+uBox.height))); - - akaze_tracker.setFirstFrame(frame, bb, "AKAZE", stats); - orb_tracker.setFirstFrame(frame, bb, "ORB", stats); - - Stats akaze_draw_stats, orb_draw_stats; - Mat akaze_res, orb_res, res_frame; - int i = 0; - for(;;) { - i++; - bool update_stats = (i % stats_update_period == 0); - video_in >> frame; - // stop the program if no more images - if(frame.empty()) break; - - akaze_res = akaze_tracker.process(frame, stats); - akaze_stats += stats; - if(update_stats) { - akaze_draw_stats = stats; - } - - orb->setMaxFeatures(stats.keypoints); - orb_res = orb_tracker.process(frame, stats); - orb_stats += stats; - if(update_stats) { - orb_draw_stats = stats; - } - - drawStatistics(akaze_res, akaze_draw_stats); - drawStatistics(orb_res, orb_draw_stats); - vconcat(akaze_res, orb_res, res_frame); - cv::imshow(video_name, res_frame); - if(waitKey(1)==27) break; //quit on ESC button - } - akaze_stats /= i - 1; - orb_stats /= i - 1; - printStatistics("AKAZE", akaze_stats); - printStatistics("ORB", orb_stats); - return 0; -} diff --git a/modules/xfeatures2d/samples/python/tutorial_code/akaze_matching/AKAZE_match.py b/modules/xfeatures2d/samples/python/tutorial_code/akaze_matching/AKAZE_match.py deleted file mode 100644 index d39b64c2ccf..00000000000 --- a/modules/xfeatures2d/samples/python/tutorial_code/akaze_matching/AKAZE_match.py +++ /dev/null @@ -1,81 +0,0 @@ -from __future__ import print_function -import cv2 as cv -import numpy as np -import argparse -from math import sqrt - -## [load] -parser = argparse.ArgumentParser(description='Code for AKAZE local features matching tutorial.') -parser.add_argument('--input1', help='Path to input image 1.', default='graf1.png') -parser.add_argument('--input2', help='Path to input image 2.', default='graf3.png') -parser.add_argument('--homography', help='Path to the homography matrix.', default='H1to3p.xml') -args = parser.parse_args() - -img1 = cv.imread(cv.samples.findFile(args.input1), cv.IMREAD_GRAYSCALE) -img2 = cv.imread(cv.samples.findFile(args.input2), cv.IMREAD_GRAYSCALE) -if img1 is None or img2 is None: - print('Could not open or find the images!') - exit(0) - -fs = cv.FileStorage(cv.samples.findFile(args.homography), cv.FILE_STORAGE_READ) -homography = fs.getFirstTopLevelNode().mat() -## [load] - -## [AKAZE] -akaze = cv.xfeatures2d.AKAZE_create() -kpts1, desc1 = akaze.detectAndCompute(img1, None) -kpts2, desc2 = akaze.detectAndCompute(img2, None) -## [AKAZE] - -## [2-nn matching] -matcher = cv.DescriptorMatcher_create(cv.DescriptorMatcher_BRUTEFORCE_HAMMING) -nn_matches = matcher.knnMatch(desc1, desc2, 2) -## [2-nn matching] - -## [ratio test filtering] -matched1 = [] -matched2 = [] -nn_match_ratio = 0.8 # Nearest neighbor matching ratio -for m, n in nn_matches: - if m.distance < nn_match_ratio * n.distance: - matched1.append(kpts1[m.queryIdx]) - matched2.append(kpts2[m.trainIdx]) -## [ratio test filtering] - -## [homography check] -inliers1 = [] -inliers2 = [] -good_matches = [] -inlier_threshold = 2.5 # Distance threshold to identify inliers with homography check -for i, m in enumerate(matched1): - col = np.ones((3,1), dtype=np.float64) - col[0:2,0] = m.pt - - col = np.dot(homography, col) - col /= col[2,0] - dist = sqrt(pow(col[0,0] - matched2[i].pt[0], 2) +\ - pow(col[1,0] - matched2[i].pt[1], 2)) - - if dist < inlier_threshold: - good_matches.append(cv.DMatch(len(inliers1), len(inliers2), 0)) - inliers1.append(matched1[i]) - inliers2.append(matched2[i]) -## [homography check] - -## [draw final matches] -res = np.empty((max(img1.shape[0], img2.shape[0]), img1.shape[1]+img2.shape[1], 3), dtype=np.uint8) -cv.drawMatches(img1, inliers1, img2, inliers2, good_matches, res) -cv.imwrite("akaze_result.png", res) - -inlier_ratio = len(inliers1) / float(len(matched1)) -print('A-KAZE Matching Results') -print('*******************************') -print('# Keypoints 1: \t', len(kpts1)) -print('# Keypoints 2: \t', len(kpts2)) -print('# Matches: \t', len(matched1)) -print('# Inliers: \t', len(inliers1)) -print('# Inliers Ratio: \t', inlier_ratio) - -cv.imshow('result', res) -cv.waitKey() -## [draw final matches] diff --git a/modules/xfeatures2d/samples/stats.h b/modules/xfeatures2d/samples/stats.h deleted file mode 100644 index f5e09480d30..00000000000 --- a/modules/xfeatures2d/samples/stats.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef STATS_H -#define STATS_H - -struct Stats -{ - int matches; - int inliers; - double ratio; - int keypoints; - double fps; - - Stats() : matches(0), - inliers(0), - ratio(0), - keypoints(0), - fps(0.) - {} - - Stats& operator+=(const Stats& op) { - matches += op.matches; - inliers += op.inliers; - ratio += op.ratio; - keypoints += op.keypoints; - fps += op.fps; - return *this; - } - Stats& operator/=(int num) - { - matches /= num; - inliers /= num; - ratio /= num; - keypoints /= num; - fps /= num; - return *this; - } -}; - -#endif // STATS_H diff --git a/modules/xfeatures2d/samples/utils.h b/modules/xfeatures2d/samples/utils.h deleted file mode 100644 index b3f3aa5692d..00000000000 --- a/modules/xfeatures2d/samples/utils.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef UTILS_H -#define UTILS_H - -#include -#include -#include "stats.h" - -using namespace std; -using namespace cv; - -void drawBoundingBox(Mat image, vector bb); -void drawStatistics(Mat image, const Stats& stats); -void printStatistics(string name, Stats stats); -vector Points(vector keypoints); -Rect2d selectROI(const String &video_name, const Mat &frame); - -void drawBoundingBox(Mat image, vector bb) -{ - for(unsigned i = 0; i < bb.size() - 1; i++) { - line(image, bb[i], bb[i + 1], Scalar(0, 0, 255), 2); - } - line(image, bb[bb.size() - 1], bb[0], Scalar(0, 0, 255), 2); -} - -void drawStatistics(Mat image, const Stats& stats) -{ - static const int font = FONT_HERSHEY_PLAIN; - stringstream str1, str2, str3, str4; - - str1 << "Matches: " << stats.matches; - str2 << "Inliers: " << stats.inliers; - str3 << "Inlier ratio: " << setprecision(2) << stats.ratio; - str4 << "FPS: " << std::fixed << setprecision(2) << stats.fps; - - putText(image, str1.str(), Point(0, image.rows - 120), font, 2, Scalar::all(255), 3); - putText(image, str2.str(), Point(0, image.rows - 90), font, 2, Scalar::all(255), 3); - putText(image, str3.str(), Point(0, image.rows - 60), font, 2, Scalar::all(255), 3); - putText(image, str4.str(), Point(0, image.rows - 30), font, 2, Scalar::all(255), 3); -} - -void printStatistics(string name, Stats stats) -{ - cout << name << endl; - cout << "----------" << endl; - - cout << "Matches " << stats.matches << endl; - cout << "Inliers " << stats.inliers << endl; - cout << "Inlier ratio " << setprecision(2) << stats.ratio << endl; - cout << "Keypoints " << stats.keypoints << endl; - cout << "FPS " << std::fixed << setprecision(2) << stats.fps << endl; - cout << endl; -} - -vector Points(vector keypoints) -{ - vector res; - for(unsigned i = 0; i < keypoints.size(); i++) { - res.push_back(keypoints[i].pt); - } - return res; -} -#endif // UTILS_H