diff include/cvutils.hpp @ 804:17e54690af8a dev

work in progress, not fully functional yet
author Nicolas Saunier <nicolas.saunier@polymtl.ca>
date Wed, 01 Jun 2016 17:57:49 -0400
parents b6ad86ee7033
children
line wrap: on
line diff
--- a/include/cvutils.hpp	Wed Jun 01 01:55:45 2016 -0400
+++ b/include/cvutils.hpp	Wed Jun 01 17:57:49 2016 -0400
@@ -5,28 +5,38 @@
 #include "opencv2/features2d/features2d.hpp"
 
 class CvCapture;
-//template<typename T> class Point_<T>;
-
-/// constant that indicates if the image should be flipped
-//static const int flipImage = CV_CVTIMG_FLIP;
 
 /** Projects a point with the homography matrix
  use perspectiveTransform for arrays of points. */
-cv::Point2f project(const cv::Point2f& p, const cv::Mat& homography);
+//cv::Point2f project(const cv::Point2f& p, const cv::Mat& homography);
+template<typename T>
+inline cv::Point_<T> project(const cv::Point_<T>& p, const cv::Mat_<T>& homography) {
+  if (homography.empty())
+    return p;
+  else {
+    T x, y;
+    T w = homography.template at<T>(2,0)*p.x+homography.template at<T>(2,1)*p.y+homography.template at<T>(2,2);
+    if (w != 0.) {
+      x = (homography.template at<T>(0,0)*p.x+homography.template at<T>(0,1)*p.y+homography.template at<T>(0,2))/w;
+      y = (homography.template at<T>(1,0)*p.x+homography.template at<T>(1,1)*p.y+homography.template at<T>(1,2))/w;
+    } else {
+      x = 0.;
+      y = 0.;
+    }
+    return cv::Point_<T>(x, y);
+  }
+}
 
 /** Loads a cv mat from a text file where the numbers are saved line by line separated by separator */
 cv::Mat loadMat(const std::string& filename, const std::string& separator);
 
+inline bool inImage(const  cv::Point2f& p, const cv::Size s) { return (p.x >= 0) && (p.x <= s.width) && (p.y >= 0) && (p.y <= s.height); }
+
 //template<typename T> 
 //float scalarProduct(const cv::Point_<T>& v1, const cv::Point_<T>& v2) { return v1.x*v2.x+v1.y*v2.y;}
 
 void keyPoints2Points(const std::vector<cv::KeyPoint>& kpts, std::vector<cv::Point2f>& pts, const bool& clearPts = true);
 
-/** Allocates a new IplImage. */
-// IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels);
-
-// IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels);
-
 /** Goes to the target frame number, by querying frame, 
     supposing the video input is currently at current frame number.
     Returns the frame number that was reached.*/