Visual Servoing Platform version 3.6.0
Loading...
Searching...
No Matches
tutorial-bridge-opencv-matrix.cpp
1
2#include <visp3/core/vpImageConvert.h>
3#include <visp3/io/vpImageIo.h>
4
5#if defined(HAVE_OPENCV_IMGPROC)
6#include <opencv2/core/core.hpp>
7#include <opencv2/imgproc/imgproc.hpp>
8#endif
9
10int main()
11{
12#if defined(VISP_HAVE_OPENCV) && defined(HAVE_OPENCV_IMGPROC) && (VISP_CXX_STANDARD >= VISP_CXX_STANDARD_11)
13 {
14 std::cout << "From OpenCV to ViSP conversion" << std::endl;
16 cv::Mat M_cv = (cv::Mat_<double>(3, 4) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
17 std::cout << "M_cv: \n" << M_cv << std::endl;
19
21 vpMatrix M(static_cast<unsigned int>(M_cv.rows), static_cast<unsigned int>(M_cv.cols));
22 memcpy(M.data, M_cv.data, sizeof(double) * static_cast<size_t>(M_cv.rows * M_cv.cols));
23 std::cout << "M: \n" << M << std::endl;
25 }
26
27 {
28 std::cout << "From ViSP to OpenCV conversion" << std::endl;
30 vpMatrix M(3, 4, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
31 std::cout << "M: \n" << M << std::endl;
33
35 cv::Mat tmp(static_cast<int>(M.getRows()), static_cast<int>(M.getCols()), CV_64F, static_cast<void *>(M.data));
36 cv::Mat M_cv_deep = tmp.clone();
37 std::cout << "M_cv_deep: \n" << M_cv_deep << std::endl;
39
41 cv::Mat M_cv(static_cast<int>(M.getRows()), static_cast<int>(M.getCols()), CV_64F, static_cast<void *>(M.data));
42 std::cout << "M_cv: \n" << M_cv << std::endl;
44
46 std::cout << "Set M = eye" << std::endl;
47 M.eye();
48 std::cout << "M: \n" << M << std::endl;
49 std::cout << "M_cv: \n" << M_cv << std::endl;
51 }
52#endif
53}
Implementation of a matrix and operations on matrices.
Definition vpMatrix.h:152