SLProject  4.3.020
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SENSUtils.h
Go to the documentation of this file.
1 #ifndef SENS_UTILS_H
2 #define SENS_UTILS_H
3 
4 #include <opencv2/opencv.hpp>
5 
6 #define SENS_PI 3.1415926535897932384626433832795
7 #define SENS_DEG2RAD SENS_PI / 180.0
8 #define SENS_RAD2DEG 180.0 / SENS_PI
9 
10 namespace SENS
11 {
12 //returns true if crop was calculated
13 bool calcCrop(cv::Size inputSize, float targetWdivH, int& cropW, int& cropH, int& width, int& height);
14 void cropImage(cv::Mat& img, float targetWdivH, int& cropW, int& cropH);
15 void cropImageTo(const cv::Mat& img, cv::Mat& outImg, float targetWdivH, int& cropW, int& cropH);
16 
17 void mirrorImage(cv::Mat& img, bool mirrorH, bool mirrorV);
18 void extendWithBars(cv::Mat& img, float targetWdivH);
19 
20 //calculate field of view in degree from focal length in pixel. (If you want to know the horizontal field of view you have to pass the image width as imgLength, for vertical field of view pass the image height
21 float calcFOVDegFromFocalLengthPix(const float focalLengthPix, const int imgLength);
22 //calculate focal length in pix from field of view in degree. (If you pass the horizontal field of view you have to pass the image width as imgLength. If you pass the vertical field of view you have to pass the image height as imgLength.
23 float calcFocalLengthPixFromFOVDeg(const float fovDeg, const int imgLength);
24 
25 /*
26  @brief calculate an unknown field of view (e.g. vertical) from a known field of view (e.g. horizontal)
27  @param otherFovDeg specifies the known field of view in degree
28  @param otherLength specifies the length belonging to the known field of view (e.g. width belongs to horizontal fovV and height belongs to vertical fov)
29  @param length specifies the relative length (repecting the img aspect ration) in the direction of the unknown field of view
30  @returns field of view in degree
31 */
32 float calcFovDegFromOtherFovDeg(const float otherFovDeg, const int otherLength, const int length);
33 /*
34  @brief calculate a scaled camera matrix using new and old reference lengths
35  @param origMat specifies the original camera matrix
36  @param newRefLength specifies the new reference length
37  @param oldRefLength specifies the old reference length
38  @returns adapted camera matrix
39 */
40 cv::Mat adaptCameraMat(cv::Mat origMat, int newRefLength, int oldRefLength);
41 
42 /*
43  @brief calculate increased fov: e.g. we know the fov of a, image (oldFovDeg) with height heightOld that is vertically centered in a screen with heightNew and want to know the corresponding new field of view
44  @param oldFovDeg old field of view in degree
45  @param oldImgLength specifies corresponding old img length (e.g. combine vertical fov with height and horizontal fov with width)
46  @param newImgLength specifies corresponding new img length (e.g. combine vertical fov with height and horizontal fovV with width)
47  @returns new field of view in degree
48  */
49 //todo: does not give correct results, I wonder why...
50 //float calcFovOfCenteredImg(const float oldFovDeg, const int oldImgLength, const int newImgLength);
51 
52 };
53 
54 #endif //SENS_UTILS_H
void extendWithBars(cv::Mat &img, float targetWdivH)
Definition: SENSUtils.cpp:85
void mirrorImage(cv::Mat &img, bool mirrorH, bool mirrorV)
Definition: SENSUtils.cpp:170
float calcFocalLengthPixFromFOVDeg(const float fovDeg, const int imgLength)
Definition: SENSUtils.cpp:199
float calcFOVDegFromFocalLengthPix(const float focalLengthPix, const int imgLength)
Definition: SENSUtils.cpp:192
void cropImageTo(const cv::Mat &img, cv::Mat &outImg, float targetWdivH, int &cropW, int &cropH)
Definition: SENSUtils.cpp:73
void cropImage(cv::Mat &img, float targetWdivH, int &cropW, int &cropH)
Definition: SENSUtils.cpp:62
bool calcCrop(cv::Size inputSize, float targetWdivH, int &cropW, int &cropH, int &width, int &height)
Definition: SENSUtils.cpp:9
cv::Mat adaptCameraMat(cv::Mat origMat, int newRefLength, int oldRefLength)
Definition: SENSUtils.cpp:212
float calcFovDegFromOtherFovDeg(const float otherFovDeg, const int otherLength, const int length)
Definition: SENSUtils.cpp:206