Visual Servoing Platform
version 3.7.0
Toggle main menu visibility
Loading...
Searching...
No Matches
tutorial-bridge-opencv-matrix.cpp
1
2
#include <iostream>
3
#include <visp3/core/vpConfig.h>
4
5
#if defined(HAVE_OPENCV_CORE)
6
7
#include <visp3/core/vpImageConvert.h>
8
#include <visp3/io/vpImageIo.h>
9
10
#include <opencv2/core/core.hpp>
11
12
int
main()
13
{
14
#ifdef ENABLE_VISP_NAMESPACE
15
using namespace
VISP_NAMESPACE_NAME
;
16
#endif
17
{
18
std::cout <<
"From OpenCV to ViSP conversion"
<< std::endl;
20
cv::Mat M_cv = (cv::Mat_<double>(3, 4) << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
21
std::cout <<
"M_cv: \n"
<< M_cv << std::endl;
23
25
vpMatrix
M(
static_cast<
unsigned
int
>
(M_cv.rows),
static_cast<
unsigned
int
>
(M_cv.cols));
26
memcpy(M.data, M_cv.data,
sizeof
(
double
) *
static_cast<
size_t
>
(M_cv.rows * M_cv.cols));
27
std::cout <<
"M: \n"
<< M << std::endl;
29
}
30
31
{
32
std::cout <<
"From ViSP to OpenCV conversion"
<< std::endl;
34
vpMatrix
M(3, 4, { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 });
35
std::cout <<
"M: \n"
<< M << std::endl;
37
39
cv::Mat tmp(
static_cast<
int
>
(M.getRows()),
static_cast<
int
>
(M.getCols()), CV_64F,
static_cast<
void
*
>
(M.data));
40
cv::Mat M_cv_deep = tmp.clone();
41
std::cout <<
"M_cv_deep: \n"
<< M_cv_deep << std::endl;
43
45
cv::Mat M_cv(
static_cast<
int
>
(M.getRows()),
static_cast<
int
>
(M.getCols()), CV_64F,
static_cast<
void
*
>
(M.data));
46
std::cout <<
"M_cv: \n"
<< M_cv << std::endl;
48
50
std::cout <<
"Set M = eye"
<< std::endl;
51
M.eye();
52
std::cout <<
"M: \n"
<< M << std::endl;
53
std::cout <<
"M_cv: \n"
<< M_cv << std::endl;
55
}
56
}
57
#else
58
int
main()
59
{
60
#if !defined(HAVE_OPENCV_CORE)
61
std::cout <<
"This tutorial requires OpenCV core module."
<< std::endl;
62
#endif
63
return
EXIT_SUCCESS;
64
}
65
#endif
vpMatrix
Implementation of a matrix and operations on matrices.
Definition
vpMatrix.h:175
VISP_NAMESPACE_NAME
Definition
vpEigenConversion.h:44
tutorial
bridge
opencv
tutorial-bridge-opencv-matrix.cpp
Generated by
1.17.0