ibg_cv.cpp
Go to the documentation of this file.
1 #include <cv_wrapper/ibg_cv.h>
2 #include <vtec_core/image.h>
3 #include <homography_optimizer/types.h>
5 
7 {
8  initialized_ = false;
9 }
10 
11 bool VTEC::IBGHomographyOptimizerCvWrapper::setReferenceTemplate(const cv::Mat& ref_image, const int posx,
12  const int posy, const int sizex, const int sizey)
13 {
14  if (!initialized_)
15  return false;
16  /* convert cv Image to vtec image */
17  VTEC::Image v_image;
18  VTEC::cv2vtecImg(ref_image, v_image);
19 
20  initialized_ = optimizer->setReferenceTemplate(v_image, posx, posy, sizex, sizey);
21  return initialized_;
22 }
23 
24 double VTEC::IBGHomographyOptimizerCvWrapper::optimize(const cv::Mat& curr_image, cv::Mat& H, float& alpha, float& beta,
25  int predictor)
26 {
27  if (!initialized_)
28  return -1.0;
29 
30  /* convert cv Image to Vtec image */
31  VTEC::Image v_image;
32  VTEC::cv2vtecImg(curr_image, v_image);
33 
34  /* convert cv Homography to Vtec Homography */
35  VTEC::Homography v_H;
36  v_H[0] = H.at<double>(0, 0);
37  v_H[1] = H.at<double>(0, 1);
38  v_H[2] = H.at<double>(0, 2);
39  v_H[3] = H.at<double>(1, 0);
40  v_H[4] = H.at<double>(1, 1);
41  v_H[5] = H.at<double>(1, 2);
42  v_H[6] = H.at<double>(2, 0);
43  v_H[7] = H.at<double>(2, 1);
44  v_H[8] = H.at<double>(2, 2);
45 
46  double score = optimizer->optimize(v_image, v_H, alpha, beta, predictor);
47 
48  H.at<double>(0, 0) = v_H[0];
49  H.at<double>(0, 1) = v_H[1];
50  H.at<double>(0, 2) = v_H[2];
51  H.at<double>(1, 0) = v_H[3];
52  H.at<double>(1, 1) = v_H[4];
53  H.at<double>(1, 2) = v_H[5];
54  H.at<double>(2, 0) = v_H[6];
55  H.at<double>(2, 1) = v_H[7];
56  H.at<double>(2, 2) = v_H[8];
57 
58  return score;
59 }
60 
62 {
63  if (!initialized_)
64  {
65  std::vector<int> v;
66  return v;
67  }
68  else
69  {
70  return optimizer->getNbIterations();
71  }
72 };
73 
75 {
76  auto vtec_homographies = optimizer->getHomographySequence();
77  size_t size = vtec_homographies.size();
78  std::vector<cv::Mat> cv_homographies;
79 
80  for (int i = 0; i < size; ++i)
81  {
82  cv::Mat cv_H;
83  VTEC::Homography* vtec_H = vtec_homographies[i];
84 
85  VTEC::vtec2cvHomography(*vtec_H, cv_H);
86 
87  cv_homographies.push_back(cv_H);
88  }
89  return cv_homographies;
90 }
91 
93 {
94  VTEC::Homography vtec_h;
95  cv2vtecHomography(H, vtec_h);
96  return optimizer->setHomography(vtec_h);
97 }
98 
100 {
101  VTEC::Image vtec_template;
102  optimizer->getCurrentTemplate(vtec_template);
103  vtec2cvImg(vtec_template, img);
104 }
105 
107 {
108  VTEC::Image vtec_template;
109  optimizer->getReferenceTemplate(vtec_template);
110  vtec2cvImg(vtec_template, img);
111 }
112 
114 {
115  VTEC::Homography vtec_h;
116  optimizer->getHomography(vtec_h);
117  vtec2cvHomography(vtec_h, H);
118 }
void getCurrentTemplate(cv::Mat &img)
Gets the current template.
Definition: ibg_cv.cpp:99
IBGHomographyOptimizer * optimizer
Definition: ibg_cv.h:98
bool setReferenceTemplate(const cv::Mat &ref_image, const int posx, const int posy, const int sizex, const int sizey)
Sets the reference template.
Definition: ibg_cv.cpp:11
double optimize(const cv::Mat &curr_image, cv::Mat &H, float &alpha, float &beta, int predictor)
Optimization function.
Definition: ibg_cv.cpp:24
void cv2vtecHomography(const cv::Mat &cv_h, VTEC::Homography &vtec_h)
Converts opencv matrix to vtec homography.
Definition: vtec_opencv.h:71
IBGHomographyOptimizerCvWrapper()
Constructor.
Definition: ibg_cv.cpp:6
void getReferenceTemplate(cv::Mat &img)
Gets the reference template.
Definition: ibg_cv.cpp:106
void setHomography(const cv::Mat H)
Sets the homography.
Definition: ibg_cv.cpp:92
void cv2vtecImg(const cv::Mat &image, VTEC::Image &vtec_img)
Converts a opencv image to vtec format.
Definition: vtec_opencv.h:17
std::vector< cv::Mat > getHomographySequence()
Gets the homography sequence.
Definition: ibg_cv.cpp:74
void vtec2cvImg(const VTEC::Image &vtec_img, cv::Mat &image)
Converts vtec image to opencv format.
Definition: vtec_opencv.h:35
void getHomography(cv::Mat &H)
Gets the homography.
Definition: ibg_cv.cpp:113
std::vector< int > getNbIterations()
Gets the number of iterations.
Definition: ibg_cv.cpp:61
void vtec2cvHomography(const VTEC::Homography &vtec_h, cv::Mat &cv_h)
Converts vtec homography to opencv matrix.
Definition: vtec_opencv.h:53


cv_wrapper
Author(s):
autogenerated on Sun Dec 16 2018 03:14:36