SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
WAICompassAlignment Class Reference

#include <WAICompassAlignment.h>

Classes

struct  Template
 

Public Member Functions

void update (const cv::Mat &frameGray, cv::Mat &resultImage, const float hFov, double latitudeDEG, double longitudeDEG, double altitudeM, cv::Point &forwardPoint)
 
void setTemplate (cv::Mat &templateImage, double latitudeDEG, double longitudeDEG, double altitudeM)
 
float getRotAngleDEG ()
 

Private Attributes

Template _template
 
float _rotAngDEG = 0.0f
 

Detailed Description

Definition at line 6 of file WAICompassAlignment.h.

Member Function Documentation

◆ getRotAngleDEG()

float WAICompassAlignment::getRotAngleDEG ( )
inline

Definition at line 27 of file WAICompassAlignment.h.

27 { return _rotAngDEG; }

◆ setTemplate()

void WAICompassAlignment::setTemplate ( cv::Mat &  templateImage,
double  latitudeDEG,
double  longitudeDEG,
double  altitudeM 
)

Definition at line 7 of file WAICompassAlignment.cpp.

8 {
9  _template.image = templateImage.clone();
10  _template.latitudeDEG = latitudeDEG;
11  _template.longitudeDEG = longitudeDEG;
12  _template.altitudeM = altitudeM;
13 }

◆ update()

void WAICompassAlignment::update ( const cv::Mat &  frameGray,
cv::Mat &  resultImage,
const float  hFov,
double  latitudeDEG,
double  longitudeDEG,
double  altitudeM,
cv::Point &  forwardPoint 
)

Definition at line 15 of file WAICompassAlignment.cpp.

22 {
24 
25  // TODO(dgj1): handle error if no template has been set
26 
27  cv::matchTemplate(frameGray, _template.image, resultImage, cv::TM_CCOEFF_NORMED);
28 
29  double minVal, maxVal;
30  cv::Point minLoc, maxLoc;
31  cv::minMaxLoc(resultImage, &minVal, &maxVal, &minLoc, &maxLoc);
32 
33  std::cout << "maxLoc: " << maxLoc << std::endl;
34 
35  cv::Point imCenter = cv::Point((int)(frameGray.cols * 0.5f),
36  (int)(frameGray.rows * 0.5f));
37  cv::Point tplCenter = cv::Point((int)(_template.image.cols * 0.5f),
38  (int)(_template.image.rows * 0.5f));
39  cv::Point tplMatchCenter = maxLoc + tplCenter;
40 
41  cv::Point offset = tplMatchCenter - imCenter;
42 
43  float degPerPixelH = hFov / frameGray.cols;
44 
45  // Angle between camera forward and template match center
46  // If GPS is absolutely precise, the difference between this angle and
47  // the angle between GPS forward and template match center should be 0
48  float angleCenterTemplateDegH = offset.x * degPerPixelH;
49 
50  // TODO(dgj1): actually calculate this
51  cv::Point vecCurTpl = cv::Point((int)(_template.latitudeDEG - latitudeDEG),
52  (int)(_template.longitudeDEG - longitudeDEG));
53  vecCurTpl /= cv::norm(vecCurTpl);
54  vecCurForward /= cv::norm(vecCurForward);
55  float angleGPSTemplateDegH = (float)vecCurTpl.dot(vecCurForward);
56 
57  _rotAngDEG = angleGPSTemplateDegH - angleCenterTemplateDegH;
58 }
#define PROFILE_FUNCTION()
Definition: Instrumentor.h:41

Member Data Documentation

◆ _rotAngDEG

float WAICompassAlignment::_rotAngDEG = 0.0f
private

Definition at line 32 of file WAICompassAlignment.h.

◆ _template

Template WAICompassAlignment::_template
private

Definition at line 31 of file WAICompassAlignment.h.


The documentation for this class was generated from the following files: