Mercurial > hg > nsaunier > traffic-intelligence
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 803:f7cf43b5ad3b | 804:17e54690af8a |
|---|---|
| 3 | 3 |
| 4 #include "opencv2/core/core.hpp" | 4 #include "opencv2/core/core.hpp" |
| 5 #include "opencv2/features2d/features2d.hpp" | 5 #include "opencv2/features2d/features2d.hpp" |
| 6 | 6 |
| 7 class CvCapture; | 7 class CvCapture; |
| 8 //template<typename T> class Point_<T>; | |
| 9 | |
| 10 /// constant that indicates if the image should be flipped | |
| 11 //static const int flipImage = CV_CVTIMG_FLIP; | |
| 12 | 8 |
| 13 /** Projects a point with the homography matrix | 9 /** Projects a point with the homography matrix |
| 14 use perspectiveTransform for arrays of points. */ | 10 use perspectiveTransform for arrays of points. */ |
| 15 cv::Point2f project(const cv::Point2f& p, const cv::Mat& homography); | 11 //cv::Point2f project(const cv::Point2f& p, const cv::Mat& homography); |
| 12 template<typename T> | |
| 13 inline cv::Point_<T> project(const cv::Point_<T>& p, const cv::Mat_<T>& homography) { | |
| 14 if (homography.empty()) | |
| 15 return p; | |
| 16 else { | |
| 17 T x, y; | |
| 18 T w = homography.template at<T>(2,0)*p.x+homography.template at<T>(2,1)*p.y+homography.template at<T>(2,2); | |
| 19 if (w != 0.) { | |
| 20 x = (homography.template at<T>(0,0)*p.x+homography.template at<T>(0,1)*p.y+homography.template at<T>(0,2))/w; | |
| 21 y = (homography.template at<T>(1,0)*p.x+homography.template at<T>(1,1)*p.y+homography.template at<T>(1,2))/w; | |
| 22 } else { | |
| 23 x = 0.; | |
| 24 y = 0.; | |
| 25 } | |
| 26 return cv::Point_<T>(x, y); | |
| 27 } | |
| 28 } | |
| 16 | 29 |
| 17 /** Loads a cv mat from a text file where the numbers are saved line by line separated by separator */ | 30 /** Loads a cv mat from a text file where the numbers are saved line by line separated by separator */ |
| 18 cv::Mat loadMat(const std::string& filename, const std::string& separator); | 31 cv::Mat loadMat(const std::string& filename, const std::string& separator); |
| 32 | |
| 33 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); } | |
| 19 | 34 |
| 20 //template<typename T> | 35 //template<typename T> |
| 21 //float scalarProduct(const cv::Point_<T>& v1, const cv::Point_<T>& v2) { return v1.x*v2.x+v1.y*v2.y;} | 36 //float scalarProduct(const cv::Point_<T>& v1, const cv::Point_<T>& v2) { return v1.x*v2.x+v1.y*v2.y;} |
| 22 | 37 |
| 23 void keyPoints2Points(const std::vector<cv::KeyPoint>& kpts, std::vector<cv::Point2f>& pts, const bool& clearPts = true); | 38 void keyPoints2Points(const std::vector<cv::KeyPoint>& kpts, std::vector<cv::Point2f>& pts, const bool& clearPts = true); |
| 24 | |
| 25 /** Allocates a new IplImage. */ | |
| 26 // IplImage* allocateImage(const int& width, const int& height, const int& depth, const int& channels); | |
| 27 | |
| 28 // IplImage* allocateImage(const CvSize& size, const int& depth, const int& channels); | |
| 29 | 39 |
| 30 /** Goes to the target frame number, by querying frame, | 40 /** Goes to the target frame number, by querying frame, |
| 31 supposing the video input is currently at current frame number. | 41 supposing the video input is currently at current frame number. |
| 32 Returns the frame number that was reached.*/ | 42 Returns the frame number that was reached.*/ |
| 33 // int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum); | 43 // int goToFrameNum(CvCapture* inputVideo, const int& currentFrameNum, const int& targetFrameNum); |
