Convert Quaternion rotation to rotation matrix?

The following code is based on a quaternion (qw, qx, qy, qz), where the order is based on the Boost quaternions: boost::math::quaternion<float> quaternion; float qw = quaternion.R_component_1(); float qx = quaternion.R_component_2(); float qy = quaternion.R_component_3(); float qz = quaternion.R_component_4(); First you have to normalize the quaternion: const float n = 1.0f/sqrt(qx*qx+qy*qy+qz*qz+qw*qw); qx *= n; qy … Read more

Apply function to all Eigen matrix element

Yes, use the Eigen::MatrixBase<>::unaryExpr() member function. Example: #include <cmath> #include <iostream> #include <Eigen/Core> double Exp(double x) // the functor we want to apply { return std::exp(x); } int main() { Eigen::MatrixXd m(2, 2); m << 0, 1, 2, 3; std::cout << m << std::endl << “becomes: “; std::cout << std::endl << m.unaryExpr(&Exp) << std::endl; }

Differences of using “const cv::Mat &”, “cv::Mat &”, “cv::Mat” or “const cv::Mat” as function parameters?

It’s all because OpenCV uses Automatic Memory Management. OpenCV handles all the memory automatically. First of all, std::vector, Mat, and other data structures used by the functions and methods have destructors that deallocate the underlying memory buffers when needed. This means that the destructors do not always deallocate the buffers as in case of Mat. … Read more