/*
 * Copyright 2017 Jan Dorazil <deu439@gmail.com>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

#ifndef KPTRACKER_HPP
#define KPTRACKER_HPP

#include <opencv2/opencv.hpp>

using namespace cv;

#define MATCH_RATIO  0.5f

const struct {
  int   nfeatures     =    300;
  float scale_factor  =    1.2f; // 1.2
  int   nlevels       =    8; // 8
  int   edge_thresh   =    51; //31
  int   first_level   =    0;
  int   wta_k         =    2;
  int   score_type    =    ORB::HARRIS_SCORE;
  int   patch_size    =    51; //31
} ORB_opts;

const struct {
  int  	  descriptor_type     = AKAZE::DESCRIPTOR_MLDB;
		int  	  descriptor_size     = 0;
		int  	  descriptor_channels = 3;
		float  	threshold           = 0.005f;
		int  	  nOctaves            = 4;
		int  	  nOctaveLayers       = 4;
		int  	  diffusivity         = KAZE::DIFF_PM_G2;
} AKAZE_opts;

using namespace cv;

class KpTracker
{
public:
  typedef std::vector<std::vector<DMatch>> MatchType;
  std::vector<KeyPoint> mKp;
  Mat mDesc;
  
private:
  Ptr<Feature2D> mDetector;
  Ptr<DescriptorMatcher> mMatcher;
  
public:
  KpTracker(InputArray temp, InputArray mask = noArray());

  void DetectKeypoints(InputArray img, InputArray mask,
                       std::vector<KeyPoint> &kp, Mat &desc);
  void MatchKeypoints(Mat &desc, std::vector<KeyPoint> &kp,
                      std::vector<Point> &pts1, std::vector<Point> &pts2,
                      std::vector<DMatch> &good);
};

#endif // KPTRACKER_HPP
