diff options
-rw-r--r-- | ftnoir_tracker_aruco/ar_video_widget.cpp | 2 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/include/board.h | 2 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/include/boarddetector.h | 3 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/include/cameraparameters.h | 3 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/include/marker.h | 2 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/include/markerdetector.h | 3 | ||||
-rw-r--r-- | ftnoir_tracker_aruco/trans_calib.cpp | 16 | ||||
-rw-r--r-- | ftnoir_tracker_ht/ht_video_widget.cpp | 2 | ||||
-rw-r--r-- | ftnoir_tracker_pt/camera.cpp | 10 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt.cpp | 17 | ||||
-rw-r--r-- | ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp | 2 | ||||
-rw-r--r-- | ftnoir_tracker_pt/point_extractor.cpp | 40 | ||||
-rw-r--r-- | ftnoir_tracker_pt/point_tracker.cpp | 65 | ||||
-rw-r--r-- | ftnoir_tracker_pt/pt_video_widget.cpp | 3 | ||||
-rw-r--r-- | ftnoir_tracker_pt/trans_calib.cpp | 17 |
15 files changed, 80 insertions, 107 deletions
diff --git a/ftnoir_tracker_aruco/ar_video_widget.cpp b/ftnoir_tracker_aruco/ar_video_widget.cpp index 70c26e55..1c3af262 100644 --- a/ftnoir_tracker_aruco/ar_video_widget.cpp +++ b/ftnoir_tracker_aruco/ar_video_widget.cpp @@ -7,8 +7,6 @@ #include "ar_video_widget.h" -using namespace std; - void ArucoVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_aruco/include/board.h b/ftnoir_tracker_aruco/include/board.h index c1d79292..ec7dd43f 100644 --- a/ftnoir_tracker_aruco/include/board.h +++ b/ftnoir_tracker_aruco/include/board.h @@ -32,8 +32,8 @@ or implied, of Rafael Muñoz Salinas. #include <vector> #include "exports.h" #include "marker.h" -using namespace std; namespace aruco { +using namespace std; /** * 3d representation of a marker */ diff --git a/ftnoir_tracker_aruco/include/boarddetector.h b/ftnoir_tracker_aruco/include/boarddetector.h index a0ee2361..619b4798 100644 --- a/ftnoir_tracker_aruco/include/boarddetector.h +++ b/ftnoir_tracker_aruco/include/boarddetector.h @@ -32,11 +32,10 @@ or implied, of Rafael Muñoz Salinas. #include "board.h" #include "cameraparameters.h" #include "markerdetector.h" -using namespace std; namespace aruco { - +using namespace std; /**\brief This class detects AR boards * Version 1.2 * There are two modes for board detection. diff --git a/ftnoir_tracker_aruco/include/cameraparameters.h b/ftnoir_tracker_aruco/include/cameraparameters.h index a419afbe..083d5f96 100644 --- a/ftnoir_tracker_aruco/include/cameraparameters.h +++ b/ftnoir_tracker_aruco/include/cameraparameters.h @@ -30,9 +30,10 @@ or implied, of Rafael Muñoz Salinas. #include "exports.h" #include <opencv2/core/core.hpp> #include <string> -using namespace std; + namespace aruco { +using namespace std; /**\brief Parameters of the camera */ diff --git a/ftnoir_tracker_aruco/include/marker.h b/ftnoir_tracker_aruco/include/marker.h index 89961002..efc3e5fe 100644 --- a/ftnoir_tracker_aruco/include/marker.h +++ b/ftnoir_tracker_aruco/include/marker.h @@ -32,8 +32,8 @@ or implied, of Rafael Muñoz Salinas. #include <opencv2/core/core.hpp> #include "exports.h" #include "cameraparameters.h" -using namespace std; namespace aruco { +using namespace std; /**\brief This class represents a marker. It is a vector of the fours corners ot the marker * */ diff --git a/ftnoir_tracker_aruco/include/markerdetector.h b/ftnoir_tracker_aruco/include/markerdetector.h index 8a351f7c..ac120b18 100644 --- a/ftnoir_tracker_aruco/include/markerdetector.h +++ b/ftnoir_tracker_aruco/include/markerdetector.h @@ -33,11 +33,10 @@ or implied, of Rafael Muñoz Salinas. #include "cameraparameters.h" #include "exports.h" #include "marker.h" -using namespace std; namespace aruco { - +using namespace std; /**\brief Main class for marker detection * */ diff --git a/ftnoir_tracker_aruco/trans_calib.cpp b/ftnoir_tracker_aruco/trans_calib.cpp index a562763a..176cf24c 100644 --- a/ftnoir_tracker_aruco/trans_calib.cpp +++ b/ftnoir_tracker_aruco/trans_calib.cpp @@ -7,8 +7,6 @@ #include "trans_calib.h" -using namespace cv; - //----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { @@ -17,13 +15,13 @@ TranslationCalibrator::TranslationCalibrator() void TranslationCalibrator::reset() { - P = Matx66f::zeros(); - y = Vec6f(0,0,0, 0,0,0); + P = cv::Matx66f::zeros(); + y = cv::Vec6f(0,0,0, 0,0,0); } -void TranslationCalibrator::update(const Matx33d& R_CM_k, const Vec3d& t_CM_k) +void TranslationCalibrator::update(const cv::Matx33d& R_CM_k, const cv::Vec3d& t_CM_k) { - Matx<double, 6,3> H_k_T = Matx<double, 6,3>::zeros(); + cv::Matx<double, 6,3> H_k_T = cv::Matx<double, 6,3>::zeros(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { H_k_T(i,j) = R_CM_k(j,i); @@ -37,8 +35,8 @@ void TranslationCalibrator::update(const Matx33d& R_CM_k, const Vec3d& t_CM_k) y += H_k_T * t_CM_k; } -Vec3f TranslationCalibrator::get_estimate() +cv::Vec3f TranslationCalibrator::get_estimate() { - Vec6f x = P.inv() * y; - return Vec3f(x[0], x[1], x[2]); + cv::Vec6f x = P.inv() * y; + return cv::Vec3f(x[0], x[1], x[2]); } diff --git a/ftnoir_tracker_ht/ht_video_widget.cpp b/ftnoir_tracker_ht/ht_video_widget.cpp index ef58c98f..02fe71d1 100644 --- a/ftnoir_tracker_ht/ht_video_widget.cpp +++ b/ftnoir_tracker_ht/ht_video_widget.cpp @@ -7,8 +7,6 @@ #include "ht_video_widget.h" -using namespace std; - void HTVideoWidget::update_image(unsigned char *frame, int width, int height) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_pt/camera.cpp b/ftnoir_tracker_pt/camera.cpp index 2989c1fe..4619f695 100644 --- a/ftnoir_tracker_pt/camera.cpp +++ b/ftnoir_tracker_pt/camera.cpp @@ -10,8 +10,6 @@ #include <QDebug> #include "opentrack/sleep.hpp" -using namespace cv; - void Camera::set_device_index(int index) { if (desired_index != index) @@ -74,7 +72,7 @@ void CVCamera::start() { if (cap) delete cap; - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); _set_res(); _set_fps(); // extract camera info @@ -103,11 +101,11 @@ void CVCamera::stop() active = false; } -bool CVCamera::_get_frame(Mat* frame) +bool CVCamera::_get_frame(cv::Mat* frame) { if (cap && cap->isOpened()) { - Mat img; + cv::Mat img; for (int i = 0; i < 100 && !cap->read(img); i++) ;; @@ -142,5 +140,5 @@ void CVCamera::_set_device_index() cap->release(); delete cap; } - cap = new VideoCapture(desired_index); + cap = new cv::VideoCapture(desired_index); } diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp index 07370f84..d3b43503 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt.cpp @@ -13,9 +13,6 @@ #include <QCoreApplication> #include "opentrack/camera-names.hpp" -using namespace std; -using namespace cv; - //#define PT_PERF_LOG //log performance //----------------------------------------------------------------------------- @@ -101,7 +98,7 @@ void Tracker_PT::run() { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below + Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); // just copy pasted these lines from below Affine X_GH = X_CM * X_MH; cv::Vec3f p = X_GH.t; // head (center?) position in global space float fx = get_focal_length(); @@ -171,17 +168,17 @@ void Tracker_PT::data(double *data) { Affine X_CM = pose(); - Affine X_MH(Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); + Affine X_MH(cv::Matx33f::eye(), cv::Vec3f(s.t_MH_x, s.t_MH_y, s.t_MH_z)); Affine X_GH = X_CM * X_MH; - Matx33f R = X_GH.R; - Vec3f t = X_GH.t; + cv::Matx33f R = X_GH.R; + cv::Vec3f t = X_GH.t; // translate rotation matrix from opengl (G) to roll-pitch-yaw (E) frame // -z -> x, y -> z, x -> -y - Matx33f R_EG(0, 0,-1, - -1, 0, 0, - 0, 1, 0); + cv::Matx33f R_EG(0, 0,-1, + -1, 0, 0, + 0, 1, 0); R = R_EG * R * R_EG.t(); // extract rotation angles diff --git a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp index 9fdab441..07ee4f1b 100644 --- a/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp +++ b/ftnoir_tracker_pt/ftnoir_tracker_pt_dialog.cpp @@ -14,8 +14,6 @@ #include "opentrack/camera-names.hpp" #include <vector> -using namespace std; - //----------------------------------------------------------------------------- TrackerDialog_PT::TrackerDialog_PT() : tracker(NULL), diff --git a/ftnoir_tracker_pt/point_extractor.cpp b/ftnoir_tracker_pt/point_extractor.cpp index e81e3aa0..4791dcc2 100644 --- a/ftnoir_tracker_pt/point_extractor.cpp +++ b/ftnoir_tracker_pt/point_extractor.cpp @@ -12,10 +12,6 @@ # include "opentrack/timer.hpp" #endif -using namespace cv; -using namespace std; - - PointExtractor::PointExtractor(){ //if (!AllocConsole()){} //else SetConsoleTitle("debug"); @@ -23,20 +19,20 @@ PointExtractor::PointExtractor(){ //freopen("CON", "w", stderr); } // ---------------------------------------------------------------------------- -std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) +std::vector<cv::Vec2f> PointExtractor::extract_points(cv::Mat& frame) { - const int W = frame.cols; - const int H = frame.rows; + const int W = frame.cols; + const int H = frame.rows; + + // convert to grayscale + cv::Mat frame_gray; + cv::cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - // convert to grayscale - Mat frame_gray; - cvtColor(frame, frame_gray, cv::COLOR_RGB2GRAY); - int min_size = s.min_point_size; int max_size = s.max_point_size; - unsigned int region_size_min = 3.14*min_size*min_size/4.0; - unsigned int region_size_max = 3.14*max_size*max_size/4.0; + unsigned int region_size_min = 3.14*min_size*min_size/4.0; + unsigned int region_size_max = 3.14*max_size*max_size/4.0; // testing indicates threshold difference of 45 from lowest to highest // that's applicable to poor lighting conditions. @@ -144,7 +140,7 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) }; // mask for everything that passes the threshold (or: the upper threshold of the hysteresis) - Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); + cv::Mat frame_bin = cv::Mat::zeros(H, W, CV_8U); const int min = std::max(0, thres - diff/2); const int max = std::min(255, thres + diff/2); @@ -155,8 +151,8 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) // this code is based on OpenCV SimpleBlobDetector for (int i = min; i < max; i += step) { - Mat frame_bin_; - threshold(frame_gray, frame_bin_, i, 255, THRESH_BINARY); + cv::Mat frame_bin_; + cv::threshold(frame_gray, frame_bin_, i, 255, cv::THRESH_BINARY); frame_bin.setTo(170, frame_bin_); std::vector<std::vector<cv::Point>> contours; @@ -211,19 +207,19 @@ std::vector<Vec2f> PointExtractor::extract_points(Mat& frame) for (auto& b : simple_blob::merge(blobs)) { auto pos = b.effective_pos(); - Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); + cv::Vec2f p((pos[0] - W/2)/W, -(pos[1] - H/2)/W); points.push_back(p); } - vector<Mat> channels_; + std::vector<cv::Mat> channels_; cv::split(frame, channels_); // draw output image - Mat frame_bin_ = frame_bin * .5; - vector<Mat> channels; + cv::Mat frame_bin_ = frame_bin * .5; + std::vector<cv::Mat> channels; channels.push_back(channels_[0] + frame_bin_); channels.push_back(channels_[1] - frame_bin_); channels.push_back(channels_[2] - frame_bin_); - merge(channels, frame); + cv::merge(channels, frame); - return points; + return points; } diff --git a/ftnoir_tracker_pt/point_tracker.cpp b/ftnoir_tracker_pt/point_tracker.cpp index b4283d37..d7adc09c 100644 --- a/ftnoir_tracker_pt/point_tracker.cpp +++ b/ftnoir_tracker_pt/point_tracker.cpp @@ -13,46 +13,43 @@ #include <QDebug> -using namespace cv; -using namespace std; - const float PI = 3.14159265358979323846f; // ---------------------------------------------------------------------------- -static void get_row(const Matx33f& m, int i, Vec3f& v) +static void get_row(const cv::Matx33f& m, int i, cv::Vec3f& v) { v[0] = m(i,0); v[1] = m(i,1); v[2] = m(i,2); } -static void set_row(Matx33f& m, int i, const Vec3f& v) +static void set_row(cv::Matx33f& m, int i, const cv::Vec3f& v) { m(i,0) = v[0]; m(i,1) = v[1]; m(i,2) = v[2]; } -static bool d_vals_sort(const pair<float,int> a, const pair<float,int> b) +static bool d_vals_sort(const std::pair<float,int> a, const std::pair<float,int> b) { return a.first < b.first; } void PointModel::get_d_order(const std::vector<cv::Vec2f>& points, int d_order[], cv::Vec2f d) const { - // fit line to orthographically projected points - vector< pair<float,int> > d_vals; + // fit line to orthographically projected points + std::vector<std::pair<float,int>> d_vals; // get sort indices with respect to d scalar product - for (unsigned i = 0; i<points.size(); ++i) - d_vals.push_back(pair<float, int>(d.dot(points[i]), i)); + for (unsigned i = 0; i<points.size(); ++i) + d_vals.push_back(std::pair<float, int>(d.dot(points[i]), i)); std::sort(d_vals.begin(), d_vals.end(), d_vals_sort ); - for (unsigned i = 0; i<points.size(); ++i) - d_order[i] = d_vals[i].second; + for (unsigned i = 0; i<points.size(); ++i) + d_order[i] = d_vals[i].second; } @@ -60,10 +57,10 @@ PointTracker::PointTracker() : init_phase(true) { } -PointTracker::PointOrder PointTracker::find_correspondences_previous(const vector<Vec2f>& points, const PointModel& model, float f) +PointTracker::PointOrder PointTracker::find_correspondences_previous(const std::vector<cv::Vec2f>& points, const PointModel& model, float f) { PointTracker::PointOrder p; - p.points[0] = project(Vec3f(0,0,0), f); + p.points[0] = project(cv::Vec3f(0,0,0), f); p.points[1] = project(model.M01, f); p.points[2] = project(model.M02, f); @@ -79,7 +76,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto // find closest point to projected model point i for (int j=0; j<PointModel::N_POINTS; ++j) { - Vec2f d = p.points[i]-points[j]; + cv::Vec2f d = p.points[i]-points[j]; float sdist = d.dot(d); if (sdist < min_sdist || j==0) { @@ -99,7 +96,7 @@ PointTracker::PointOrder PointTracker::find_correspondences_previous(const vecto return p; } -void PointTracker::track(const vector<Vec2f>& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) +void PointTracker::track(const std::vector<cv::Vec2f>& points, const PointModel& model, float f, bool dynamic_pose, int init_phase_timeout) { PointOrder order; @@ -129,9 +126,9 @@ PointTracker::PointOrder PointTracker::find_correspondences(const std::vector<cv model.get_d_order(points, point_d_order, d); // calculate d and d_order for simple freetrack-like point correspondence model.get_d_order(std::vector<cv::Vec2f> { - Vec2f{0,0}, - Vec2f(model.M01[0], model.M01[1]), - Vec2f(model.M02[0], model.M02[1]) + cv::Vec2f{0,0}, + cv::Vec2f(model.M01[0], model.M01[1]), + cv::Vec2f(model.M02[0], model.M02[1]) }, model_d_order, d); @@ -151,10 +148,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // The expected rotation used for resolving the ambiguity in POSIT: // In every iteration step the rotation closer to R_expected is taken - Matx33f R_expected = Matx33f::eye(); + cv::Matx33f R_expected = cv::Matx33f::eye(); // initial pose = last (predicted) pose - Vec3f k; + cv::Vec3f k; get_row(R_expected, 2, k); float Z0 = 1000.f; @@ -163,17 +160,17 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float float epsilon_1 = 1; float epsilon_2 = 1; - Vec3f I0, J0; - Vec2f I0_coeff, J0_coeff; + cv::Vec3f I0, J0; + cv::Vec2f I0_coeff, J0_coeff; - Vec3f I_1, J_1, I_2, J_2; - Matx33f R_1, R_2; - Matx33f* R_current; + cv::Vec3f I_1, J_1, I_2, J_2; + cv::Matx33f R_1, R_2; + cv::Matx33f* R_current; const int MAX_ITER = 100; const float EPS_THRESHOLD = 1e-4; - const cv::Vec2f* order = order_.points; + const cv::Vec2f* order = order_.points; int i=1; for (; i<MAX_ITER; ++i) @@ -182,10 +179,10 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float epsilon_2 = k.dot(model.M02)/Z0; // vector of scalar products <I0, M0i> and <J0, M0i> - Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], - order[2][0]*(1.0 + epsilon_2) - order[0][0]); - Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], - order[2][1]*(1.0 + epsilon_2) - order[0][1]); + cv::Vec2f I0_M0i(order[1][0]*(1.0 + epsilon_1) - order[0][0], + order[2][0]*(1.0 + epsilon_2) - order[0][0]); + cv::Vec2f J0_M0i(order[1][1]*(1.0 + epsilon_1) - order[0][1], + order[2][1]*(1.0 + epsilon_2) - order[0][1]); // construct projection of I, J onto M0i plane: I0 and J0 I0_coeff = model.P * I0_M0i; @@ -236,8 +233,8 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float // pick the rotation solution closer to the expected one // in simple metric d(A,B) = || I - A * B^T || - float R_1_deviation = norm(Matx33f::eye() - R_expected * R_1.t()); - float R_2_deviation = norm(Matx33f::eye() - R_expected * R_2.t()); + float R_1_deviation = norm(cv::Matx33f::eye() - R_expected * R_1.t()); + float R_2_deviation = norm(cv::Matx33f::eye() - R_expected * R_2.t()); if (R_1_deviation < R_2_deviation) R_current = &R_1; @@ -259,7 +256,7 @@ int PointTracker::POSIT(const PointModel& model, const PointOrder& order_, float X_CM.t[1] = order[0][1] * Z0/focal_length; X_CM.t[2] = Z0; - //qDebug() << "iter:" << i; + //qDebug() << "iter:" << i; return i; } diff --git a/ftnoir_tracker_pt/pt_video_widget.cpp b/ftnoir_tracker_pt/pt_video_widget.cpp index 15fc5a86..9f2b90f6 100644 --- a/ftnoir_tracker_pt/pt_video_widget.cpp +++ b/ftnoir_tracker_pt/pt_video_widget.cpp @@ -9,9 +9,6 @@ #include "pt_video_widget.h" -using namespace cv; -using namespace std; - void PTVideoWidget::update_image(const cv::Mat& frame) { QMutexLocker foo(&mtx); diff --git a/ftnoir_tracker_pt/trans_calib.cpp b/ftnoir_tracker_pt/trans_calib.cpp index 2994eb48..a1a4b641 100644 --- a/ftnoir_tracker_pt/trans_calib.cpp +++ b/ftnoir_tracker_pt/trans_calib.cpp @@ -7,9 +7,6 @@ #include "trans_calib.h" -using namespace cv; - -//----------------------------------------------------------------------------- TranslationCalibrator::TranslationCalibrator() { reset(); @@ -17,13 +14,13 @@ TranslationCalibrator::TranslationCalibrator() void TranslationCalibrator::reset() { - P = Matx66f::zeros(); - y = Vec6f(0,0,0, 0,0,0); + P = cv::Matx66f::zeros(); + y = cv::Vec6f(0,0,0, 0,0,0); } -void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) +void TranslationCalibrator::update(const cv::Matx33f& R_CM_k, const cv::Vec3f& t_CM_k) { - Matx<float, 6,3> H_k_T = Matx<float, 6,3>::zeros(); + cv::Matx<float, 6,3> H_k_T = cv::Matx<float, 6,3>::zeros(); for (int i=0; i<3; ++i) { for (int j=0; j<3; ++j) { H_k_T(i,j) = R_CM_k(j,i); @@ -37,8 +34,8 @@ void TranslationCalibrator::update(const Matx33f& R_CM_k, const Vec3f& t_CM_k) y += H_k_T * t_CM_k; } -Vec3f TranslationCalibrator::get_estimate() +cv::Vec3f TranslationCalibrator::get_estimate() { - Vec6f x = P.inv() * y; - return Vec3f(-x[0], -x[1], -x[2]); + cv::Vec6f x = P.inv() * y; + return cv::Vec3f(-x[0], -x[1], -x[2]); } |