1
0
mirror of https://github.com/opencv/opencv.git synced 2026-07-21 19:33:03 +04:00

core: deprecate MatCommaInitializer_

This commit is contained in:
Maksim Shabunin
2026-05-19 06:11:12 +03:00
parent cd4d732442
commit 201381e019
24 changed files with 324 additions and 337 deletions
@@ -201,9 +201,7 @@ object in multiple ways:
![](images/MatBasicContainerOut3.png) ![](images/MatBasicContainerOut3.png)
- For small matrices you may use comma separated initializers or initializer lists (C++11 support is required in the last case): - For small matrices you may use initializer lists:
@snippet mat_the_basic_image_container.cpp comma
@snippet mat_the_basic_image_container.cpp list @snippet mat_the_basic_image_container.cpp list
+9 -2
View File
@@ -548,6 +548,13 @@ public:
double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180); double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
Mat R = (Mat_<double>(2,2) << a, -b, b, a); Mat R = (Mat_<double>(2,2) << a, -b, b, a);
\endcode \endcode
\deprecated Use constructors with std::initializer_list instead:
\code
Mat_<int> m1({1, 2, 3, 4}); // 4x1 Mat
Mat_<uchar> m2({2, 3}, {1, 2, 3, 4, 5, 6}); // 2x3 Mat
Mat_<double> R({2, 2}, {a, -b, b, a}); // from example
*/ */
template<typename _Tp> class MatCommaInitializer_ template<typename _Tp> class MatCommaInitializer_
{ {
@@ -1083,7 +1090,7 @@ public:
/** @overload /** @overload
*/ */
template<typename _Tp> explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer); template<typename _Tp> CV_DEPRECATED_EXTERNAL explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
//! download data from GpuMat //! download data from GpuMat
explicit Mat(const cuda::GpuMat& m); explicit Mat(const cuda::GpuMat& m);
@@ -2338,7 +2345,7 @@ public:
template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true); template<int m, int n> explicit Mat_(const Matx<typename DataType<_Tp>::channel_type, m, n>& mtx, bool copyData=true);
explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); explicit Mat_(const Point_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true); explicit Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer); CV_DEPRECATED_EXTERNAL explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
Mat_(std::initializer_list<_Tp> values); Mat_(std::initializer_list<_Tp> values);
explicit Mat_(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> values); explicit Mat_(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> values);
@@ -3011,7 +3011,7 @@ MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
} }
template<typename _Tp, typename T2> static inline template<typename _Tp, typename T2> CV_DEPRECATED_EXTERNAL static inline
MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val) MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val)
{ {
MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m); MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
@@ -115,7 +115,7 @@ public:
int idx; int idx;
}; };
template<typename _Tp, typename _T2, int m, int n> static inline template<typename _Tp, typename _T2, int m, int n> CV_DEPRECATED_EXTERNAL static inline
MatxCommaInitializer<_Tp, m, n> operator << (const Matx<_Tp, m, n>& mtx, _T2 val) MatxCommaInitializer<_Tp, m, n> operator << (const Matx<_Tp, m, n>& mtx, _T2 val)
{ {
MatxCommaInitializer<_Tp, m, n> commaInitializer((Matx<_Tp, m, n>*)&mtx); MatxCommaInitializer<_Tp, m, n> commaInitializer((Matx<_Tp, m, n>*)&mtx);
@@ -738,7 +738,7 @@ public:
Vec<_Tp, m> operator *() const; Vec<_Tp, m> operator *() const;
}; };
template<typename _Tp, typename _T2, int cn> static inline template<typename _Tp, typename _T2, int cn> CV_DEPRECATED_EXTERNAL static inline
VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val) VecCommaInitializer<_Tp, cn> operator << (const Vec<_Tp, cn>& vec, _T2 val)
{ {
VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec); VecCommaInitializer<_Tp, cn> commaInitializer((Vec<_Tp, cn>*)&vec);
+12
View File
@@ -1465,6 +1465,8 @@ TEST(Core_Matx, from_initializer_list)
Mat_<double> a = (Mat_<double>(2,2) << 10, 11, 12, 13); Mat_<double> a = (Mat_<double>(2,2) << 10, 11, 12, 13);
Matx22d b = {10, 11, 12, 13}; Matx22d b = {10, 11, 12, 13};
ASSERT_EQ( cvtest::norm(a, b, NORM_INF), 0.); ASSERT_EQ( cvtest::norm(a, b, NORM_INF), 0.);
Mat_<double> c({2, 2}, {10, 11, 12, 13});
ASSERT_EQ( cvtest::norm(c, b, NORM_INF), 0.);
} }
TEST(Core_Mat, regression_9507) TEST(Core_Mat, regression_9507)
@@ -1918,6 +1920,11 @@ TEST(Mat, from_initializer_list)
auto D = Mat_<double>({2, 3}, {1, 2, 3, 4, 5, 6}); auto D = Mat_<double>({2, 3}, {1, 2, 3, 4, 5, 6});
EXPECT_EQ(2, D.rows); EXPECT_EQ(2, D.rows);
EXPECT_EQ(3, D.cols); EXPECT_EQ(3, D.cols);
double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
Mat R({2, 2}, {a, -b, b, a});
ASSERT_EQ(CV_64FC1, R.type());
ASSERT_EQ(cv::Size(2, 2), R.size());
} }
TEST(Mat_, from_initializer_list) TEST(Mat_, from_initializer_list)
@@ -1929,6 +1936,11 @@ TEST(Mat_, from_initializer_list)
ASSERT_DOUBLE_EQ(cvtest::norm(A, B, NORM_INF), 0.); ASSERT_DOUBLE_EQ(cvtest::norm(A, B, NORM_INF), 0.);
ASSERT_DOUBLE_EQ(cvtest::norm(A, C, NORM_INF), 0.); ASSERT_DOUBLE_EQ(cvtest::norm(A, C, NORM_INF), 0.);
ASSERT_DOUBLE_EQ(cvtest::norm(B, C, NORM_INF), 0.); ASSERT_DOUBLE_EQ(cvtest::norm(B, C, NORM_INF), 0.);
double angle = 30, a = cos(angle*CV_PI/180), b = sin(angle*CV_PI/180);
Mat_<double> R({2, 2}, {a, -b, b, a});
ASSERT_EQ(CV_64FC1, R.type());
ASSERT_EQ(cv::Size(2, 2), R.size());
} }
+58 -103
View File
@@ -240,8 +240,8 @@ TEST(Imgproc_ConnectedComponents, missing_background_pixels)
TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats) TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats)
{ {
cv::Mat1b img(16, 16); cv::Mat1b img({16, 16}, {
img << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0,
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 0,
0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0,
@@ -256,7 +256,8 @@ TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats)
0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1; 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
});
cv::Mat1i labels; cv::Mat1i labels;
cv::Mat1i stats; cv::Mat1i stats;
@@ -360,15 +361,8 @@ TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats)
TEST(Imgproc_ConnectedComponents, chessboard_even) TEST(Imgproc_ConnectedComponents, chessboard_even)
{ {
cv::Size size(16, 16); const auto size = {16, 16};
cv::Mat1b input(size); cv::Mat1b input(size, {
cv::Mat1i output_8c(size);
cv::Mat1i output_4c(size);
// Chessboard image with even number of rows and cols
// Note that this is the maximum number of labels for 4-way connectivity
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
@@ -384,9 +378,9 @@ TEST(Imgproc_ConnectedComponents, chessboard_even)
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1; 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
});
output_8c << cv::Mat1i output_8c(size, {
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
@@ -402,9 +396,9 @@ TEST(Imgproc_ConnectedComponents, chessboard_even)
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1; 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
});
output_4c << cv::Mat1i output_4c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16,
17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0,
@@ -420,8 +414,11 @@ TEST(Imgproc_ConnectedComponents, chessboard_even)
97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0, 97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0,
0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112, 0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112,
113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119, 0, 120, 0, 113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119, 0, 120, 0,
0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127, 0, 128; 0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127, 0, 128
} });
// Chessboard image with even number of rows and cols
// Note that this is the maximum number of labels for 4-way connectivity
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
@@ -448,15 +445,8 @@ TEST(Imgproc_ConnectedComponents, chessboard_even)
TEST(Imgproc_ConnectedComponents, chessboard_odd) TEST(Imgproc_ConnectedComponents, chessboard_odd)
{ {
cv::Size size(15, 15); const auto size = {15, 15};
cv::Mat1b input(size); cv::Mat1b input(size, {
cv::Mat1i output_8c(size);
cv::Mat1i output_4c(size);
// Chessboard image with odd number of rows and cols
// Note that this is the maximum number of labels for 4-way connectivity
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -471,9 +461,9 @@ TEST(Imgproc_ConnectedComponents, chessboard_odd)
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1; 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
});
output_8c << cv::Mat1i output_8c(size, {
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -488,9 +478,9 @@ TEST(Imgproc_ConnectedComponents, chessboard_odd)
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1; 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
});
output_4c << cv::Mat1i output_4c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0,
16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23,
@@ -505,8 +495,11 @@ TEST(Imgproc_ConnectedComponents, chessboard_odd)
0, 84, 0, 85, 0, 86, 0, 87, 0, 88, 0, 89, 0, 90, 0, 0, 84, 0, 85, 0, 86, 0, 87, 0, 88, 0, 89, 0, 90, 0,
91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 96, 0, 97, 0, 98, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 96, 0, 97, 0, 98,
0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0, 105, 0, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0, 105, 0,
106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112, 0, 113; 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112, 0, 113
} });
// Chessboard image with odd number of rows and cols
// Note that this is the maximum number of labels for 4-way connectivity
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
@@ -533,13 +526,8 @@ TEST(Imgproc_ConnectedComponents, chessboard_odd)
TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even) TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
{ {
cv::Size size(16, 16); const auto size = {16, 16};
cv::Mat1b input(size); cv::Mat1b input(size, {
cv::Mat1i output_8c(size);
cv::Mat1i output_4c(size);
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
@@ -555,9 +543,9 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
});
output_8c << cv::Mat1i output_8c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0,
@@ -573,9 +561,9 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
});
output_4c << cv::Mat1i output_4c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0,
@@ -591,8 +579,8 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0; 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
} });
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
@@ -619,13 +607,8 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd) TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
{ {
cv::Size size(15, 15); const auto size = {15, 15};
cv::Mat1b input(size); cv::Mat1b input(size, {
cv::Mat1i output_8c(size);
cv::Mat1i output_4c(size);
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
@@ -640,9 +623,9 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1; 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1
});
output_8c << cv::Mat1i output_8c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16,
@@ -657,9 +640,9 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64; 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64
});
output_4c << cv::Mat1i output_4c(size, {
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16,
@@ -674,8 +657,8 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64; 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64
} });
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
@@ -702,24 +685,10 @@ TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
TEST(Imgproc_ConnectedComponents, single_row) TEST(Imgproc_ConnectedComponents, single_row)
{ {
cv::Size size(1, 15); const auto size = {1, 15};
cv::Mat1b input(size); cv::Mat1b input(size, {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1});
cv::Mat1i output_8c(size); cv::Mat1i output_8c(size, {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8});
cv::Mat1i output_4c(size); cv::Mat1i output_4c(size, {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8});
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
output_8c <<
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
output_4c <<
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
}
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
@@ -746,24 +715,10 @@ TEST(Imgproc_ConnectedComponents, single_row)
TEST(Imgproc_ConnectedComponents, single_column) TEST(Imgproc_ConnectedComponents, single_column)
{ {
cv::Size size(15, 1); const auto size = {15, 1};
cv::Mat1b input(size); cv::Mat1b input(size, {1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1});
cv::Mat1i output_8c(size); cv::Mat1i output_8c(size, {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8});
cv::Mat1i output_4c(size); cv::Mat1i output_4c(size, {1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8});
{
input <<
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
output_8c <<
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
output_4c <<
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
}
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI }; int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
+16 -11
View File
@@ -242,33 +242,38 @@ int main (const int argc, const char * argv[])
double angle; double angle;
switch (mode_temp) { switch (mode_temp) {
case MOTION_TRANSLATION: case MOTION_TRANSLATION:
warpGround = (Mat_<float>(2,3) << 1, 0, (rng.uniform(10.f, 20.f)), warpGround = Mat_<float>({2,3}, {
0, 1, (rng.uniform(10.f, 20.f))); 1, 0, (rng.uniform(10.f, 20.f)),
0, 1, (rng.uniform(10.f, 20.f))
});
warpAffine(target_image, template_image, warpGround, warpAffine(target_image, template_image, warpGround,
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
break; break;
case MOTION_EUCLIDEAN: case MOTION_EUCLIDEAN:
angle = CV_PI/30 + CV_PI*rng.uniform((double)-2.f, (double)2.f)/180; angle = CV_PI/30 + CV_PI*rng.uniform((double)-2.f, (double)2.f)/180;
warpGround = (Mat_<float>(2,3) << cos(angle), -sin(angle), (rng.uniform(10.f, 20.f)), warpGround = Mat_<float>({2,3}, {
sin(angle), cos(angle), (rng.uniform(10.f, 20.f))); (float)cos(angle), (float)-sin(angle), (rng.uniform(10.f, 20.f)),
(float)sin(angle), (float)cos(angle), (rng.uniform(10.f, 20.f))
});
warpAffine(target_image, template_image, warpGround, warpAffine(target_image, template_image, warpGround,
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
break; break;
case MOTION_AFFINE: case MOTION_AFFINE:
warpGround = (Mat_<float>(2,3) << (1-rng.uniform(-0.05f, 0.05f)), warpGround = Mat_<float>({2,3}, {
(rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)), (1-rng.uniform(-0.05f, 0.05f)), (rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)),
(rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)), (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)), (rng.uniform(10.f, 20.f))
(rng.uniform(10.f, 20.f))); });
warpAffine(target_image, template_image, warpGround, warpAffine(target_image, template_image, warpGround,
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
break; break;
case MOTION_HOMOGRAPHY: case MOTION_HOMOGRAPHY:
warpGround = (Mat_<float>(3,3) << (1-rng.uniform(-0.05f, 0.05f)), warpGround = Mat_<float>({3,3}, {
(rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)), (1-rng.uniform(-0.05f, 0.05f)), (rng.uniform(-0.03f, 0.03f)), (rng.uniform(10.f, 20.f)),
(rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)),(rng.uniform(10.f, 20.f)), (rng.uniform(-0.03f, 0.03f)), (1-rng.uniform(-0.05f, 0.05f)),(rng.uniform(10.f, 20.f)),
(rng.uniform(0.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f); (rng.uniform(0.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f
});
warpPerspective(target_image, template_image, warpGround, warpPerspective(target_image, template_image, warpGround,
Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP); Size(200,200), INTER_LINEAR + WARP_INVERSE_MAP);
break; break;
+1 -1
View File
@@ -46,7 +46,7 @@ int main(int, char**)
img = Scalar::all(0); img = Scalar::all(0);
state.at<float>(0) = 0.0f; state.at<float>(0) = 0.0f;
state.at<float>(1) = 2.f * (float)CV_PI / 6; state.at<float>(1) = 2.f * (float)CV_PI / 6;
KF.transitionMatrix = (Mat_<float>(2, 2) << 1, 1, 0, 1); KF.transitionMatrix = Mat_<float>({2, 2}, {1, 1, 0, 1});
setIdentity(KF.measurementMatrix); setIdentity(KF.measurementMatrix);
setIdentity(KF.processNoiseCov, Scalar::all(1e-5)); setIdentity(KF.processNoiseCov, Scalar::all(1e-5));
+1 -1
View File
@@ -120,7 +120,7 @@ static Point3f image2plane(Point2f imgpt, const Mat& R, const Mat& tvec,
{ {
Mat R1 = R.clone(); Mat R1 = R.clone();
R1.col(2) = R1.col(2)*Z + tvec; R1.col(2) = R1.col(2)*Z + tvec;
Mat_<double> v = (cameraMatrix*R1).inv()*(Mat_<double>(3,1) << imgpt.x, imgpt.y, 1); Mat_<double> v = (cameraMatrix*R1).inv()*(Mat_<double>({3,1}, {imgpt.x, imgpt.y, 1}));
double iw = fabs(v(2,0)) > DBL_EPSILON ? 1./v(2,0) : 0; double iw = fabs(v(2,0)) > DBL_EPSILON ? 1./v(2,0) : 0;
return Point3f((float)(v(0,0)*iw), (float)(v(1,0)*iw), (float)Z); return Point3f((float)(v(0,0)*iw), (float)(v(1,0)*iw), (float)Z);
} }
@@ -5,7 +5,7 @@
using namespace cv; using namespace cv;
int main(){ int main(){
Mat input_image = (Mat_<uchar>(8, 8) << Mat input_image = Mat_<uchar>({8, 8}, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 255, 255, 255, 0, 0, 0, 255, 0, 255, 255, 255, 0, 0, 0, 255,
0, 255, 255, 255, 0, 0, 0, 0, 0, 255, 255, 255, 0, 0, 0, 0,
@@ -13,12 +13,14 @@ int main(){
0, 0, 255, 0, 0, 0, 0, 0, 0, 0, 255, 0, 0, 0, 0, 0,
0, 0, 255, 0, 0, 255, 255, 0, 0, 0, 255, 0, 0, 255, 255, 0,
0, 255, 0, 255, 0, 0, 255, 0, 0, 255, 0, 255, 0, 0, 255, 0,
0, 255, 255, 255, 0, 0, 0, 0); 0, 255, 255, 255, 0, 0, 0, 0
});
Mat kernel = (Mat_<int>(3, 3) << Mat kernel = Mat_<int>({3, 3}, {
0, 1, 0, 0, 1, 0,
1, -1, 1, 1, -1, 1,
0, 1, 0); 0, 1, 0
});
Mat output_image; Mat output_image;
morphologyEx(input_image, output_image, MORPH_HITMISS, kernel); morphologyEx(input_image, output_image, MORPH_HITMISS, kernel);
@@ -41,10 +41,11 @@ int main(int argc, char *argv[])
//! [sharp] //! [sharp]
// Create a kernel that we will use to sharpen our image // Create a kernel that we will use to sharpen our image
Mat kernel = (Mat_<float>(3,3) << Mat kernel = Mat_<float>({3,3}, {
1, 1, 1, 1, 1, 1,
1, -8, 1, 1, -8, 1,
1, 1, 1); // an approximation of second derivative, a quite strong kernel 1, 1, 1
}); // an approximation of second derivative, a quite strong kernel
// do the laplacian filtering as it is // do the laplacian filtering as it is
// well, we need to convert everything in something more deeper then CV_8U // well, we need to convert everything in something more deeper then CV_8U
@@ -273,9 +273,11 @@ int main(int argc, char *argv[])
namedWindow("Output3", 1); namedWindow("Output3", 1);
imshow("Input", src); imshow("Input", src);
kernel = (Mat_<double>(3, 3) << 1, 0, -1, kernel = Mat_<double>({3, 3}, {
1, 0, -1, 1, 0, -1,
1, 0, -1); 1, 0, -1,
1, 0, -1
});
/* /*
Uncomment the kernels you want to use or write your own kernels to test out Uncomment the kernels you want to use or write your own kernels to test out
@@ -51,9 +51,11 @@ int main( int argc, char* argv[])
waitKey(); waitKey();
//![kern] //![kern]
Mat kernel = (Mat_<char>(3,3) << 0, -1, 0, Mat kernel = Mat_<char>({3,3}, {
0, -1, 0,
-1, 5, -1, -1, 5, -1,
0, -1, 0); 0, -1, 0
});
//![kern] //![kern]
t = (double)getTickCount(); t = (double)getTickCount();
@@ -54,14 +54,9 @@ int main(int,char**)
//! [matlab] //! [matlab]
// create a 3x3 double-precision identity matrix // create a 3x3 double-precision identity matrix
//! [comma]
Mat C = (Mat_<double>(3,3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
cout << "C = " << endl << " " << C << endl << endl;
//! [comma]
// do the same with initializer_list
//! [list] //! [list]
C = (Mat_<double>({0, -1, 0, -1, 5, -1, 0, -1, 0})).reshape(3); Mat C = Mat_<double>({3, 3}, {0, -1, 0, -1, 5, -1, 0, -1, 0});
cout << "C = " << endl << " " << C << endl << endl; cout << "C = " << endl << " " << C << endl << endl;
//! [list] //! [list]
@@ -201,9 +201,11 @@ int main(int argc, char *argv[])
namedWindow("Output", 1); namedWindow("Output", 1);
imshow("Input", src); imshow("Input", src);
kernel = (Mat_<float>(3, 3) << 1, 0, -1, kernel = Mat_<float>({3, 3}, {
2, 0, -2, 1., 0., -1.,
1, 0, -1); 2., 0., -2.,
1., 0., -1.
});
t = (double)getTickCount(); t = (double)getTickCount();
@@ -92,7 +92,7 @@ void decomposeHomography(const string &img1Path, const string &img2Path, const S
//! [compute-camera-displacement] //! [compute-camera-displacement]
//! [compute-plane-normal-at-camera-pose-1] //! [compute-plane-normal-at-camera-pose-1]
Mat normal = (Mat_<double>(3,1) << 0, 0, 1); Mat normal = Mat_<double>({3,1}, {0, 0, 1});
Mat normal1 = R1*normal; Mat normal1 = R1*normal;
//! [compute-plane-normal-at-camera-pose-1] //! [compute-plane-normal-at-camera-pose-1]
@@ -112,7 +112,7 @@ void homographyFromCameraDisplacement(const string &img1Path, const string &img2
//! [compute-camera-displacement] //! [compute-camera-displacement]
//! [compute-plane-normal-at-camera-pose-1] //! [compute-plane-normal-at-camera-pose-1]
Mat normal = (Mat_<double>(3,1) << 0, 0, 1); Mat normal = Mat_<double>({3,1}, {0, 0, 1});
Mat normal1 = R1*normal; Mat normal1 = R1*normal;
//! [compute-plane-normal-at-camera-pose-1] //! [compute-plane-normal-at-camera-pose-1]
@@ -14,23 +14,29 @@ void basicPanoramaStitching(const string &img1Path, const string &img2Path)
Mat img2 = imread( samples::findFile( img2Path ) ); Mat img2 = imread( samples::findFile( img2Path ) );
//! [camera-pose-from-Blender-at-location-1] //! [camera-pose-from-Blender-at-location-1]
Mat c1Mo = (Mat_<double>(4,4) << 0.9659258723258972, 0.2588190734386444, 0.0, 1.5529145002365112, Mat c1Mo = Mat_<double>({4,4}, {
0.9659258723258972, 0.2588190734386444, 0.0, 1.5529145002365112,
0.08852133899927139, -0.3303661346435547, -0.9396926164627075, -0.10281121730804443, 0.08852133899927139, -0.3303661346435547, -0.9396926164627075, -0.10281121730804443,
-0.24321036040782928, 0.9076734185218811, -0.342020183801651, 6.130080699920654, -0.24321036040782928, 0.9076734185218811, -0.342020183801651, 6.130080699920654,
0, 0, 0, 1); 0, 0, 0, 1
});
//! [camera-pose-from-Blender-at-location-1] //! [camera-pose-from-Blender-at-location-1]
//! [camera-pose-from-Blender-at-location-2] //! [camera-pose-from-Blender-at-location-2]
Mat c2Mo = (Mat_<double>(4,4) << 0.9659258723258972, -0.2588190734386444, 0.0, -1.5529145002365112, Mat c2Mo = Mat_<double>({4,4}, {
0.9659258723258972, -0.2588190734386444, 0.0, -1.5529145002365112,
-0.08852133899927139, -0.3303661346435547, -0.9396926164627075, -0.10281121730804443, -0.08852133899927139, -0.3303661346435547, -0.9396926164627075, -0.10281121730804443,
0.24321036040782928, 0.9076734185218811, -0.342020183801651, 6.130080699920654, 0.24321036040782928, 0.9076734185218811, -0.342020183801651, 6.130080699920654,
0, 0, 0, 1); 0, 0, 0, 1
});
//! [camera-pose-from-Blender-at-location-2] //! [camera-pose-from-Blender-at-location-2]
//! [camera-intrinsics-from-Blender] //! [camera-intrinsics-from-Blender]
Mat cameraMatrix = (Mat_<double>(3,3) << 700.0, 0.0, 320.0, Mat cameraMatrix = Mat_<double>({3,3}, {
700.0, 0.0, 320.0,
0.0, 700.0, 240.0, 0.0, 700.0, 240.0,
0, 0, 1); 0, 0, 1
});
//! [camera-intrinsics-from-Blender] //! [camera-intrinsics-from-Blender]
//! [extract-rotation] //! [extract-rotation]
@@ -53,7 +53,7 @@ void perspectiveCorrection(const string &img1Path, const string &img2Path, const
hconcat(img1, img2, img_draw_matches); hconcat(img1, img2, img_draw_matches);
for (size_t i = 0; i < corners1.size(); i++) for (size_t i = 0; i < corners1.size(); i++)
{ {
Mat pt1 = (Mat_<double>(3,1) << corners1[i].x, corners1[i].y, 1); Mat pt1 = Mat_<double>({3,1}, {corners1[i].x, corners1[i].y, 1});
Mat pt2 = H * pt1; Mat pt2 = H * pt1;
pt2 /= pt2.at<double>(2); pt2 /= pt2.at<double>(2);
@@ -41,7 +41,7 @@ int main(int, char**)
{ {
for (int j = 0; j < image.cols; j++) for (int j = 0; j < image.cols; j++)
{ {
Mat sampleMat = (Mat_<float>(1,2) << j,i); Mat sampleMat = Mat_<float>({1,2}, {(float)j,(float)i});
float response = svm->predict(sampleMat); float response = svm->predict(sampleMat);
if (response == 1) if (response == 1)
@@ -96,7 +96,7 @@ int main()
{ {
for (int j = 0; j < I.cols; j++) for (int j = 0; j < I.cols; j++)
{ {
Mat sampleMat = (Mat_<float>(1,2) << j, i); Mat sampleMat = Mat_<float>({1,2}, {(float)j, (float)i});
float response = svm->predict(sampleMat); float response = svm->predict(sampleMat);
if (response == 1) I.at<Vec3b>(i,j) = green; if (response == 1) I.at<Vec3b>(i,j) = green;
@@ -17,9 +17,9 @@ using namespace cv;
int main() int main()
{ {
//! [example] //! [example]
Mat m1 = (Mat_<uchar>(2,2) << 1,4,7,10); Mat m1 = Mat_<uchar>({2,2}, {1,4,7,10});
Mat m2 = (Mat_<uchar>(2,2) << 2,5,8,11); Mat m2 = Mat_<uchar>({2,2}, {2,5,8,11});
Mat m3 = (Mat_<uchar>(2,2) << 3,6,9,12); Mat m3 = Mat_<uchar>({2,2}, {3,6,9,12});
Mat channels[3] = {m1, m2, m3}; Mat channels[3] = {m1, m2, m3};
Mat m; Mat m;
@@ -20,7 +20,7 @@ int main()
{ {
{ {
//! [example] //! [example]
Mat m = (Mat_<uchar>(3,2) << 1,2,3,4,5,6); Mat m = Mat_<uchar>({3,2}, {1,2,3,4,5,6});
Mat col_sum, row_sum; Mat col_sum, row_sum;
reduce(m, col_sum, 0, REDUCE_SUM, CV_32F); reduce(m, col_sum, 0, REDUCE_SUM, CV_32F);
+1 -1
View File
@@ -324,7 +324,7 @@ inline void preprocess(const Mat& frame, Net& net, Size inpSize, float scale,
if (net.getLayer(0)->outputNameToIndex("im_info") != -1) // Faster-RCNN or R-FCN if (net.getLayer(0)->outputNameToIndex("im_info") != -1) // Faster-RCNN or R-FCN
{ {
resize(frame, frame, inpSize); resize(frame, frame, inpSize);
Mat imInfo = (Mat_<float>(1, 3) << inpSize.height, inpSize.width, 1.6f); Mat imInfo = Mat_<float>({1, 3}, {(float)inpSize.height, (float)inpSize.width, 1.6f});
net.setInput(imInfo, "im_info"); net.setInput(imInfo, "im_info");
} }
} }