Merge pull request #29948 from vrabaud:comma_initializer

Remove deprecated CommaInitializer API - #29948

This goes hand in hand with https://github.com/opencv/opencv_contrib/pull/4217

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [ ] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
This commit is contained in:
Vincent Rabaud
2026-09-16 13:59:50 +03:00
committed by GitHub
parent 61127d3812
commit 551dbcac54
58 changed files with 705 additions and 804 deletions
+4 -4
View File
@@ -61,7 +61,7 @@ static Mat rot2quatMinimal(const Mat& R)
qz = 0.25 * S;
}
return (Mat_<double>(3,1) << qx, qy, qz);
return Mat_<double>({3,1}, {qx, qy, qz});
}
static Mat skew(const Mat& v)
@@ -71,9 +71,9 @@ static Mat skew(const Mat& v)
double vx = v.at<double>(0,0);
double vy = v.at<double>(1,0);
double vz = v.at<double>(2,0);
return (Mat_<double>(3,3) << 0, -vz, vy,
return Mat_<double>({3,3}, {0, -vz, vy,
vz, 0, -vx,
-vy, vx, 0);
-vy, vx, 0});
}
// R = quatMinimal2rot(q)
@@ -135,7 +135,7 @@ static Mat rot2quat(const Mat& R)
qz = 0.25 * S;
}
return (Mat_<double>(4,1) << qw, qx, qy, qz);
return Mat_<double>({4,1}, {qw, qx, qy, qz});
}
// R = quat2rot(q)
@@ -761,82 +761,100 @@ TEST(Calib3d_CalibrateHandEye, regression_24871)
std::vector<Mat> R_gripper2base, t_gripper2base;
Mat T_true_cam2gripper;
T_true_cam2gripper = (cv::Mat_<double>(4, 4) << 0, 0, -1, 0.1,
1, 0, 0, 0.2,
0, -1, 0, 0.3,
0, 0, 0, 1);
T_true_cam2gripper = cv::Mat_<double>({4, 4}, {
0, 0, -1, 0.1,
1, 0, 0, 0.2,
0, -1, 0, 0.3,
0, 0, 0, 1
});
R_target2cam.push_back((cv::Mat_<double>(3, 3) <<
R_target2cam.push_back(cv::Mat_<double>({3, 3}, {
0.04964505493834381, 0.5136826827431226, 0.8565427426404346,
-0.3923117691818854, 0.7987004864191318, -0.4562554205214679,
-0.9184916136152514, -0.3133809733274676, 0.2411752915926112));
t_target2cam.push_back((cv::Mat_<double>(3, 1) <<
-0.9184916136152514, -0.3133809733274676, 0.2411752915926112
}));
t_target2cam.push_back(cv::Mat_<double>({3, 1}, {
-1.588728904724121,
0.07843752950429916,
-1.002813339233398));
-1.002813339233398
}));
R_gripper2base.push_back((cv::Mat_<double>(3, 3) <<
R_gripper2base.push_back(cv::Mat_<double>({3, 3}, {
-0.4143743581399177, -0.6105088815982459, -0.6749613298595637,
-0.1598851232573451, -0.6812625208693498, 0.71436554019614,
-0.895952364066927, 0.4039310376145889, 0.1846864320259794));
t_gripper2base.push_back((cv::Mat_<double>(3, 1) <<
-0.895952364066927, 0.4039310376145889, 0.1846864320259794
}));
t_gripper2base.push_back(cv::Mat_<double>({3, 1}, {
-1.249274406461827,
-1.916570771580279,
2.005069553422765));
2.005069553422765
}));
R_target2cam.push_back((cv::Mat_<double>(3, 3) <<
R_target2cam.push_back(cv::Mat_<double>({3, 3}, {
-0.3048000068139332, 0.6971848192711539, 0.6488684640388026,
-0.9377589344241749, -0.3387497187353627, -0.07652979135179161,
0.1664486009369332, -0.6318084803439735, 0.7570422097951847));
t_target2cam.push_back((cv::Mat_<double>(3, 1) <<
0.1664486009369332, -0.6318084803439735, 0.7570422097951847
}));
t_target2cam.push_back(cv::Mat_<double>({3, 1}, {
-1.906493663787842,
-0.07281044125556946,
0.6088893413543701));
0.6088893413543701
}));
R_gripper2base.push_back((cv::Mat_<double>(3, 3) <<
R_gripper2base.push_back(cv::Mat_<double>({3, 3}, {
0.7262439860936567, -0.201662933718935, -0.6571923111439066,
-0.4640017362244384, -0.8491808316335328, -0.2521791108852766,
-0.5072199339965884, 0.4880819361030014, -0.7102844234575628));
t_gripper2base.push_back((cv::Mat_<double>(3, 1) <<
-0.5072199339965884, 0.4880819361030014, -0.7102844234575628
}));
t_gripper2base.push_back(cv::Mat_<double>({3, 1}, {
-0.7375172846804027,
-2.579760910816792,
1.336561572270101));
1.336561572270101
}));
R_target2cam.push_back((cv::Mat_<double>(3, 3) <<
R_target2cam.push_back(cv::Mat_<double>({3, 3}, {
-0.590234879685801, -0.7051138289845309, -0.3929850823848928,
0.6017371069678565, -0.7088332765096816, 0.3680595606834615,
-0.5380847896941907, -0.01923211603859842, 0.8426712792141644));
t_target2cam.push_back((cv::Mat_<double>(3, 1) <<
-0.5380847896941907, -0.01923211603859842, 0.8426712792141644
}));
t_target2cam.push_back(cv::Mat_<double>({3, 1}, {
-0.9809040427207947,
-0.2707894444465637,
-0.2577074766159058));
-0.2577074766159058
}));
R_gripper2base.push_back((cv::Mat_<double>(3, 3) <<
R_gripper2base.push_back(cv::Mat_<double>({3, 3}, {
0.2541996332132083, 0.6186461729765909, 0.7434106934499181,
0.2194912986375709, 0.711701808961156, -0.6673111005698995,
-0.9419161938817396, 0.3328024155303503, 0.04512688689130734));
t_gripper2base.push_back((cv::Mat_<double>(3, 1) <<
-0.9419161938817396, 0.3328024155303503, 0.04512688689130734
}));
t_gripper2base.push_back(cv::Mat_<double>({3, 1}, {
-1.040123533893404,
-0.1303773962721222,
1.068029475621886));
1.068029475621886
}));
R_target2cam.push_back((cv::Mat_<double>(3, 3) <<
R_target2cam.push_back(cv::Mat_<double>({3, 3}, {
0.7643667483125168, -0.08523002870239212, 0.63912386614923,
-0.2583463792779588, 0.8676987164647345, 0.424683512464778,
-0.5907627462764713, -0.489729292214425, 0.6412211770980741));
t_target2cam.push_back((cv::Mat_<double>(3, 1) <<
-0.5907627462764713, -0.489729292214425, 0.6412211770980741
}));
t_target2cam.push_back(cv::Mat_<double>({3, 1}, {
-1.58987033367157,
-1.924914002418518,
-0.3109001517295837));
-0.3109001517295837
}));
R_gripper2base.push_back((cv::Mat_<double>(3, 3) <<
R_gripper2base.push_back(cv::Mat_<double>({3, 3}, {
0.116348305340805, -0.9917998080681939, 0.0528792261688552,
-0.2760629007224059, 0.01884966191381591, 0.9609547154213178,
-0.9540714578526358, -0.1264034452126562, -0.2716060057313114));
t_gripper2base.push_back((cv::Mat_<double>(3, 1) <<
-0.9540714578526358, -0.1264034452126562, -0.2716060057313114
}));
t_gripper2base.push_back(cv::Mat_<double>({3, 1}, {
-2.551899142554571,
-2.986937398237611,
1.317613923218308));
1.317613923218308
}));
Mat R_true_cam2gripper;
Mat t_true_cam2gripper;
@@ -387,8 +387,7 @@ protected:
double cx = bg.cols/2 + (40 * (double)rng - 20);
double cy = bg.rows/2 + (40 * (double)rng - 20);
Mat_<double> camMat(3, 3);
camMat << fx, 0., cx, 0, fy, cy, 0., 0., 1.;
Mat_<double> camMat({3, 3}, {fx, 0., cx, 0, fy, cy, 0., 0., 1.});
double k1 = 0.5 + (double)rng/5;
double k2 = (double)rng/5;
@@ -397,8 +396,7 @@ protected:
double p1 = 0.001 + (double)rng/10;
double p2 = 0.001 + (double)rng/10;
Mat_<double> distCoeffs(1, 5, 0.0);
distCoeffs << k1, k2, p1, p2, k3;
Mat_<double> distCoeffs({1, 5}, {k1, k2, p1, p2, k3});
ChessBoardGenerator cbg(Size(9, 8));
cbg.min_cos = 0.9;
@@ -106,8 +106,8 @@ void CV_CameraCalibrationBadArgTest::run( int /* start_from */ )
Mat_<float> camMat(3, 3);
Mat_<float> distCoeffs0(1, 5);
camMat << 300.f, 0.f, imgSize.width/2.f, 0, 300.f, imgSize.height/2.f, 0.f, 0.f, 1.f;
distCoeffs0 << 1.2f, 0.2f, 0.f, 0.f, 0.f;
camMat = Mat_<float>({3, 3}, {300.f, 0.f, imgSize.width/2.f, 0, 300.f, imgSize.height/2.f, 0.f, 0.f, 1.f});
distCoeffs0 = Mat_<float>({1, 5}, {1.2f, 0.2f, 0.f, 0.f, 0.f});
ChessBoardGenerator cbg(Size(8,6));
Size corSize = cbg.cornersSize();
@@ -267,8 +267,8 @@ public:
CV_ProjectPoints2BadArgTest() : camMat(3, 3), distCoeffs(1, 5)
{
Size imsSize(800, 600);
camMat << 300.f, 0.f, imsSize.width/2.f, 0, 300.f, imsSize.height/2.f, 0.f, 0.f, 1.f;
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
camMat = Mat_<float>({3, 3}, {300.f, 0.f, imsSize.width/2.f, 0, 300.f, imsSize.height/2.f, 0.f, 0.f, 1.f});
distCoeffs = Mat_<float>({1, 5}, {1.2f, 0.2f, 0.f, 0.f, 0.f});
}
~CV_ProjectPoints2BadArgTest() {}
protected:
+8 -8
View File
@@ -1183,12 +1183,12 @@ The function horizontally concatenates two or more cv::Mat matrices (with the sa
CV_EXPORTS void hconcat(const Mat* src, size_t nsrc, OutputArray dst);
/** @overload
@code{.cpp}
cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 4,
cv::Mat_<float> A = cv::Mat_<float>({3, 2}, { 1, 4,
2, 5,
3, 6);
cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 7, 10,
3, 6 });
cv::Mat_<float> B = cv::Mat_<float>({3, 2}, { 7, 10,
8, 11,
9, 12);
9, 12 });
cv::Mat C;
cv::hconcat(A, B, C);
@@ -1245,12 +1245,12 @@ The function vertically concatenates two or more cv::Mat matrices (with the same
CV_EXPORTS void vconcat(const Mat* src, size_t nsrc, OutputArray dst);
/** @overload
@code{.cpp}
cv::Mat_<float> A = (cv::Mat_<float>(3, 2) << 1, 7,
cv::Mat_<float> A = cv::Mat_<float>({3, 2}, { 1, 7,
2, 8,
3, 9);
cv::Mat_<float> B = (cv::Mat_<float>(3, 2) << 4, 10,
3, 9 });
cv::Mat_<float> B = cv::Mat_<float>({3, 2}, { 4, 10,
5, 11,
6, 12);
6, 12 });
cv::Mat C;
cv::vconcat(A, B, C);
+3 -44
View File
@@ -668,42 +668,6 @@ public:
};
//////////////////////////////// MatCommaInitializer //////////////////////////////////
/** @brief Comma-separated Matrix Initializer
The class instances are usually not created explicitly.
Instead, they are created on "matrix << firstValue" operator.
The sample below initializes 2x2 rotation matrix:
\code
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);
\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
\endcode
*/
template<typename _Tp> class MatCommaInitializer_
{
public:
//! the constructor, created by "matrix << firstValue" operator, where matrix is cv::Mat
MatCommaInitializer_(Mat_<_Tp>* _m);
//! the operator that takes the next value and put it to the matrix
template<typename T2> MatCommaInitializer_<_Tp>& operator , (T2 v);
//! another form of conversion operator
operator Mat_<_Tp>() const;
protected:
MatIterator_<_Tp> it;
};
/////////////////////////////////////// Mat ///////////////////////////////////////////
// note that umatdata might be allocated together
@@ -890,7 +854,7 @@ sub-matrices.
- Use a comma-separated initializer:
@code
// create a 3x3 double-precision identity matrix
Mat M = (Mat_<double>(3,3) << 1, 0, 0, 0, 1, 0, 0, 0, 1);
Mat M = Mat_<double>({3,3}, {1, 0, 0, 0, 1, 0, 0, 0, 1});
@endcode
With this approach, you first call a constructor of the Mat class with the proper parameters, and
then you just put `<< operator` followed by comma-separated values that can be constants,
@@ -1268,10 +1232,6 @@ public:
*/
template<typename _Tp> explicit Mat(const Point3_<_Tp>& pt, bool copyData=true);
/** @overload
*/
template<typename _Tp> CV_DEPRECATED_EXTERNAL explicit Mat(const MatCommaInitializer_<_Tp>& commaInitializer);
//! download data from GpuMat
explicit Mat(const cuda::GpuMat& m);
@@ -1384,10 +1344,10 @@ public:
immediately above the main one.
For example:
@code
Mat m = (Mat_<int>(3,3) <<
Mat m = Mat_<int>({3,3}, {
1,2,3,
4,5,6,
7,8,9);
7,8,9});
Mat d0 = m.diag(0);
Mat d1 = m.diag(1);
Mat d_1 = m.diag(-1);
@@ -2627,7 +2587,6 @@ public:
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 Point3_<typename DataType<_Tp>::channel_type>& pt, bool copyData=true);
CV_DEPRECATED_EXTERNAL explicit Mat_(const MatCommaInitializer_<_Tp>& commaInitializer);
Mat_(std::initializer_list<_Tp> values);
explicit Mat_(const std::initializer_list<int> sizes, const std::initializer_list<_Tp> values);
@@ -722,14 +722,6 @@ Mat::Mat(const Point3_<_Tp>& pt, bool copyData)
}
}
template<typename _Tp> inline
Mat::Mat(const MatCommaInitializer_<_Tp>& commaInitializer)
: flags(+MAGIC_VAL + traits::Type<_Tp>::value + CV_MAT_CONT_FLAG), dims(0), rows(0), cols(0), data(0),
datastart(0), dataend(0), allocator(0), u(0)
{
*this = commaInitializer.operator Mat_<_Tp>();
}
inline
Mat Mat::row(int y) const
{
@@ -1585,11 +1577,6 @@ Mat_<_Tp>::Mat_(const Point3_<typename DataType<_Tp>::channel_type>& pt, bool co
*this = clone();
}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(const MatCommaInitializer_<_Tp>& commaInitializer)
: Mat(commaInitializer)
{}
template<typename _Tp> inline
Mat_<_Tp>::Mat_(const std::vector<_Tp>& vec, bool copyData)
: Mat(vec, copyData)
@@ -3183,39 +3170,6 @@ SparseMatIterator_<_Tp> SparseMatIterator_<_Tp>::operator ++(int)
//////////////////////// MatCommaInitializer_ ///////////////////////
template<typename _Tp> inline
MatCommaInitializer_<_Tp>::MatCommaInitializer_(Mat_<_Tp>* _m)
: it(_m)
{}
template<typename _Tp> template<typename T2> inline
MatCommaInitializer_<_Tp>& MatCommaInitializer_<_Tp>::operator , (T2 v)
{
CV_DbgAssert( this->it < ((const Mat_<_Tp>*)this->it.m)->end() );
*this->it = _Tp(v);
++this->it;
return *this;
}
template<typename _Tp> inline
MatCommaInitializer_<_Tp>::operator Mat_<_Tp>() const
{
CV_DbgAssert( this->it == ((const Mat_<_Tp>*)this->it.m)->end() );
return Mat_<_Tp>(*this->it.m);
}
template<typename _Tp, typename T2> CV_DEPRECATED_EXTERNAL static inline
MatCommaInitializer_<_Tp> operator << (const Mat_<_Tp>& m, T2 val)
{
MatCommaInitializer_<_Tp> commaInitializer((Mat_<_Tp>*)&m);
return (commaInitializer, val);
}
///////////////////////// Matrix Expressions ////////////////////////
inline
@@ -103,45 +103,6 @@ struct Type< Matx<_Tp, m, n> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, n
} // namespace
//! @brief Comma-separated Matrix Initializer
template<typename _Tp, int m, int n> class MatxCommaInitializer
{
public:
MatxCommaInitializer(Matx<_Tp, m, n>* _mtx);
template<typename T2> MatxCommaInitializer<_Tp, m, n>& operator , (T2 val);
Matx<_Tp, m, n> operator *() const;
Matx<_Tp, m, n>* dst;
int idx;
};
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> commaInitializer((Matx<_Tp, m, n>*)&mtx);
return (commaInitializer, val);
}
template<typename _Tp, int m, int n> inline
MatxCommaInitializer<_Tp, m, n>::MatxCommaInitializer(Matx<_Tp, m, n>* _mtx)
: dst(_mtx), idx(0)
{}
template<typename _Tp, int m, int n> template<typename _T2> inline
MatxCommaInitializer<_Tp, m, n>& MatxCommaInitializer<_Tp, m, n>::operator , (_T2 value)
{
CV_DbgAssert( idx < m*n );
dst->val[idx++] = saturate_cast<_Tp>(value);
return *this;
}
template<typename _Tp, int m, int n> inline
Matx<_Tp, m, n> MatxCommaInitializer<_Tp, m, n>::operator *() const
{
CV_DbgAssert( idx == n*m );
return *dst;
}
////////////////////////////////// Matx Implementation ///////////////////////////////////
template<typename _Tp, int m, int n> inline
@@ -728,44 +689,6 @@ template<typename _Tp, int cn>
struct Type< Vec<_Tp, cn> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, cn) }; };
} // namespace
/** @brief Comma-separated Vec Initializer
*/
template<typename _Tp, int m> class VecCommaInitializer : public MatxCommaInitializer<_Tp, m, 1>
{
public:
VecCommaInitializer(Vec<_Tp, m>* _vec);
template<typename T2> VecCommaInitializer<_Tp, m>& operator , (T2 val);
Vec<_Tp, m> operator *() const;
};
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> commaInitializer((Vec<_Tp, cn>*)&vec);
return (commaInitializer, val);
}
template<typename _Tp, int cn> inline
VecCommaInitializer<_Tp, cn>::VecCommaInitializer(Vec<_Tp, cn>* _vec)
: MatxCommaInitializer<_Tp, cn, 1>(_vec)
{}
template<typename _Tp, int cn> template<typename _T2> inline
VecCommaInitializer<_Tp, cn>& VecCommaInitializer<_Tp, cn>::operator , (_T2 value)
{
CV_DbgAssert( this->idx < cn );
this->dst->val[this->idx++] = saturate_cast<_Tp>(value);
return *this;
}
template<typename _Tp, int cn> inline
Vec<_Tp, cn> VecCommaInitializer<_Tp, cn>::operator *() const
{
CV_DbgAssert( this->idx == cn );
return *this->dst;
}
template<typename _Tp, int cn> inline
Vec<_Tp, cn>::Vec() {}
@@ -92,8 +92,8 @@ Here is an example:
fs << "frameCount" << 5;
time_t rawtime; time(&rawtime);
fs << "calibrationDate" << asctime(localtime(&rawtime));
Mat cameraMatrix = (Mat_<double>(3,3) << 1000, 0, 320, 0, 1000, 240, 0, 0, 1);
Mat distCoeffs = (Mat_<double>(5,1) << 0.1, 0.01, -0.001, 0, 0);
Mat cameraMatrix = Mat_<double>({3,3},{1000, 0, 320, 0, 1000, 240, 0, 0, 1});
Mat distCoeffs = Mat_<double>({5,1},{0.1, 0.01, -0.001, 0, 0});
fs << "cameraMatrix" << cameraMatrix << "distCoeffs" << distCoeffs;
fs << "features" << "[";
for( int i = 0; i < 3; i++ )
@@ -944,7 +944,7 @@ public:
* Quatd q_unit = Quatd::createFromAngleAxis(angle, axis); //quaternion could also be get by interpolation by two or more quaternions.
*
* //assume there is two points (1,0,0) and (1,0,1) to be rotated
* Mat pointsA = (Mat_<double>(2, 3) << 1,0,0,1,0,1);
* Mat pointsA = Mat_<double>({2, 3}, {1,0,0,1,0,1});
* //change the shape
* pointsA = pointsA.t();
* // rotate 180 degrees around the z axis
+2 -2
View File
@@ -117,8 +117,8 @@ return x[0] * x[0] + x[1] * x[1];
}
};
Mat P = (Mat_<double>(1, 2) << 1.0, 1.0);
Mat step = (Mat_<double>(2, 1) << -0.5, 0.5);
Mat P = Mat_<double>({1, 2}, {1.0, 1.0});
Mat step = Mat_<double>({2, 1}, {-0.5, 0.5});
Ptr<optim::MinProblemSolver::Function> ptr_F(new DistanceToLines());
Ptr<optim::DownhillSolver> MinProblemSolver = optim::createDownhillSolver();
+7 -7
View File
@@ -2059,10 +2059,10 @@ TEST(Multiply, FloatingPointRounding)
TEST(Core_Add, AddToColumnWhen3Rows)
{
cv::Mat m1 = (cv::Mat_<double>(3, 2) << 1, 2, 3, 4, 5, 6);
cv::Mat m1 = cv::Mat_<double>({3, 2}, {1, 2, 3, 4, 5, 6});
m1.col(1) += 10;
cv::Mat m2 = (cv::Mat_<double>(3, 2) << 1, 12, 3, 14, 5, 16);
cv::Mat m2 = cv::Mat_<double>({3, 2}, {1, 12, 3, 14, 5, 16});
cv::MatExpr diff = m1 - m2;
int nz = countNonZero(diff);
@@ -2071,10 +2071,10 @@ TEST(Core_Add, AddToColumnWhen3Rows)
TEST(Core_Add, AddToColumnWhen4Rows)
{
cv::Mat m1 = (cv::Mat_<double>(4, 2) << 1, 2, 3, 4, 5, 6, 7, 8);
cv::Mat m1 = cv::Mat_<double>({4, 2}, {1, 2, 3, 4, 5, 6, 7, 8});
m1.col(1) += 10;
cv::Mat m2 = (cv::Mat_<double>(4, 2) << 1, 12, 3, 14, 5, 16, 7, 18);
cv::Mat m2 = cv::Mat_<double>({4, 2}, {1, 12, 3, 14, 5, 16, 7, 18});
ASSERT_EQ(0, countNonZero(m1 - m2));
}
@@ -2516,11 +2516,11 @@ TEST(Compare, regression_8999)
{
// Issue #8999 predates broadcasting element-wise ops: comparing a 4x1 array against a 1x1 operand
// used to throw (both look like a Scalar). It now broadcasts the 1x1 operand across the 4x1 array.
Mat_<double> A(4,1); A << 1, 3, 2, 4;
Mat_<double> B(1,1); B << 2;
Mat_<double> A({4,1}, {1, 3, 2, 4});
Mat_<double> B({1,1}, {2});
Mat C;
cv::compare(A, B, C, CMP_LT);
Mat expected = (Mat_<uchar>(4,1) << 255, 0, 0, 0); // A < 2
Mat expected = Mat_<uchar>({4,1}, {255, 0, 0, 0}); // A < 2
EXPECT_EQ(0, cvtest::norm(C, expected, NORM_INF));
}
+2 -2
View File
@@ -354,8 +354,8 @@ TEST(Core_TExpr, atan2)
std::atan2(y64.at<double>(r, c), x64.at<double>(r, c)));
// axis cases: atan2(0, 1) = 0, atan2(1, 0) = pi/2, atan2(0, -1) = pi, atan2(-1, 0) = -pi/2
Mat ya = (Mat_<float>(1, 4) << 0.f, 1.f, 0.f, -1.f);
Mat xa = (Mat_<float>(1, 4) << 1.f, 0.f, -1.f, 0.f);
Mat ya = Mat_<float>({1, 4}, {0.f, 1.f, 0.f, -1.f});
Mat xa = Mat_<float>({1, 4}, {1.f, 0.f, -1.f, 0.f});
Mat ga = expr1("atan2({0}, {1})", { ya, xa });
const float expctd[] = { 0.f, (float)(CV_PI/2), (float)CV_PI, (float)(-CV_PI/2) };
for (int i = 0; i < 4; i++)
@@ -88,8 +88,8 @@ TEST(Core_ConjGradSolver, regression_basic){
#if 1
{
cv::Ptr<cv::MinProblemSolver::Function> ptr_F(new SphereF_CG());
cv::Mat x=(cv::Mat_<double>(4,1)<<50.0,10.0,1.0,-10.0),
etalon_x=(cv::Mat_<double>(1,4)<<0.0,0.0,0.0,0.0);
cv::Mat x=cv::Mat_<double>({4,1},{50.0,10.0,1.0,-10.0}),
etalon_x=cv::Mat_<double>({1,4},{0.0,0.0,0.0,0.0});
double etalon_res=0.0;
mytest(solver,ptr_F,x,etalon_x,etalon_res);
}
@@ -97,8 +97,8 @@ TEST(Core_ConjGradSolver, regression_basic){
#if 1
{
cv::Ptr<cv::MinProblemSolver::Function> ptr_F(new RosenbrockF_CG());
cv::Mat x=(cv::Mat_<double>(2,1)<<0.0,0.0),
etalon_x=(cv::Mat_<double>(2,1)<<1.0,1.0);
cv::Mat x=cv::Mat_<double>({2,1},{0.0,0.0}),
etalon_x=cv::Mat_<double>({2,1},{1.0,1.0});
double etalon_res=0.0;
mytest(solver,ptr_F,x,etalon_x,etalon_res);
}
+6 -6
View File
@@ -84,9 +84,9 @@ TEST(Core_DownhillSolver, regression_basic){
#if 1
{
cv::Ptr<cv::MinProblemSolver::Function> ptr_F = cv::makePtr<SphereF>();
cv::Mat x=(cv::Mat_<double>(1,2)<<1.0,1.0),
step=(cv::Mat_<double>(2,1)<<-0.5,-0.5),
etalon_x=(cv::Mat_<double>(1,2)<<-0.0,0.0);
cv::Mat x=cv::Mat_<double>({1,2},{1.0,1.0}),
step=cv::Mat_<double>({2,1},{-0.5,-0.5}),
etalon_x=cv::Mat_<double>({1,2},{-0.0,0.0});
double etalon_res=0.0;
mytest(solver,ptr_F,x,step,etalon_x,etalon_res);
}
@@ -94,9 +94,9 @@ TEST(Core_DownhillSolver, regression_basic){
#if 1
{
cv::Ptr<cv::MinProblemSolver::Function> ptr_F = cv::makePtr<RosenbrockF>();
cv::Mat x=(cv::Mat_<double>(2,1)<<0.0,0.0),
step=(cv::Mat_<double>(2,1)<<0.5,+0.5),
etalon_x=(cv::Mat_<double>(2,1)<<1.0,1.0);
cv::Mat x=cv::Mat_<double>({2,1},{0.0,0.0}),
step=cv::Mat_<double>({2,1},{0.5,+0.5}),
etalon_x=cv::Mat_<double>({2,1},{1.0,1.0});
double etalon_res=0.0;
mytest(solver,ptr_F,x,step,etalon_x,etalon_res);
}
+1 -1
View File
@@ -119,7 +119,7 @@ TEST(Core_FP8, cross_fp8_conversion)
TEST(Core_FP8, convert_scale)
{
Mat f = (Mat_<float>(1, 4) << 1.f, 2.f, 3.f, 4.f);
Mat f = Mat_<float>({1, 4}, {1.f, 2.f, 3.f, 4.f});
Mat q, back;
f.convertTo(q, CV_8F_E4M3FN, 2.0, 1.0); // 2x+1 -> {3,5,7,9}
q.convertTo(back, CV_32F);
+27 -25
View File
@@ -47,34 +47,34 @@ TEST(Core_LPSolver, regression_basic){
#if 1
//cormen's example #1
A=(cv::Mat_<double>(3,1)<<3,1,2);
B=(cv::Mat_<double>(3,4)<<1,1,3,30,2,2,5,24,4,1,2,36);
A=cv::Mat_<double>({3, 1}, {3,1,2});
B=cv::Mat_<double>({3, 4}, {1,1,3,30,2,2,5,24,4,1,2,36});
std::cout<<"here A goes\n"<<A<<"\n";
cv::solveLP(A,B,z);
std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(3,1)<<8,4,0);
etalon_z=cv::Mat_<double>({3, 1}, {8,4,0});
ASSERT_LT(cvtest::norm(z, etalon_z, cv::NORM_L1), 1e-12);
#endif
#if 1
//cormen's example #2
A=(cv::Mat_<double>(1,2)<<18,12.5);
B=(cv::Mat_<double>(3,3)<<1,1,20,1,0,20,0,1,16);
A=cv::Mat_<double>({1, 2}, {18,12.5});
B=cv::Mat_<double>({3, 3}, {1,1,20,1,0,20,0,1,16});
std::cout<<"here A goes\n"<<A<<"\n";
cv::solveLP(A,B,z);
std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(2,1)<<20,0);
etalon_z=cv::Mat_<double>({2, 1}, {20,0});
ASSERT_LT(cvtest::norm(z, etalon_z, cv::NORM_L1), 1e-12);
#endif
#if 1
//cormen's example #3
A=(cv::Mat_<double>(1,2)<<5,-3);
B=(cv::Mat_<double>(2,3)<<1,-1,1,2,1,2);
A=cv::Mat_<double>({1,2},{5,-3});
B=cv::Mat_<double>({2,3},{1,-1,1,2,1,2});
std::cout<<"here A goes\n"<<A<<"\n";
cv::solveLP(A,B,z);
std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(2,1)<<1,0);
etalon_z=cv::Mat_<double>({2, 1}, {1,0});
ASSERT_LT(cvtest::norm(z, etalon_z, cv::NORM_L1), 1e-12);
#endif
}
@@ -84,12 +84,12 @@ TEST(Core_LPSolver, regression_init_unfeasible){
#if 1
//cormen's example #4 - unfeasible
A=(cv::Mat_<double>(1,3)<<-1,-1,-1);
B=(cv::Mat_<double>(2,4)<<-2,-7.5,-3,-10000,-20,-5,-10,-30000);
A=cv::Mat_<double>({1,3},{-1,-1,-1});
B=cv::Mat_<double>({2,4},{-2,-7.5,-3,-10000,-20,-5,-10,-30000});
std::cout<<"here A goes\n"<<A<<"\n";
cv::solveLP(A,B,z);
std::cout<<"here z goes\n"<<z<<"\n";
etalon_z=(cv::Mat_<double>(3,1)<<1250,1000,0);
etalon_z=cv::Mat_<double>({3, 1}, {1250,1000,0});
ASSERT_LT(cvtest::norm(z, etalon_z, cv::NORM_L1), 1e-12);
#endif
}
@@ -99,8 +99,8 @@ TEST(DISABLED_Core_LPSolver, regression_absolutely_unfeasible){
#if 1
//trivial absolutely unfeasible example
A=(cv::Mat_<double>(1,1)<<1);
B=(cv::Mat_<double>(2,2)<<1,-1);
A=cv::Mat_<double>({1,1},{1});
B=cv::Mat_<double>({2,2},{1,-1});
std::cout<<"here A goes\n"<<A<<"\n";
int res=cv::solveLP(A,B,z);
ASSERT_EQ(res,-1);
@@ -112,8 +112,8 @@ TEST(Core_LPSolver, regression_multiple_solutions){
#if 1
//trivial example with multiple solutions
A=(cv::Mat_<double>(2,1)<<1,1);
B=(cv::Mat_<double>(1,3)<<1,1,1);
A=cv::Mat_<double>({2,1},{1,1});
B=cv::Mat_<double>({1,3},{1,1,1});
std::cout<<"here A goes\n"<<A<<"\n";
int res=cv::solveLP(A,B,z);
printf("res=%d\n",res);
@@ -129,8 +129,8 @@ TEST(Core_LPSolver, regression_cycling){
#if 1
//example with cycling from http://people.orie.cornell.edu/miketodd/or630/SimplexCyclingExample.pdf
A=(cv::Mat_<double>(4,1)<<10,-57,-9,-24);
B=(cv::Mat_<double>(3,5)<<0.5,-5.5,-2.5,9,0,0.5,-1.5,-0.5,1,0,1,0,0,0,1);
A=cv::Mat_<double>({4,1},{10,-57,-9,-24});
B=cv::Mat_<double>({3,5},{0.5,-5.5,-2.5,9,0,0.5,-1.5,-0.5,1,0,1,0,0,0,1});
std::cout<<"here A goes\n"<<A<<"\n";
int res=cv::solveLP(A,B,z);
printf("res=%d\n",res);
@@ -143,8 +143,8 @@ TEST(Core_LPSolver, regression_cycling){
TEST(Core_LPSolver, issue_12337)
{
Mat A=(cv::Mat_<double>(3,1)<<3,1,2);
Mat B=(cv::Mat_<double>(3,4)<<1,1,3,30,2,2,5,24,4,1,2,36);
Mat A=cv::Mat_<double>({3,1},{3,1,2});
Mat B=cv::Mat_<double>({3,4},{1,1,3,30,2,2,5,24,4,1,2,36});
Mat1f z_float; cv::solveLP(A, B, z_float);
Mat1d z_double; cv::solveLP(A, B, z_double);
Mat1i z_int; cv::solveLP(A, B, z_int);
@@ -155,11 +155,13 @@ TEST(Core_LPSolver, issue_12337)
// The test behaviour may change after algorithm tuning and may removed.
TEST(Core_LPSolver, issue_12343)
{
Mat A = (cv::Mat_<double>(4, 1) << 3., 3., 3., 4.);
Mat B = (cv::Mat_<double>(4, 5) << 0., 1., 4., 4., 3.,
3., 1., 2., 2., 3.,
4., 4., 0., 1., 4.,
4., 0., 4., 1., 4.);
Mat A = cv::Mat_<double>({4, 1}, {3., 3., 3., 4.});
Mat B = cv::Mat_<double>({4, 5}, {
0., 1., 4., 4., 3.,
3., 1., 2., 2., 3.,
4., 4., 0., 1., 4.,
4., 0., 4., 1., 4.
});
Mat z;
int result = cv::solveLP(A, B, z);
EXPECT_EQ(SOLVELP_LOST, result);
+25 -40
View File
@@ -1132,7 +1132,7 @@ TEST(Core_Mat, issue4457_pass_null_ptr)
TEST(Core_Mat, reshape_1942)
{
cv::Mat A = (cv::Mat_<float>(2,3) << 3.4884074, 1.4159607, 0.78737736, 2.3456569, -0.88010466, 0.3009364);
cv::Mat A = cv::Mat_<float>({2, 3}, {3.4884074, 1.4159607, 0.78737736, 2.3456569, -0.88010466, 0.3009364});
int cn = 0;
ASSERT_NO_THROW(
cv::Mat_<float> M = A.reshape(3);
@@ -1246,8 +1246,8 @@ TEST(Core_Mat, reinterpret_OutputArray_8UC4_32FC1) {
TEST(Core_Mat, push_back)
{
Mat a = (Mat_<float>(1,2) << 3.4884074f, 1.4159607f);
Mat b = (Mat_<float>(1,2) << 0.78737736f, 2.3456569f);
Mat a = Mat_<float>({1, 2}, {3.4884074f, 1.4159607f});
Mat b = Mat_<float>({1, 2}, {0.78737736f, 2.3456569f});
a.push_back(b);
@@ -1259,7 +1259,7 @@ TEST(Core_Mat, push_back)
ASSERT_FLOAT_EQ(0.78737736f, a.at<float>(1, 0));
ASSERT_FLOAT_EQ(2.3456569f, a.at<float>(1, 1));
Mat c = (Mat_<float>(2,2) << -0.88010466f, 0.3009364f, 2.22399974f, -5.45933905f);
Mat c = Mat_<float>({2, 2}, {-0.88010466f, 0.3009364f, 2.22399974f, -5.45933905f});
ASSERT_EQ(c.rows, a.cols);
@@ -1320,14 +1320,12 @@ INSTANTIATE_TYPED_TEST_CASE_P(CopyToTest, Core_Mat_copyTo, AllMatDepths);
TEST(Core_Mat, copyNx1ToVector)
{
cv::Mat_<uchar> src(5, 1);
cv::Mat_<uchar> src({5, 1}, {1, 2, 3, 4, 5});
cv::Mat_<uchar> ref_dst8;
cv::Mat_<ushort> ref_dst16;
std::vector<uchar> dst8;
std::vector<ushort> dst16;
src << 1, 2, 3, 4, 5;
src.copyTo(ref_dst8);
src.copyTo(dst8);
@@ -1360,14 +1358,14 @@ TEST(Core_Mat, zeros)
TEST(Core_Matx, fromMat_)
{
Mat_<double> a = (Mat_<double>(2,2) << 10, 11, 12, 13);
Mat_<double> a = Mat_<double>({2, 2}, {10, 11, 12, 13});
Matx22d b(a);
ASSERT_EQ( cvtest::norm(a, b, NORM_INF), 0.);
}
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};
ASSERT_EQ( cvtest::norm(a, b, NORM_INF), 0.);
Mat_<double> c({2, 2}, {10, 11, 12, 13});
@@ -1479,11 +1477,9 @@ TEST(Core_SparseMat, footprint)
// Can't fix without dirty hacks or broken user code (PR #4159)
TEST(Core_Mat_vector, DISABLED_OutputArray_create_getMat)
{
cv::Mat_<uchar> src_base(5, 1);
cv::Mat_<uchar> src_base({5, 1}, {1, 2, 3, 4, 5});
std::vector<uchar> dst8;
src_base << 1, 2, 3, 4, 5;
Mat src(src_base);
OutputArray _dst(dst8);
{
@@ -1497,11 +1493,9 @@ TEST(Core_Mat_vector, DISABLED_OutputArray_create_getMat)
TEST(Core_Mat_vector, copyTo_roi_column)
{
cv::Mat_<uchar> src_base(5, 2);
cv::Mat_<uchar> src_base({5, 2}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
std::vector<uchar> dst1;
src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
Mat src_full(src_base);
Mat src(src_full.col(0));
#if 0 // Can't fix without dirty hacks or broken user code (PR #4159)
@@ -1529,11 +1523,9 @@ TEST(Core_Mat_vector, copyTo_roi_column)
TEST(Core_Mat_vector, copyTo_roi_row)
{
cv::Mat_<uchar> src_base(2, 5);
cv::Mat_<uchar> src_base({2, 5}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
std::vector<uchar> dst1;
src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
Mat src_full(src_base);
Mat src(src_full.row(0));
OutputArray _dst(dst1);
@@ -1699,11 +1691,9 @@ TEST(Mat, regression_10507_mat_setTo)
TEST(Core_Mat_array, outputArray_create_getMat)
{
cv::Mat_<uchar> src_base(5, 1);
cv::Mat_<uchar> src_base({5, 1}, {1, 2, 3, 4, 5});
std::array<uchar, 5> dst8;
src_base << 1, 2, 3, 4, 5;
Mat src(src_base);
OutputArray _dst(dst8);
@@ -1718,9 +1708,7 @@ TEST(Core_Mat_array, outputArray_create_getMat)
TEST(Core_Mat_array, copyTo_roi_column)
{
cv::Mat_<uchar> src_base(5, 2);
src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
cv::Mat_<uchar> src_base({5, 2}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
Mat src_full(src_base);
Mat src(src_full.col(0));
@@ -1739,11 +1727,9 @@ TEST(Core_Mat_array, copyTo_roi_column)
TEST(Core_Mat_array, copyTo_roi_row)
{
cv::Mat_<uchar> src_base(2, 5);
cv::Mat_<uchar> src_base({2, 5}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10});
std::array<uchar, 5> dst1;
src_base << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10;
Mat src_full(src_base);
Mat src(src_full.row(0));
OutputArray _dst(dst1);
@@ -1826,8 +1812,7 @@ TEST(Mat_, range_based_for)
TEST(Mat, from_initializer_list)
{
Mat A({1.f, 2.f, 3.f});
int n = 3;
Mat_<float> B(1, &n); B << 1, 2, 3;
Mat_<float> B({3}, {1, 2, 3});
Mat_<float> C({3}, {1,2,3});
ASSERT_EQ(A.type(), CV_32F);
@@ -1848,8 +1833,7 @@ TEST(Mat, from_initializer_list)
TEST(Mat_, from_initializer_list)
{
Mat_<float> A = {1, 2, 3};
int n = 3;
Mat_<float> B(1, &n); B << 1, 2, 3;
Mat_<float> B({3}, {1, 2, 3});
Mat_<float> C({3}, {1,2,3});
ASSERT_DOUBLE_EQ(cvtest::norm(A, B, NORM_INF), 0.);
@@ -1865,7 +1849,7 @@ TEST(Mat_, from_initializer_list)
TEST(Mat, template_based_ptr)
{
Mat mat = (Mat_<float>(2, 2) << 11.0f, 22.0f, 33.0f, 44.0f);
Mat mat = Mat_<float>({2, 2}, {11.0f, 22.0f, 33.0f, 44.0f});
int idx[2] = {1, 0};
ASSERT_FLOAT_EQ(33.0f, *(mat.ptr<float>(idx)));
idx[0] = 1;
@@ -1875,9 +1859,8 @@ TEST(Mat, template_based_ptr)
TEST(Mat_, template_based_ptr)
{
int dim[4] = {2, 2, 1, 2};
Mat_<float> mat = (Mat_<float>(4, dim) << 11.0f, 22.0f, 33.0f, 44.0f,
55.0f, 66.0f, 77.0f, 88.0f);
Mat_<float> mat({2, 2, 1, 2}, {11.0f, 22.0f, 33.0f, 44.0f,
55.0f, 66.0f, 77.0f, 88.0f});
int idx[4] = {1, 0, 0, 1};
ASSERT_FLOAT_EQ(66.0f, *(mat.ptr<float>(idx)));
}
@@ -2238,10 +2221,12 @@ TEST(Core_Vectors, issue_13078_workaround)
TEST(Core_MatExpr, issue_13926)
{
Mat M1 = (Mat_<double>(4,4,CV_64FC1) << 1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16);
Mat M1 = Mat_<double>({4, 4}, {
1, 2, 3, 4,
5, 6, 7, 8,
9, 10, 11, 12,
13, 14, 15, 16
});
Matx44d M2(1, 2, 3, 4,
5, 6, 7, 8,
@@ -2546,7 +2531,7 @@ TEST(Mat1D, basic)
TEST(Mat, ptrVecni_20044)
{
Mat_<int> m(3,4); m << 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12;
Mat_<int> m({3, 4}, {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12});
Vec2i idx(1,1);
uchar *u = m.ptr(idx);
+5 -5
View File
@@ -1926,7 +1926,7 @@ TEST(Core_SolveCubic, regression_27748)
double c = -96.795;
double d = 13.6826;
Mat coeffs = (Mat_<double>(1, 4) << a, b, c, d);
Mat coeffs = Mat_<double>({1, 4}, {a, b, c, d});
Mat roots;
int n = solveCubic(coeffs, roots);
@@ -1947,7 +1947,7 @@ TEST(Core_SolveCubic, regression_27748)
TEST(Core_SolvePoly, regression_5599)
{
// x^4 - x^2 = 0, roots: 1, -1, 0, 0
cv::Mat coefs = (cv::Mat_<float>(1,5) << 0, 0, -1, 0, 1 );
cv::Mat coefs = cv::Mat_<float>({1, 5}, {0, 0, -1, 0, 1});
{
cv::Mat r;
double prec;
@@ -1963,7 +1963,7 @@ TEST(Core_SolvePoly, regression_5599)
checkRoot<float>(r, 0, 0);
}
// x^2 - 2x + 1 = 0, roots: 1, 1
coefs = (cv::Mat_<float>(1,3) << 1, -2, 1 );
coefs = cv::Mat_<float>({1, 3}, {1, -2, 1});
{
cv::Mat r;
double prec;
@@ -1981,7 +1981,7 @@ TEST(Core_SolvePoly, regression_5599)
TEST(Core_SolvePoly, regression_23644)
{
// x^2 - 2x - 3 = 0, roots: 3, -1
cv::Mat coefs = (cv::Mat_<float>(1,3) << -3, -2, 1 );
cv::Mat coefs = cv::Mat_<float>({1, 3}, {-3, -2, 1});
cv::Mat r;
double prec;
prec = cv::solvePoly(coefs, r);
@@ -2322,7 +2322,7 @@ INSTANTIATE_TYPED_TEST_CASE_P(Negative_Test, Core_CheckRange, mat_data_types);
TEST(Core_Invert, small)
{
cv::Mat a = (cv::Mat_<float>(3,3) << 2.42104644730331, 1.81444796521479, -3.98072565304758, 0, 7.08389214348967e-3, 5.55326770986007e-3, 0,0, 7.44556154284261e-3);
cv::Mat a = cv::Mat_<float>({3, 3}, {2.42104644730331, 1.81444796521479, -3.98072565304758, 0, 7.08389214348967e-3, 5.55326770986007e-3, 0,0, 7.44556154284261e-3});
//cv::randu(a, -1, 1);
cv::Mat b = a.t()*a;
+7 -7
View File
@@ -50,7 +50,7 @@ static double maxAbsDiff(const T &t, const U &u)
TEST(Core_OutputArrayAssign, _Matxd_Matd)
{
Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<double>({2, 3}, {1, 2, 3, .1, .2, .3});
Matx23d actualx;
{
@@ -65,7 +65,7 @@ TEST(Core_OutputArrayAssign, _Matxd_Matd)
TEST(Core_OutputArrayAssign, _Matxd_Matf)
{
Mat expected = (Mat_<float>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<float>({2, 3}, {1.f, 2.f, 3.f, .1f, .2f, .3f});
Matx23d actualx;
{
@@ -80,7 +80,7 @@ TEST(Core_OutputArrayAssign, _Matxd_Matf)
TEST(Core_OutputArrayAssign, _Matxf_Matd)
{
Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<double>({2, 3}, {1, 2, 3, .1, .2, .3});
Matx23f actualx;
{
@@ -95,7 +95,7 @@ TEST(Core_OutputArrayAssign, _Matxf_Matd)
TEST(Core_OutputArrayAssign, _Matxd_UMatd)
{
Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<double>({2, 3}, {1, 2, 3, .1, .2, .3});
UMat uexpected = expected.getUMat(ACCESS_READ);
Matx23d actualx;
@@ -111,7 +111,7 @@ TEST(Core_OutputArrayAssign, _Matxd_UMatd)
TEST(Core_OutputArrayAssign, _Matxd_UMatf)
{
Mat expected = (Mat_<float>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<float>({2, 3}, {1.f, 2.f, 3.f, .1f, .2f, .3f});
UMat uexpected = expected.getUMat(ACCESS_READ);
Matx23d actualx;
@@ -127,7 +127,7 @@ TEST(Core_OutputArrayAssign, _Matxd_UMatf)
TEST(Core_OutputArrayAssign, _Matxf_UMatd)
{
Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
Mat expected = Mat_<double>({2, 3}, {1, 2, 3, .1, .2, .3});
UMat uexpected = expected.getUMat(ACCESS_READ);
Matx23f actualx;
@@ -212,7 +212,7 @@ TEST(Core_String, end_method_regression)
TEST(Core_Copy, repeat_regression_8972)
{
Mat src = (Mat_<int>(1, 4) << 1, 2, 3, 4);
Mat src = Mat_<int>({1, 4}, {1, 2, 3, 4});
ASSERT_ANY_THROW({
repeat(src, 5, 1, src);
+13 -13
View File
@@ -894,8 +894,8 @@ bool CV_OperationsTest::TestMatMatxCastSum()
{
try
{
Mat ref1 = (Mat_<double>(3, 1) << 1, 2, 3);
Mat ref2 = (Mat_<double>(3, 1) << 3, 4, 5);
Mat ref1 = Mat_<double>({3, 1}, {1, 2, 3});
Mat ref2 = Mat_<double>({3, 1}, {3, 4, 5});
Mat ref3 = Mat::ones(3, 1, CV_64FC1);
Mat mat = Mat::zeros(3, 1, CV_64FC1);
@@ -1179,7 +1179,7 @@ bool CV_OperationsTest::TestSVD()
{
try
{
Mat A = (Mat_<double>(3,4) << 1, 2, -1, 4, 2, 4, 3, 5, -1, -2, 6, 7);
Mat A = Mat_<double>({3, 4}, {1, 2, -1, 4, 2, 4, 3, 5, -1, -2, 6, 7});
Mat x;
SVD::solveZ(A,x);
if( cvtest::norm(A*x, NORM_INF) > FLT_EPSILON )
@@ -1506,16 +1506,16 @@ INSTANTIATE_TEST_CASE_P(Core, sortIdx, Combine(
TEST(Core_sortIdx, regression_8941)
{
cv::Mat src = (cv::Mat_<int>(3, 3) <<
1, 2, 3,
0, 9, 5,
8, 1, 6
);
cv::Mat expected = (cv::Mat_<int>(3, 1) <<
1,
0,
2
);
cv::Mat src = cv::Mat_<int>({3, 3}, {
1, 2, 3,
0, 9, 5,
8, 1, 6
});
cv::Mat expected = cv::Mat_<int>({3, 1}, {
1,
0,
2
});
cv::Mat result;
cv::sortIdx(src.col(0), result, cv::SORT_EVERY_COLUMN | cv::SORT_ASCENDING);
+4 -4
View File
@@ -108,10 +108,10 @@ TEST_F(QuatTest, basicfuns)
EXPECT_MAT_NEAR(q1RotMat, R, 1e-6);
Vec3d z_axis{0,0,1};
Quatd q_unit1 = Quatd::createFromAngleAxis(angle, z_axis);
Mat pointsA = (Mat_<double>(2, 3) << 1,0,0,1,0,1);
Mat pointsA = Mat_<double>({2, 3}, {1,0,0,1,0,1});
pointsA = pointsA.t();
Mat new_point = q_unit1.toRotMat3x3() * pointsA;
Mat afterRo = (Mat_<double>(3, 2) << -1,-1,0,0,0,1);
Mat afterRo = Mat_<double>({3, 2}, {-1,-1,0,0,0,1});
EXPECT_MAT_NEAR(afterRo, new_point, 1e-6);
EXPECT_ANY_THROW(qNull.toRotVec());
Vec3d rodVec{CV_PI/sqrt(3), CV_PI/sqrt(3), CV_PI/sqrt(3)};
@@ -451,9 +451,9 @@ TEST_F(DualQuatTest, basic_ops)
EXPECT_EQ(dqTrans.log().exp(), dqTrans);
EXPECT_MAT_NEAR(q1norm.toMat(QUAT_ASSUME_UNIT), dq1.toMat(), 1e-6);
Matx44d R1 = dq2.toMat();
Mat point = (Mat_<double>(4, 1) << 3, 0, 0, 1);
Mat point = Mat_<double>({4, 1}, {3, 0, 0, 1});
Mat new_point = R1 * point;
Mat after = (Mat_<double>(4, 1) << 0, 3, 5 ,1);
Mat after = Mat_<double>({4, 1}, {0, 3, 5 ,1});
EXPECT_MAT_NEAR(new_point, after, 1e-6);
Vec<double, 8> vec = dq1.toVec();
EXPECT_EQ(DualQuatd(vec), dq1);
+1 -1
View File
@@ -978,7 +978,7 @@ TEST(UMat, setOpenCL)
// save the current state
bool useOCL = cv::ocl::useOpenCL();
Mat m = (Mat_<uchar>(3,3)<<0,1,2,3,4,5,6,7,8);
Mat m = Mat_<uchar>({3, 3}, {0,1,2,3,4,5,6,7,8});
cv::ocl::setUseOpenCL(true);
UMat um1;
+8 -6
View File
@@ -614,8 +614,8 @@ TEST_P(Test_Caffe_layers, Average_pooling_kernel_area)
// 4 5 | 6
// ----+--
// 7 8 | 9
Mat inp = (Mat_<float>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9);
Mat ref = (Mat_<float>(2, 2) << (1 + 2 + 4 + 5) / 4.f, (3 + 6) / 2.f, (7 + 8) / 2.f, 9);
Mat inp = Mat_<float>({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9});
Mat ref = Mat_<float>({2, 2}, {(1 + 2 + 4 + 5) / 4.f, (3 + 6) / 2.f, (7 + 8) / 2.f, 9});
Mat tmp = blobFromImage(inp);
net.setInput(blobFromImage(inp));
net.setPreferableBackend(backend);
@@ -652,10 +652,12 @@ TEST_P(Test_Caffe_layers, PriorBox_squares)
net.setPreferableTarget(target);
Mat out = net.forward();
Mat ref = (Mat_<float>(4, 4) << 0.0, 0.0, 0.75, 1.0,
0.25, 0.0, 1.0, 1.0,
0.1f, 0.1f, 0.2f, 0.2f,
0.1f, 0.1f, 0.2f, 0.2f);
Mat ref = Mat_<float>({4, 4}, {
0.0, 0.0, 0.75, 1.0,
0.25, 0.0, 1.0, 1.0,
0.1f, 0.1f, 0.2f, 0.2f,
0.1f, 0.1f, 0.2f, 0.2f
});
double l1 = 1e-5;
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CUDA_FP16)
l1 = 2e-5;
+1 -1
View File
@@ -574,7 +574,7 @@ TEST(Net, forwardAndRetrieve)
lpSlice.name = "testLayer";
lpSlice.type = "Slice";
lpSlice.set("axis", 0);
Mat slicePoint = (Mat_<int>(1, 1) << 2);
Mat slicePoint = Mat_<int>({1, 1}, {2});
lpSlice.set("slice_point", DictValue::arrayInt<int*>((int*)slicePoint.data, 1));
Net net;
+20 -14
View File
@@ -953,11 +953,13 @@ TEST_P(Test_TensorFlow_nets, Inception_v2_SSD)
// Output has shape 1x1xNx7 where N - number of detections.
// An every detection is a vector of values [id, classId, confidence, left, top, right, bottom]
Mat out = net.forward();
Mat ref = (Mat_<float>(5, 7) << 0, 1, 0.90176028, 0.19872092, 0.36311883, 0.26461923, 0.63498729,
0, 3, 0.93569964, 0.64865261, 0.45906419, 0.80675775, 0.65708131,
0, 3, 0.75838411, 0.44668293, 0.45907149, 0.49459291, 0.52197015,
0, 10, 0.95932811, 0.38349164, 0.32528657, 0.40387636, 0.39165527,
0, 10, 0.93973452, 0.66561931, 0.37841269, 0.68074018, 0.42907384);
Mat ref = Mat_<float>({5, 7}, {
0, 1, 0.90176028, 0.19872092, 0.36311883, 0.26461923, 0.63498729,
0, 3, 0.93569964, 0.64865261, 0.45906419, 0.80675775, 0.65708131,
0, 3, 0.75838411, 0.44668293, 0.45907149, 0.49459291, 0.52197015,
0, 10, 0.95932811, 0.38349164, 0.32528657, 0.40387636, 0.39165527,
0, 10, 0.93973452, 0.66561931, 0.37841269, 0.68074018, 0.42907384
});
double scoreDiff = default_l1, iouDiff = default_lInf;
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
@@ -1220,12 +1222,14 @@ TEST_P(Test_TensorFlow_nets, opencv_face_detector_uint8)
Mat out = net.forward();
// References are from test for Caffe model.
Mat ref = (Mat_<float>(6, 7) << 0, 1, 0.99520785, 0.80997437, 0.16379407, 0.87996572, 0.26685631,
0, 1, 0.9934696, 0.2831718, 0.50738752, 0.345781, 0.5985168,
0, 1, 0.99096733, 0.13629119, 0.24892329, 0.19756334, 0.3310290,
0, 1, 0.98977017, 0.23901358, 0.09084064, 0.29902688, 0.1769477,
0, 1, 0.97203469, 0.67965847, 0.06876482, 0.73999709, 0.1513494,
0, 1, 0.95097077, 0.51901293, 0.45863652, 0.5777427, 0.5347801);
Mat ref = Mat_<float>({6, 7}, {
0, 1, 0.99520785, 0.80997437, 0.16379407, 0.87996572, 0.26685631,
0, 1, 0.9934696, 0.2831718, 0.50738752, 0.345781, 0.5985168,
0, 1, 0.99096733, 0.13629119, 0.24892329, 0.19756334, 0.3310290,
0, 1, 0.98977017, 0.23901358, 0.09084064, 0.29902688, 0.1769477,
0, 1, 0.97203469, 0.67965847, 0.06876482, 0.73999709, 0.1513494,
0, 1, 0.95097077, 0.51901293, 0.45863652, 0.5777427, 0.5347801
});
double scoreDiff = 3.4e-3, iouDiff = 1e-2;
if (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD || target == DNN_TARGET_CPU_FP16)
{
@@ -1876,9 +1880,11 @@ TEST_P(Test_TensorFlow_nets, EfficientDet)
Mat out = net.forward();
// References are from test for TensorFlow model.
Mat ref = (Mat_<float>(3, 7) << 0, 1, 0.8437444, 0.153996080160141, 0.20534580945968628, 0.7463544607162476, 0.7414066195487976,
0, 17, 0.8245924, 0.16657517850399017, 0.3996818959712982, 0.4111558794975281, 0.9306337833404541,
0, 7, 0.8039304, 0.6118435263633728, 0.13175517320632935, 0.9065558314323425, 0.2943994700908661);
Mat ref = Mat_<float>({3, 7}, {
0, 1, 0.8437444, 0.153996080160141, 0.20534580945968628, 0.7463544607162476, 0.7414066195487976,
0, 17, 0.8245924, 0.16657517850399017, 0.3996818959712982, 0.4111558794975281, 0.9306337833404541,
0, 7, 0.8039304, 0.6118435263633728, 0.13175517320632935, 0.9065558314323425, 0.2943994700908661
});
double scoreDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 4e-3 : 1e-5;
double iouDiff = (target == DNN_TARGET_OPENCL_FP16 || target == DNN_TARGET_MYRIAD) ? 2e-3 : 1e-4;
if (target == DNN_TARGET_CUDA_FP16)
+13 -12
View File
@@ -11,18 +11,19 @@ namespace opencv_test { namespace {
static
Mat getReference_DrawKeypoint(int cn)
{
static Mat ref = (Mat_<uint8_t>(11, 11) <<
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 15, 54, 15, 1, 1, 1, 1,
1, 1, 1, 76, 217, 217, 221, 81, 1, 1, 1,
1, 1, 100, 224, 111, 57, 115, 225, 101, 1, 1,
1, 44, 215, 100, 1, 1, 1, 101, 214, 44, 1,
1, 54, 212, 57, 1, 1, 1, 55, 212, 55, 1,
1, 40, 215, 104, 1, 1, 1, 105, 215, 40, 1,
1, 1, 102, 221, 111, 55, 115, 222, 103, 1, 1,
1, 1, 1, 76, 218, 217, 220, 81, 1, 1, 1,
1, 1, 1, 1, 15, 55, 15, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1);
static Mat ref = Mat_<uint8_t>({11, 11}, {
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 15, 54, 15, 1, 1, 1, 1,
1, 1, 1, 76, 217, 217, 221, 81, 1, 1, 1,
1, 1, 100, 224, 111, 57, 115, 225, 101, 1, 1,
1, 44, 215, 100, 1, 1, 1, 101, 214, 44, 1,
1, 54, 212, 57, 1, 1, 1, 55, 212, 55, 1,
1, 40, 215, 104, 1, 1, 1, 105, 215, 40, 1,
1, 1, 102, 221, 111, 55, 115, 222, 103, 1, 1,
1, 1, 1, 76, 218, 217, 220, 81, 1, 1, 1,
1, 1, 1, 1, 15, 55, 15, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
});
Mat res;
cvtColor(ref, res, (cn == 4) ? COLOR_GRAY2BGRA : COLOR_GRAY2BGR);
return res;
@@ -600,10 +600,14 @@ TEST( Features2d_FlannBasedMatcher, read_write )
TEST(Features2d_DMatch, issue_11855)
{
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 0,
1, 1, 1);
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
0, 0, 0);
Mat sources = Mat_<uchar>({2, 3}, {
1, 1, 0,
1, 1, 1
});
Mat targets = Mat_<uchar>({2, 3}, {
1, 1, 1,
0, 0, 0
});
Ptr<BFMatcher> bf = BFMatcher::create(NORM_HAMMING, true);
vector<vector<DMatch> > match;
bf->knnMatch(sources, targets, match, 1, noArray(), true);
@@ -617,15 +621,19 @@ TEST(Features2d_DMatch, issue_11855)
TEST(Features2d_DMatch, issue_17771)
{
Mat sources = (Mat_<uchar>(2, 3) << 1, 1, 0,
1, 1, 1);
Mat targets = (Mat_<uchar>(2, 3) << 1, 1, 1,
0, 0, 0);
Mat sources = Mat_<uchar>({2, 3}, {
1, 1, 0,
1, 1, 1
});
Mat targets = Mat_<uchar>({2, 3}, {
1, 1, 1,
0, 0, 0
});
UMat usources = sources.getUMat(ACCESS_READ);
UMat utargets = targets.getUMat(ACCESS_READ);
vector<vector<DMatch> > match;
Ptr<BFMatcher> ubf = BFMatcher::create(NORM_HAMMING);
Mat mask = (Mat_<uchar>(2, 2) << 1, 0, 0, 1);
Mat mask = Mat_<uchar>({2, 2}, {1, 0, 0, 1});
EXPECT_NO_THROW(ubf->knnMatch(usources, utargets, match, 1, mask, true));
}
+1 -1
View File
@@ -84,7 +84,7 @@ TEST(Flann_Index, empty_data_build_and_search)
cv::Mat data(0, 2, CV_32F);
cv::flann::Index index(data, indexParams);
cv::Mat query = (cv::Mat_<float>(1, 2) << 1.0f, 2.0f);
cv::Matx12f query(1.0f, 2.0f);
std::vector<int> indices;
std::vector<float> dists;
int nn = index.radiusSearch(query, indices, dists, 100, 4);
@@ -2119,7 +2119,7 @@ estimated, both components are set to NaN and, if @p inliers is provided, the ma
@code{.cpp}
cv::Vec2d t = cv::estimateTranslation2D(from, to, inliers);
cv::Mat T = (cv::Mat_<double>(2,3) << 1,0,t[0], 0,1,t[1]);
cv::Mat T = cv::Mat_<double>({2,3}, {1,0,t[0], 0,1,t[1]});
@endcode
The function estimates a pure 2D translation between two 2D point sets using the selected robust
+3 -3
View File
@@ -493,7 +493,7 @@ Mat findEssentialMat( InputArray _points1, InputArray _points2, double focal, Po
{
CV_INSTRUMENT_REGION();
Mat cameraMatrix = (Mat_<double>(3,3) << focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1);
Matx33d cameraMatrix(focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1);
return findEssentialMat(_points1, _points2, cameraMatrix, method, prob, threshold, maxIters, _mask);
}
@@ -728,7 +728,7 @@ int recoverPose( InputArray E, InputArray _points1, InputArray _points2, InputAr
int recoverPose( InputArray E, InputArray _points1, InputArray _points2, OutputArray _R,
OutputArray _t, double focal, Point2d pp, InputOutputArray _mask)
{
Mat cameraMatrix = (Mat_<double>(3,3) << focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1);
Matx33d cameraMatrix(focal, 0, pp.x, 0, focal, pp.y, 0, 0, 1);
return recoverPose(E, _points1, _points2, cameraMatrix, _R, _t, _mask);
}
@@ -745,7 +745,7 @@ void decomposeEssentialMat( InputArray _E, OutputArray _R1, OutputArray _R2, Out
if (determinant(U) < 0) U *= -1.;
if (determinant(Vt) < 0) Vt *= -1.;
Mat W = (Mat_<double>(3, 3) << 0, 1, 0, -1, 0, 0, 0, 0, 1);
Mat W = Mat_<double>({3, 3}, {0, 1, 0, -1, 0, 0, 0, 0, 1});
W.convertTo(W, E.type());
Mat R1, R2, t;
+2 -2
View File
@@ -1320,7 +1320,7 @@ Vec2d estimateTranslation2D(InputArray _from, InputArray _to,
if (refineIters > 0) {
if (T.empty())
T = (Mat_<double>(2,3) << 1,0,0, 0,1,0);
T = Mat_<double>({2,3}, {1,0,0, 0,1,0});
// LM refine on translation only.
// T is:
// [1 0 tx]
@@ -1392,7 +1392,7 @@ Vec2d estimateTranslation2D(InputArray _from, InputArray _to,
sy += (double)t[i].y - (double)f[i].y;
}
if (T.empty())
T = (Mat_<double>(2,3) << 1,0,0, 0,1,0);
T = Mat_<double>({2,3}, {1,0,0, 0,1,0});
double* H = T.ptr<double>();
H[2] = sx / nin; // t_x
H[5] = sy / nin; // t_y
@@ -207,9 +207,11 @@ TEST(Calib3d_EstimateAffine3D, umeyama_3_pt)
std::vector<cv::Vec3d> points = {{{0.80549149, 0.8225781, 0.79949521},
{0.28906756, 0.57158557, 0.9864789},
{0.58266182, 0.65474983, 0.25078834}}};
cv::Mat R = (cv::Mat_<double>(3,3) << 0.9689135, -0.0232753, 0.2463025,
0.0236362, 0.9997195, 0.0014915,
-0.2462682, 0.0043765, 0.9691918);
cv::Mat R = cv::Mat_<double>({3, 3}, {
0.9689135, -0.0232753, 0.2463025,
0.0236362, 0.9997195, 0.0014915,
-0.2462682, 0.0043765, 0.9691918
});
cv::Vec3d t(1., 2., 3.);
cv::Affine3d transform(R, t);
std::vector<cv::Vec3d> transformed_points(points.size());
+15 -9
View File
@@ -75,10 +75,12 @@ void CV_ProjectPointsTest::run(int)
RNG rng = ts->get_rng();
// generate data
cameraMatrix << 300.f, 0.f, imgSize.width/2.f,
0.f, 300.f, imgSize.height/2.f,
0.f, 0.f, 1.f;
distCoeffs << 0.1, 0.01, 0.001, 0.001;
cameraMatrix = cv::Mat_<float>({3, 3}, {
300.f, 0.f, imgSize.width/2.f,
0.f, 300.f, imgSize.height/2.f,
0.f, 0.f, 1.f
});
distCoeffs = cv::Mat_<float>({1, 4}, {0.1f, 0.01f, 0.001f, 0.001f});
rvec(0,0) = rng.uniform( rMinVal, rMaxVal );
rvec(0,1) = rng.uniform( rMinVal, rMaxVal );
@@ -285,9 +287,11 @@ TEST(Calib3d_ProjectPoints_CPP, inputShape)
const float L = 0.1f;
{
//3xN 1-channel
Mat objectPoints = (Mat_<float>(3, 2) << -L, L,
L, L,
0, 0);
Mat objectPoints = Mat_<float>({3, 2}, {
-L, L,
L, L,
0, 0
});
vector<Point2f> imagePoints;
projectPoints(objectPoints, rvec, tvec, cameraMatrix, noArray(), imagePoints);
EXPECT_EQ(objectPoints.cols, static_cast<int>(imagePoints.size()));
@@ -298,8 +302,10 @@ TEST(Calib3d_ProjectPoints_CPP, inputShape)
}
{
//Nx2 1-channel
Mat objectPoints = (Mat_<float>(2, 3) << -L, L, 0,
L, L, 0);
Mat objectPoints = Mat_<float>({2, 3}, {
-L, L, 0,
L, L, 0
});
vector<Point2f> imagePoints;
projectPoints(objectPoints, rvec, tvec, cameraMatrix, noArray(), imagePoints);
EXPECT_EQ(objectPoints.rows, static_cast<int>(imagePoints.size()));
+3 -3
View File
@@ -1345,20 +1345,20 @@ INSTANTIATE_TEST_CASE_P(Imgproc, convexHull_monotonous,
Point(3, 2), Point(3, 4), Point(2, 5), Point(1, 5),
Point(2, 5), Point(3, 4), Point(6, 4), Point(6, 2)
},
(Mat_<int>(5, 1) << 0, 3, 4, 6, 7)
Mat_<int>({5, 1}, {0, 3, 4, 6, 7})
),
std::make_tuple(
std::vector<Point>{
Point(3, -2), Point(3, -4), Point(2, -5), Point(1, -5),
Point(2, -5), Point(3, -4), Point(6, -4), Point(6, -2)
},
(Mat_<int>(5, 1) << 3, 0, 7, 6, 4)
Mat_<int>({5, 1}, {3, 0, 7, 6, 4})
),
std::make_tuple(
std::vector<Point>{
Point(1, 1), Point(1, 0), Point(0, 0), Point(1, 0), Point(0, 1)
},
(Mat_<int>(4, 1) << 0, 1, 2, 4)
Mat_<int>({4, 1}, {0, 1, 2, 4})
)
),
testing::Bool()
+22 -20
View File
@@ -82,17 +82,18 @@ TEST_F(fisheyeTest, projectPoints)
TEST_F(fisheyeTest, distortUndistortPoints)
{
int width = imageSize.width;
int height = imageSize.height;
double width = imageSize.width;
double height = imageSize.height;
/* Create test points */
cv::Mat principalPoints = (cv::Mat_<double>(5, 2) << K(0, 2), K(1, 2), // (cx, cy)
/* Image corners */
0, 0,
0, height,
width, 0,
width, height
);
cv::Mat principalPoints = cv::Mat_<double>({5, 2}, {
K(0, 2), K(1, 2), // (cx, cy)
/* Image corners */
0, 0,
0, height,
width, 0,
width, height
});
/* Random points inside image */
cv::Mat xy[2] = {};
@@ -130,8 +131,8 @@ TEST_F(fisheyeTest, distortUndistortPoints)
TEST_F(fisheyeTest, distortUndistortPointsNewCameraFixed)
{
int width = imageSize.width;
int height = imageSize.height;
double width = imageSize.width;
double height = imageSize.height;
/* Random points inside image */
cv::Mat xy[2] = {};
@@ -166,18 +167,19 @@ TEST_F(fisheyeTest, distortUndistortPointsNewCameraFixed)
TEST_F(fisheyeTest, distortUndistortPointsNewCameraRandom)
{
int width = imageSize.width;
int height = imageSize.height;
double width = imageSize.width;
double height = imageSize.height;
/* Create test points */
std::vector<cv::Point2d> points0Vector;
cv::Mat principalPoints = (cv::Mat_<double>(5, 2) << K(0, 2), K(1, 2), // (cx, cy)
/* Image corners */
0, 0,
0, height,
width, 0,
width, height
);
cv::Mat principalPoints = cv::Mat_<double>({5, 2}, {
K(0, 2), K(1, 2), // (cx, cy)
/* Image corners */
0, 0,
0, height,
width, 0,
width, height
});
/* Random points inside image */
cv::Mat xy[2] = {};
+76 -67
View File
@@ -890,8 +890,8 @@ TEST(Calib3d_SolvePnP, input_type)
points3d_.push_back(Point3d(-l, l, l));
points3dF_.push_back(Point3f(-l, l, l));
Mat trueRvec = (Mat_<double>(3,1) << 0.1, -0.25, 0.467);
Mat trueTvec = (Mat_<double>(3,1) << -0.21, 0.12, 0.746);
Mat trueRvec = Mat_<double>({3, 1}, {0.1, -0.25, 0.467});
Mat trueTvec = Mat_<double>({3, 1}, {-0.21, 0.12, 0.746});
for (int method = 0; method < SOLVEPNP_MAX_COUNT; method++)
{
@@ -1247,15 +1247,15 @@ TEST(Calib3d_SolvePnP, translation)
projectPoints(p3d, crvec, ctvec, cameraIntrinsic, noArray(), p2d);
Mat rvec;
Mat tvec;
rvec =(Mat_<float>(3,1) << 0, 0, 0);
tvec = (Mat_<float>(3,1) << 100, 100, 0);
rvec =Mat_<float>({3, 1}, {0, 0, 0});
tvec = Mat_<float>({3, 1}, {100, 100, 0});
solvePnP(p3d, p2d, cameraIntrinsic, noArray(), rvec, tvec, true);
EXPECT_TRUE(checkRange(rvec));
EXPECT_TRUE(checkRange(tvec));
rvec =(Mat_<double>(3,1) << 0, 0, 0);
tvec = (Mat_<double>(3,1) << 100, 100, 0);
rvec =Mat_<double>({3, 1}, {0, 0, 0});
tvec = Mat_<double>({3, 1}, {100, 100, 0});
solvePnP(p3d, p2d, cameraIntrinsic, noArray(), rvec, tvec, true);
EXPECT_TRUE(checkRange(rvec));
EXPECT_TRUE(checkRange(tvec));
@@ -1278,14 +1278,14 @@ TEST(Calib3d_SolvePnP, iterativeInitialGuess3pts)
p3d.push_back(Point3d(L, -L, 0.0));
p3d.push_back(Point3d(L, L, 0.0));
Mat rvec_ground_truth = (Mat_<double>(3,1) << 0.3, -0.2, 0.75);
Mat tvec_ground_truth = (Mat_<double>(3,1) << 0.15, -0.2, 1.5);
Mat rvec_ground_truth = Mat_<double>({3, 1}, {0.3, -0.2, 0.75});
Mat tvec_ground_truth = Mat_<double>({3, 1}, {0.15, -0.2, 1.5});
vector<Point2d> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
Mat rvec_est = (Mat_<double>(3,1) << 0.2, -0.1, 0.6);
Mat tvec_est = (Mat_<double>(3,1) << 0.05, -0.05, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.2, -0.1, 0.6});
Mat tvec_est = Mat_<double>({3, 1}, {0.05, -0.05, 1.0});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1312,14 +1312,14 @@ TEST(Calib3d_SolvePnP, iterativeInitialGuess3pts)
p3d.push_back(Point3f(L, -L, 0.0f));
p3d.push_back(Point3f(L, L, 0.0f));
Mat rvec_ground_truth = (Mat_<float>(3,1) << -0.75f, 0.4f, 0.34f);
Mat tvec_ground_truth = (Mat_<float>(3,1) << -0.15f, 0.35f, 1.58f);
Mat rvec_ground_truth = Mat_<float>({3, 1}, {-0.75f, 0.4f, 0.34f});
Mat tvec_ground_truth = Mat_<float>({3, 1}, {-0.15f, 0.35f, 1.58f});
vector<Point2f> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
Mat rvec_est = (Mat_<float>(3,1) << -0.5f, 0.2f, 0.2f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.2f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.5f, 0.2f, 0.2f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.2f, 1.0f});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1351,14 +1351,14 @@ TEST(Calib3d_SolvePnP, iterativeInitialGuess)
p3d.push_back(Point3d(-L, L, L/2));
p3d.push_back(Point3d(0, 0, -L/2));
Mat rvec_ground_truth = (Mat_<double>(3,1) << 0.3, -0.2, 0.75);
Mat tvec_ground_truth = (Mat_<double>(3,1) << 0.15, -0.2, 1.5);
Mat rvec_ground_truth = Mat_<double>({3, 1}, {0.3, -0.2, 0.75});
Mat tvec_ground_truth = Mat_<double>({3, 1}, {0.15, -0.2, 1.5});
vector<Point2d> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
Mat rvec_est = (Mat_<double>(3,1) << 0.1, -0.1, 0.1);
Mat tvec_est = (Mat_<double>(3,1) << 0.0, -0.5, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.1, -0.1, 0.1});
Mat tvec_est = Mat_<double>({3, 1}, {0.0, -0.5, 1.0});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1387,14 +1387,14 @@ TEST(Calib3d_SolvePnP, iterativeInitialGuess)
p3d.push_back(Point3f(-L, L, L/2));
p3d.push_back(Point3f(0, 0, -L/2));
Mat rvec_ground_truth = (Mat_<float>(3,1) << -0.75f, 0.4f, 0.34f);
Mat tvec_ground_truth = (Mat_<float>(3,1) << -0.15f, 0.35f, 1.58f);
Mat rvec_ground_truth = Mat_<float>({3, 1}, {-0.75f, 0.4f, 0.34f});
Mat tvec_ground_truth = Mat_<float>({3, 1}, {-0.15f, 0.35f, 1.58f});
vector<Point2f> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
Mat rvec_est = (Mat_<float>(3,1) << -0.1f, 0.1f, 0.1f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.0f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.1f, 0.1f, 0.1f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.0f, 1.0f});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1563,15 +1563,15 @@ TEST(Calib3d_SolvePnP, refine3pts)
p3d.push_back(Point3d(L, -L, 0.0));
p3d.push_back(Point3d(L, L, 0.0));
Mat rvec_ground_truth = (Mat_<double>(3,1) << 0.3, -0.2, 0.75);
Mat tvec_ground_truth = (Mat_<double>(3,1) << 0.15, -0.2, 1.5);
Mat rvec_ground_truth = Mat_<double>({3, 1}, {0.3, -0.2, 0.75});
Mat tvec_ground_truth = Mat_<double>({3, 1}, {0.15, -0.2, 1.5});
vector<Point2d> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
{
Mat rvec_est = (Mat_<double>(3,1) << 0.2, -0.1, 0.6);
Mat tvec_est = (Mat_<double>(3,1) << 0.05, -0.05, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.2, -0.1, 0.6});
Mat tvec_est = Mat_<double>({3, 1}, {0.05, -0.05, 1.0});
solvePnPRefineLM(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1585,8 +1585,8 @@ TEST(Calib3d_SolvePnP, refine3pts)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<double>(3,1) << 0.2, -0.1, 0.6);
Mat tvec_est = (Mat_<double>(3,1) << 0.05, -0.05, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.2, -0.1, 0.6});
Mat tvec_est = Mat_<double>({3, 1}, {0.05, -0.05, 1.0});
solvePnPRefineVVS(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1612,15 +1612,15 @@ TEST(Calib3d_SolvePnP, refine3pts)
p3d.push_back(Point3f(L, -L, 0.0f));
p3d.push_back(Point3f(L, L, 0.0f));
Mat rvec_ground_truth = (Mat_<float>(3,1) << -0.75f, 0.4f, 0.34f);
Mat tvec_ground_truth = (Mat_<float>(3,1) << -0.15f, 0.35f, 1.58f);
Mat rvec_ground_truth = Mat_<float>({3, 1}, {-0.75f, 0.4f, 0.34f});
Mat tvec_ground_truth = Mat_<float>({3, 1}, {-0.15f, 0.35f, 1.58f});
vector<Point2f> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
{
Mat rvec_est = (Mat_<float>(3,1) << -0.5f, 0.2f, 0.2f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.2f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.5f, 0.2f, 0.2f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.2f, 1.0f});
solvePnPRefineLM(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1634,8 +1634,8 @@ TEST(Calib3d_SolvePnP, refine3pts)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<float>(3,1) << -0.5f, 0.2f, 0.2f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.2f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.5f, 0.2f, 0.2f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.2f, 1.0f});
solvePnPRefineVVS(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1667,15 +1667,15 @@ TEST(Calib3d_SolvePnP, refine)
p3d.push_back(Point3d(-L, L, L/2));
p3d.push_back(Point3d(0, 0, -L/2));
Mat rvec_ground_truth = (Mat_<double>(3,1) << 0.3, -0.2, 0.75);
Mat tvec_ground_truth = (Mat_<double>(3,1) << 0.15, -0.2, 1.5);
Mat rvec_ground_truth = Mat_<double>({3, 1}, {0.3, -0.2, 0.75});
Mat tvec_ground_truth = Mat_<double>({3, 1}, {0.15, -0.2, 1.5});
vector<Point2d> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
{
Mat rvec_est = (Mat_<double>(3,1) << 0.1, -0.1, 0.1);
Mat tvec_est = (Mat_<double>(3,1) << 0.0, -0.5, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.1, -0.1, 0.1});
Mat tvec_est = Mat_<double>({3, 1}, {0.0, -0.5, 1.0});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1689,8 +1689,8 @@ TEST(Calib3d_SolvePnP, refine)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<double>(3,1) << 0.1, -0.1, 0.1);
Mat tvec_est = (Mat_<double>(3,1) << 0.0, -0.5, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.1, -0.1, 0.1});
Mat tvec_est = Mat_<double>({3, 1}, {0.0, -0.5, 1.0});
solvePnPRefineLM(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1704,8 +1704,8 @@ TEST(Calib3d_SolvePnP, refine)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<double>(3,1) << 0.1, -0.1, 0.1);
Mat tvec_est = (Mat_<double>(3,1) << 0.0, -0.5, 1.0);
Mat rvec_est = Mat_<double>({3, 1}, {0.1, -0.1, 0.1});
Mat tvec_est = Mat_<double>({3, 1}, {0.0, -0.5, 1.0});
solvePnPRefineVVS(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1734,15 +1734,15 @@ TEST(Calib3d_SolvePnP, refine)
p3d.push_back(Point3f(-L, L, L/2));
p3d.push_back(Point3f(0, 0, -L/2));
Mat rvec_ground_truth = (Mat_<float>(3,1) << -0.75f, 0.4f, 0.34f);
Mat tvec_ground_truth = (Mat_<float>(3,1) << -0.15f, 0.35f, 1.58f);
Mat rvec_ground_truth = Mat_<float>({3, 1}, {-0.75f, 0.4f, 0.34f});
Mat tvec_ground_truth = Mat_<float>({3, 1}, {-0.15f, 0.35f, 1.58f});
vector<Point2f> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
{
Mat rvec_est = (Mat_<float>(3,1) << -0.1f, 0.1f, 0.1f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.0f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.1f, 0.1f, 0.1f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.0f, 1.0f});
solvePnP(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est, true, SOLVEPNP_ITERATIVE);
@@ -1756,8 +1756,8 @@ TEST(Calib3d_SolvePnP, refine)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<float>(3,1) << -0.1f, 0.1f, 0.1f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.0f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.1f, 0.1f, 0.1f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.0f, 1.0f});
solvePnPRefineLM(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1771,8 +1771,8 @@ TEST(Calib3d_SolvePnP, refine)
EXPECT_LE(cvtest::norm(tvec_ground_truth, tvec_est, NORM_INF), 1e-6);
}
{
Mat rvec_est = (Mat_<float>(3,1) << -0.1f, 0.1f, 0.1f);
Mat tvec_est = (Mat_<float>(3,1) << 0.0f, 0.0f, 1.0f);
Mat rvec_est = Mat_<float>({3, 1}, {-0.1f, 0.1f, 0.1f});
Mat tvec_est = Mat_<float>({3, 1}, {0.0f, 0.0f, 1.0f});
solvePnPRefineVVS(p3d, p2d, intrinsics, noArray(), rvec_est, tvec_est);
@@ -1801,8 +1801,8 @@ TEST(Calib3d_SolvePnP, refine)
p3d.push_back(Point3d(-L, L, L/2));
p3d.push_back(Point3d(0, 0, -L/2));
Mat rvec_ground_truth = (Mat_<double>(3,1) << 0.3, -0.2, 0.75);
Mat tvec_ground_truth = (Mat_<double>(3,1) << 0.15, -0.2, 1.5);
Mat rvec_ground_truth = Mat_<double>({3, 1}, {0.3, -0.2, 0.75});
Mat tvec_ground_truth = Mat_<double>({3, 1}, {0.15, -0.2, 1.5});
vector<Point2d> p2d;
projectPoints(p3d, rvec_ground_truth, tvec_ground_truth, intrinsics, noArray(), p2d);
@@ -1886,11 +1886,14 @@ TEST(Calib3d_SolvePnPRansac, minPoints)
{
//nb points = 5 --> ransac_kernel_method = SOLVEPNP_EPNP
Mat keypoints13D = (Mat_<float>(5, 3) << 12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434,
15.316854, 3.7486348, 12.491116);
Mat keypoints13D;
Mat_<double>({5, 3}, {
12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434,
15.316854, 3.7486348, 12.491116
}).convertTo(keypoints13D, CV_32F);
vector<Point2f> imagesPoints;
projectPoints(keypoints13D, true_rvec, true_tvec, matK, distCoeff, imagesPoints);
@@ -1917,10 +1920,13 @@ TEST(Calib3d_SolvePnPRansac, minPoints)
}
{
//nb points = 4 --> ransac_kernel_method = SOLVEPNP_P3P
Mat keypoints13D = (Mat_<float>(4, 3) << 12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434);
Mat keypoints13D;
Mat_<double>({4, 3}, {
12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434
}).convertTo(keypoints13D, CV_32F);
vector<Point2f> imagesPoints;
projectPoints(keypoints13D, true_rvec, true_tvec, matK, distCoeff, imagesPoints);
@@ -1958,12 +1964,15 @@ TEST(Calib3d_SolvePnPRansac, inputShape)
{
//Nx3 1-channel
Mat keypoints13D = (Mat_<float>(6, 3) << 12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434,
10.00604, 2.8654366, 15.472504,
-4.6863389, 5.9355154, 13.146358);
Mat keypoints13D;
Mat_<double>({6, 3}, {
12.00604, -2.8654366, 18.472504,
7.6863389, 4.9355154, 11.146358,
14.260933, 2.8320458, 12.582781,
3.4562225, 8.2668982, 11.300434,
10.00604, 2.8654366, 15.472504,
-4.6863389, 5.9355154, 13.146358
}).convertTo(keypoints13D, CV_32F);
vector<Point2f> imagesPoints;
projectPoints(keypoints13D, true_rvec, true_tvec, matK, distCoeff, imagesPoints);
+17 -14
View File
@@ -166,11 +166,12 @@ TEST_F(UndistortPointsTest, undistortImagePointsAccuracy)
TEST_F(UndistortPointsTest, stop_criteria)
{
Mat cameraMatrix = (Mat_<double>(3,3,CV_64F) << 857.48296979, 0, 968.06224829,
0, 876.71824265, 556.37145899,
0, 0, 1);
Mat distCoeffs = (Mat_<double>(5,1,CV_64F) <<
-2.57614020e-01, 8.77086999e-02, -2.56970803e-04, -5.93390389e-04, -1.52194091e-02);
Mat cameraMatrix = Mat_<double>({3, 3}, {
857.48296979, 0, 968.06224829,
0, 876.71824265, 556.37145899,
0, 0, 1
});
Mat distCoeffs = Mat_<double>({5, 1}, {-2.57614020e-01, 8.77086999e-02, -2.56970803e-04, -5.93390389e-04, -1.52194091e-02});
Point2d pt_distorted(theRNG().uniform(0.0, 1920.0), theRNG().uniform(0.0, 1080.0));
@@ -227,15 +228,17 @@ TEST_F(UndistortPointsTest, regression_14583)
TEST_F(UndistortPointsTest, regression_27916)
{
cv::Mat K = (cv::Mat_<double>(3, 3) <<
1570.8956145992222, 0., 744.87337646727406, 0.,
1570.3494207432338, 575.55087456337526, 0., 0., 1.);
cv::Mat dist = (cv::Mat_<double>(1, 12) <<
-2.8247717583453804, -0.80078070764368037,
-0.014595359484103326, 0.0018820998949700702, 1.9827795585249783,
-2.7306773773930897, -1.217725820479524, 2.4052243546080136,
-0.0020670359760441713, 3.4660880793174063e-05,
0.014100351510458799, -3.0935329736207612e-05);
cv::Mat K = cv::Mat_<double>({3, 3}, {
1570.8956145992222, 0., 744.87337646727406, 0.,
1570.3494207432338, 575.55087456337526, 0., 0., 1.
});
cv::Mat dist = cv::Mat_<double>({1, 12}, {
-2.8247717583453804, -0.80078070764368037,
-0.014595359484103326, 0.0018820998949700702, 1.9827795585249783,
-2.7306773773930897, -1.217725820479524, 2.4052243546080136,
-0.0020670359760441713, 3.4660880793174063e-05,
0.014100351510458799, -3.0935329736207612e-05
});
const cv::TermCriteria termCriteria(TermCriteria::MAX_ITER | TermCriteria::EPS, 100, thresh / 2);
std::vector<cv::Point2d> distortedPoints, distortedPoints2;
+7 -6
View File
@@ -121,17 +121,18 @@ PERF_TEST_P( ImgProc_ParallelFilter_Perf, filter2D_parallel,
if (isSep)
{
Mat kx = (Mat_<float>(1, 3) << 0.25f, 0.5f, 0.25f);
Mat ky = (Mat_<float>(3, 1) << 0.25f, 0.5f, 0.25f);
Mat kx = Mat_<float>({1, 3}, {0.25f, 0.5f, 0.25f});
Mat ky = Mat_<float>({3, 1}, {0.25f, 0.5f, 0.25f});
TEST_CYCLE() cv::sepFilter2D(src, dst, -1, kx, ky,
Point(-1, -1), 0, borderMode);
}
else
{
Mat kernel = (Mat_<float>(3, 3) <<
1/16.f, 2/16.f, 1/16.f,
2/16.f, 4/16.f, 2/16.f,
1/16.f, 2/16.f, 1/16.f);
Mat kernel = Mat_<float>({3, 3}, {
1/16.f, 2/16.f, 1/16.f,
2/16.f, 4/16.f, 2/16.f,
1/16.f, 2/16.f, 1/16.f
});
TEST_CYCLE() cv::filter2D(src, dst, -1, kernel,
Point(-1, -1), 0, borderMode);
}
+1 -1
View File
@@ -3299,7 +3299,7 @@ TEST(ImgProc_cvtColor_InvalidNumOfChannels, regression_25971)
TEST(ImgProc_applyColorMap, dimensions)
{
cv::Mat1b src({0, 128, 255});
cv::Mat3b gt = (cv::Mat3b(1, 3) << cv::Vec3b(128, 0, 0), cv::Vec3b(126, 255, 130), cv::Vec3b(0, 0, 128));
cv::Mat3b gt = cv::Mat3b({1, 3}, {cv::Vec3b(128, 0, 0), cv::Vec3b(126, 255, 130), cv::Vec3b(0, 0, 128)});
cv::Mat3b dst;
cv::applyColorMap(src, dst, cv::COLORMAP_JET);
ASSERT_EQ(cv::norm(dst, gt, NORM_L1), 0);
+40 -43
View File
@@ -676,7 +676,7 @@ TEST(Imgproc_Blur, borderTypes)
// should work like !BORDER_ISOLATED
cv::blur(src_roi, dst, kernelSize, Point(-1, -1), BORDER_REPLICATE);
Mat expected_dst =
(Mat_<uchar>(3, 3) << 170, 113, 170, 113, 28, 113, 170, 113, 170);
Mat_<uchar>({3, 3}, {170, 113, 170, 113, 28, 113, 170, 113, 170});
EXPECT_EQ(expected_dst.type(), dst.type());
EXPECT_EQ(expected_dst.size(), dst.size());
EXPECT_DOUBLE_EQ(0.0, cvtest::norm(expected_dst, dst, NORM_INF));
@@ -742,7 +742,7 @@ TEST(Imgproc_Sobel, borderTypes)
int kernelSize = 3;
/// ksize > src_roi.size()
Mat src = (Mat_<uchar>(3, 3) << 1, 2, 3, 4, 5, 6, 7, 8, 9), dst, expected_dst;
Mat src = Mat_<uchar>({3, 3}, {1, 2, 3, 4, 5, 6, 7, 8, 9}), dst, expected_dst;
Mat src_roi = src(Rect(1, 1, 1, 1));
src_roi.setTo(cv::Scalar::all(0));
@@ -765,7 +765,7 @@ TEST(Imgproc_Sobel, borderTypes)
// should work like !BORDER_ISOLATED, so the function MUST read values in full matrix
expected_dst =
(Mat_<short>(3, 3) << -15, 0, 15, -20, 0, 20, -15, 0, 15);
Mat_<short>({3, 3}, {-15, 0, 15, -20, 0, 20, -15, 0, 15});
cv::Sobel(src_roi, dst, CV_16S, 1, 0, kernelSize, 1, 0, BORDER_REPLICATE);
EXPECT_EQ(expected_dst.type(), dst.type());
EXPECT_EQ(expected_dst.size(), dst.size());
@@ -789,21 +789,15 @@ TEST(Imgproc_Sobel, borderTypes)
TEST(Imgproc_MorphEx, hitmiss_regression_8957)
{
Mat_<uchar> src(3, 3);
src << 0, 255, 0,
0, 0, 0,
0, 255, 0;
Mat_<uchar> src({3, 3}, {0, 255, 0,
0, 0, 0,
0, 255, 0});
Mat_<uchar> kernel = src / 255;
Mat dst;
cv::morphologyEx(src, dst, MORPH_HITMISS, kernel);
Mat ref = Mat::zeros(3, 3, CV_8U);
ref.at<uchar>(1, 1) = 255;
ASSERT_DOUBLE_EQ(cvtest::norm(dst, ref, NORM_INF), 0.);
src.at<uchar>(1, 1) = 255;
ref.at<uchar>(0, 1) = 255;
ref.at<uchar>(2, 1) = 255;
@@ -813,11 +807,9 @@ TEST(Imgproc_MorphEx, hitmiss_regression_8957)
TEST(Imgproc_MorphEx, hitmiss_zero_kernel)
{
Mat_<uchar> src(3, 3);
src << 0, 255, 0,
0, 0, 0,
0, 255, 0;
Mat_<uchar> src({3, 3}, {0, 255, 0,
0, 0, 0,
0, 255, 0});
Mat_<uchar> kernel = Mat_<uchar>::zeros(3, 3);
Mat dst;
@@ -989,22 +981,26 @@ TEST(Imgproc_MedianBlur, regression_28385)
TEST(Imgproc_Sobel, s16_regression_13506)
{
Mat src = (Mat_<short>(8, 16) << 127, 138, 130, 102, 118, 97, 76, 84, 124, 90, 146, 63, 130, 87, 212, 85,
164, 3, 51, 124, 151, 89, 154, 117, 36, 88, 116, 117, 180, 112, 147, 124,
63, 50, 115, 103, 83, 148, 106, 79, 213, 106, 135, 53, 79, 106, 122, 112,
218, 107, 81, 126, 78, 138, 85, 142, 151, 108, 104, 158, 155, 81, 112, 178,
184, 96, 187, 148, 150, 112, 138, 162, 222, 146, 128, 49, 124, 46, 165, 104,
119, 164, 77, 144, 186, 98, 106, 148, 155, 157, 160, 151, 156, 149, 43, 122,
106, 155, 120, 132, 159, 115, 126, 188, 44, 79, 164, 201, 153, 97, 139, 133,
133, 98, 111, 165, 66, 106, 131, 85, 176, 156, 67, 108, 142, 91, 74, 137);
Mat ref = (Mat_<short>(8, 16) << 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1020, -796, -489, -469, -247, 317, 760, 1429, 1983, 1384, 254, -459, -899, -1197, -1172, -1058,
2552, 2340, 1617, 591, 9, 96, 722, 1985, 2746, 1916, 676, 9, -635, -1115, -779, -380,
3546, 3349, 2838, 2206, 1388, 669, 938, 1880, 2252, 1785, 1083, 606, 180, -298, -464, -418,
816, 966, 1255, 1652, 1619, 924, 535, 288, 5, 601, 1581, 1870, 1520, 625, -627, -1260,
-782, -610, -395, -267, -122, -42, -317, -1378, -2293, -1451, 596, 1870, 1679, 763, -69, -394,
-882, -681, -463, -818, -1167, -732, -463, -1042, -1604, -1592, -1047, -334, -104, -117, 229, 512,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
Mat src = Mat_<short>({8, 16}, {
127, 138, 130, 102, 118, 97, 76, 84, 124, 90, 146, 63, 130, 87, 212, 85,
164, 3, 51, 124, 151, 89, 154, 117, 36, 88, 116, 117, 180, 112, 147, 124,
63, 50, 115, 103, 83, 148, 106, 79, 213, 106, 135, 53, 79, 106, 122, 112,
218, 107, 81, 126, 78, 138, 85, 142, 151, 108, 104, 158, 155, 81, 112, 178,
184, 96, 187, 148, 150, 112, 138, 162, 222, 146, 128, 49, 124, 46, 165, 104,
119, 164, 77, 144, 186, 98, 106, 148, 155, 157, 160, 151, 156, 149, 43, 122,
106, 155, 120, 132, 159, 115, 126, 188, 44, 79, 164, 201, 153, 97, 139, 133,
133, 98, 111, 165, 66, 106, 131, 85, 176, 156, 67, 108, 142, 91, 74, 137
});
Mat ref = Mat_<short>({8, 16}, {
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
-1020, -796, -489, -469, -247, 317, 760, 1429, 1983, 1384, 254, -459, -899, -1197, -1172, -1058,
2552, 2340, 1617, 591, 9, 96, 722, 1985, 2746, 1916, 676, 9, -635, -1115, -779, -380,
3546, 3349, 2838, 2206, 1388, 669, 938, 1880, 2252, 1785, 1083, 606, 180, -298, -464, -418,
816, 966, 1255, 1652, 1619, 924, 535, 288, 5, 601, 1581, 1870, 1520, 625, -627, -1260,
-782, -610, -395, -267, -122, -42, -317, -1378, -2293, -1451, 596, 1870, 1679, 763, -69, -394,
-882, -681, -463, -818, -1167, -732, -463, -1042, -1604, -1592, -1047, -334, -104, -117, 229, 512,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
});
Mat dst;
Sobel(src, dst, CV_16S, 0, 1, 5);
ASSERT_EQ(0.0, cvtest::norm(dst, ref, NORM_INF));
@@ -1257,16 +1253,17 @@ static void runFilter(const Mat& src, Mat& dst, int borderType, bool isSep)
{
if (isSep)
{
Mat kx = (Mat_<float>(1, 3) << 0.25f, 0.5f, 0.25f);
Mat ky = (Mat_<float>(3, 1) << 0.25f, 0.5f, 0.25f);
Mat kx = Mat_<float>({1, 3}, {0.25f, 0.5f, 0.25f});
Mat ky = Mat_<float>({3, 1}, {0.25f, 0.5f, 0.25f});
cv::sepFilter2D(src, dst, -1, kx, ky, Point(-1, -1), 0, borderType);
}
else
{
Mat kernel = (Mat_<float>(3, 3) <<
1/16.f, 2/16.f, 1/16.f,
2/16.f, 4/16.f, 2/16.f,
1/16.f, 2/16.f, 1/16.f);
Mat kernel = Mat_<float>({3, 3}, {
1/16.f, 2/16.f, 1/16.f,
2/16.f, 4/16.f, 2/16.f,
1/16.f, 2/16.f, 1/16.f
});
cv::filter2D(src, dst, -1, kernel, Point(-1, -1), 0, borderType);
}
}
@@ -1362,7 +1359,7 @@ TEST(Imgproc_Filter2D, padding_bounds_extreme_anchor)
{
// Case 1: 1x1 image, large kernel, anchor at far right
{
Mat src = (Mat_<uchar>(1, 1) << 128);
Mat src = Mat_<uchar>({1, 1}, {128});
Mat kernel = Mat::ones(1, 7, CV_32F) / 7.0f;
Mat dst;
Point anchor(6, 0);
@@ -1373,7 +1370,7 @@ TEST(Imgproc_Filter2D, padding_bounds_extreme_anchor)
// Case 2: 1x1 image, large kernel, anchor at far left
{
Mat src = (Mat_<uchar>(1, 1) << 200);
Mat src = Mat_<uchar>({1, 1}, {200});
Mat kernel = Mat::ones(1, 9, CV_32F) / 9.0f;
Mat dst;
Point anchor(0, 0);
@@ -1384,7 +1381,7 @@ TEST(Imgproc_Filter2D, padding_bounds_extreme_anchor)
// Case 3: 2x2 image, 11x11 kernel, various anchors
{
Mat src = (Mat_<uchar>(2, 2) << 100, 150, 200, 250);
Mat src = Mat_<uchar>({2, 2}, {100, 150, 200, 250});
Mat kernel = Mat::ones(11, 11, CV_32F) / 121.0f;
Mat dst;
for (int ax : {0, 5, 10}) {
@@ -1410,7 +1407,7 @@ TEST(Imgproc_Filter2D, padding_bounds_extreme_anchor)
// Case 5: all border types with all valid anchors for wide kernel on narrow image
{
Mat src = (Mat_<uchar>(1, 3) << 10, 20, 30);
Mat src = Mat_<uchar>({1, 3}, {10, 20, 30});
Mat kernel = Mat::ones(1, 15, CV_32F) / 15.0f;
Mat dst;
int borderTypes[] = {BORDER_REPLICATE, BORDER_REFLECT, BORDER_REFLECT_101, BORDER_CONSTANT};
+1 -1
View File
@@ -39,7 +39,7 @@ void TestPhaseCorrelationIterative(const Size& size, const double maxShift)
{
const auto shift =
Point2d(maxShift * i / (iters - 1), maxShift * i / (iters - 1)) + shiftOffset;
const Mat Tmat = (Mat_<double>(2, 3) << 1., 0., shift.x, 0., 1., shift.y);
const Mat Tmat = Mat_<double>({2, 3}, {1., 0., shift.x, 0., 1., shift.y});
warpAffine(image1, image2, Tmat, image2.size());
Mat crop2 = CropMid(image2, size.width, size.height);
const auto ipcshift = phaseCorrelateIterative(crop1, crop2);
+30 -26
View File
@@ -194,41 +194,45 @@ TEST(Resize_Bitexact, Nearest8U)
Mat src[6], dst[6];
// 2x decimation
src[0] = (Mat_<uint8_t>(1, 6) << 0, 1, 2, 3, 4, 5);
dst[0] = (Mat_<uint8_t>(1, 3) << 1, 3, 5);
src[0] = Mat_<uint8_t>({1, 6}, {0, 1, 2, 3, 4, 5});
dst[0] = Mat_<uint8_t>({1, 3}, {1, 3, 5});
// decimation odd to 1
src[1] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[1] = (Mat_<uint8_t>(1, 1) << 2);
src[1] = Mat_<uint8_t>({1, 5}, {0, 1, 2, 3, 4});
dst[1] = Mat_<uint8_t>({1, 1}, {2});
// decimation n*2-1 to n
src[2] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[2] = (Mat_<uint8_t>(1, 3) << 0, 2, 4);
src[2] = Mat_<uint8_t>({1, 5}, {0, 1, 2, 3, 4});
dst[2] = Mat_<uint8_t>({1, 3}, {0, 2, 4});
// decimation n*2+1 to n
src[3] = (Mat_<uint8_t>(1, 5) << 0, 1, 2, 3, 4);
dst[3] = (Mat_<uint8_t>(1, 2) << 1, 3);
src[3] = Mat_<uint8_t>({1, 5}, {0, 1, 2, 3, 4});
dst[3] = Mat_<uint8_t>({1, 2}, {1, 3});
// zoom
src[4] = (Mat_<uint8_t>(3, 5) <<
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14);
dst[4] = (Mat_<uint8_t>(5, 7) <<
0, 1, 1, 2, 3, 3, 4,
0, 1, 1, 2, 3, 3, 4,
5, 6, 6, 7, 8, 8, 9,
10, 11, 11, 12, 13, 13, 14,
10, 11, 11, 12, 13, 13, 14);
src[4] = Mat_<uint8_t>({3, 5}, {
0, 1, 2, 3, 4,
5, 6, 7, 8, 9,
10, 11, 12, 13, 14
});
dst[4] = Mat_<uint8_t>({5, 7}, {
0, 1, 1, 2, 3, 3, 4,
0, 1, 1, 2, 3, 3, 4,
5, 6, 6, 7, 8, 8, 9,
10, 11, 11, 12, 13, 13, 14,
10, 11, 11, 12, 13, 13, 14
});
src[5] = (Mat_<uint8_t>(2, 3) <<
0, 1, 2,
3, 4, 5);
dst[5] = (Mat_<uint8_t>(4, 6) <<
0, 0, 1, 1, 2, 2,
0, 0, 1, 1, 2, 2,
3, 3, 4, 4, 5, 5,
3, 3, 4, 4, 5, 5);
src[5] = Mat_<uint8_t>({2, 3}, {
0, 1, 2,
3, 4, 5
});
dst[5] = Mat_<uint8_t>({4, 6}, {
0, 0, 1, 1, 2, 2,
0, 0, 1, 1, 2, 2,
3, 3, 4, 4, 5, 5,
3, 3, 4, 4, 5, 5
});
for (int i = 0; i < 6; i++)
{
@@ -5,12 +5,13 @@ namespace opencv_test { namespace {
TEST(MorphShapes, getStructuringElementDiamond)
{
cv::Mat element = cv::getStructuringElement(cv::MORPH_DIAMOND, cv::Size(5,5));
cv::Mat expected = (cv::Mat_<uchar>(5,5) <<
0,0,1,0,0,
0,1,1,1,0,
1,1,1,1,1,
0,1,1,1,0,
0,0,1,0,0);
cv::Mat expected = cv::Mat_<uchar>({5, 5}, {
0,0,1,0,0,
0,1,1,1,0,
1,1,1,1,1,
0,1,1,1,0,
0,0,1,0,0
});
EXPECT_EQ(0, cvtest::norm(element, expected, cv::NORM_INF));
}
+2 -2
View File
@@ -2004,14 +2004,14 @@ bool Chessboard::Board::estimatePoint(const cv::Point2f &p0,const cv::Point2f &p
// use 1D homography to find fith point minimizing square error
if(p0 == p1 || p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3 || p2 == p3 )
return false;
static const cv::Mat src = (cv::Mat_<double>(1,4) << 0,10,20,30);
static const cv::Mat src = cv::Mat_<double>({1, 4}, {0,10,20,30});
cv::Point2f p01 = p1-p0;
cv::Point2f p02 = p2-p0;
cv::Point2f p03 = p3-p0;
float a = float(cv::norm(p01));
float b = float(cv::norm(p02));
float c = float(cv::norm(p03));
cv::Mat dst = (cv::Mat_<double>(1,4) << 0,a,b,c);
cv::Mat dst = cv::Mat_<double>({1, 4}, {0,a,b,c});
cv::Mat h = findHomography1D(src,dst);
float d = float((h.at<double>(0,0)*40+h.at<double>(0,1))/(h.at<double>(1,0)*40+h.at<double>(1,1)));
cv::Point2f p12 = p2-p1;
+4 -4
View File
@@ -113,7 +113,7 @@ private:
for (int i = 0; i < 5; i++)
A11 += dst_demean[i][1] * src_demean[i][1];
A11 = A11 / 5;
Mat A = (Mat_<double>(2, 2) << A00, A01, A10, A11);
Mat A = Mat_<double>({2, 2}, {A00, A01, A10, A11});
double d[2] = { 1.0, 1.0 };
double detA = A00 * A11 - A01 * A10;
if (detA < 0)
@@ -146,7 +146,7 @@ private:
{
double temp = d[1];
d[1] = -1;
Mat D = (Mat_<double>(2, 2) << d[0], 0.0, 0.0, d[1]);
Mat D = Mat_<double>({2, 2}, {d[0], 0.0, 0.0, d[1]});
Mat Dvt = D*vt;
Mat uDvt = u*Dvt;
T[0][0] = uDvt.ptr<double>(0)[0];
@@ -158,7 +158,7 @@ private:
}
else
{
Mat D = (Mat_<double>(2, 2) << d[0], 0.0, 0.0, d[1]);
Mat D = Mat_<double>({2, 2}, {d[0], 0.0, 0.0, d[1]});
Mat Dvt = D*vt;
Mat uDvt = u*Dvt;
T[0][0] = uDvt.ptr<double>(0)[0];
@@ -184,7 +184,7 @@ private:
T[0][1] *= scale;
T[1][0] *= scale;
T[1][1] *= scale;
Mat transform_mat = (Mat_<double>(2, 3) << T[0][0], T[0][1], T[0][2], T[1][0], T[1][1], T[1][2]);
Mat transform_mat = Mat_<double>({2, 3}, {T[0][0], T[0][1], T[0][2], T[1][0], T[1][1], T[1][2]});
return transform_mat;
}
private:
+2 -2
View File
@@ -898,8 +898,8 @@ void QRCodeEncoderImpl::findAutoMaskType()
}
}
Mat penalty_pattern[2];
penalty_pattern[0] = (Mat_<uint8_t >(1, 11) << 255, 255, 255, 255, 0, 255, 0, 0, 0, 255, 0);
penalty_pattern[1] = (Mat_<uint8_t >(1, 11) << 0, 255, 0, 0, 0, 255, 0, 255, 255, 255, 255);
penalty_pattern[0] = Mat_<uint8_t >({1, 11}, {255, 255, 255, 255, 0, 255, 0, 0, 0, 255, 0});
penalty_pattern[1] = Mat_<uint8_t >({1, 11}, {0, 255, 0, 0, 0, 255, 0, 255, 255, 255, 255});
for (int direction = 0; direction < 2; direction++)
{
if (direction != 0)
@@ -596,25 +596,26 @@ TEST(Charuco, testCharucoCornersCollinear_false)
TEST(Charuco, testBoardSubpixelCoords)
{
cv::Size res{500, 500};
cv::Mat K = (cv::Mat_<double>(3,3) <<
0.5*res.width, 0, 0.5*res.width,
0, 0.5*res.height, 0.5*res.height,
0, 0, 1);
cv::Mat K = cv::Mat_<double>({3, 3}, {
0.5*res.width, 0, 0.5*res.width,
0, 0.5*res.height, 0.5*res.height,
0, 0, 1
});
// set expected_corners values
// Note: Values adjusted by -0.5px after fixing the systematic offset bug in charuco_detector.cpp
// The fix removes the incorrect +0.5 offset that was added after cornerSubPix
cv::Mat expected_corners = (cv::Mat_<float>(9,2) <<
199.5, 199.5,
249.5, 199.5,
299.5, 199.5,
199.5, 249.5,
249.5, 249.5,
299.5, 249.5,
199.5, 299.5,
249.5, 299.5,
299.5, 299.5
);
cv::Mat expected_corners = cv::Mat_<float>({9, 2}, {
199.5, 199.5,
249.5, 199.5,
299.5, 199.5,
199.5, 249.5,
249.5, 249.5,
299.5, 249.5,
199.5, 299.5,
249.5, 299.5,
299.5, 299.5
});
std::vector<int> shape={expected_corners.rows};
expected_corners = expected_corners.reshape(2, shape);
@@ -848,16 +849,18 @@ TEST_P(CharucoBoardGenerate, issue_24806)
// chessboard corner 1:
// B W
// W B
Mat goldCorner1 = (Mat_<uint8_t>(2, 2) <<
0, 255,
255, 0);
Mat goldCorner1 = Mat_<uint8_t>({2, 2}, {
0, 255,
255, 0
});
// B - black pixel, W - white pixel
// chessboard corner 2:
// W B
// B W
Mat goldCorner2 = (Mat_<uint8_t>(2, 2) <<
255, 0,
0, 255);
Mat goldCorner2 = Mat_<uint8_t>({2, 2}, {
255, 0,
0, 255
});
// test chessboard corners in generated image
for (const Point3f& p: board.getChessboardCorners()) {
@@ -920,24 +923,25 @@ TEST_P(CharucoBoardGenerate, issue_24806)
TEST(Charuco, testSeveralBoardsWithCustomIds)
{
Size res{500, 500};
Mat K = (Mat_<double>(3,3) <<
0.5*res.width, 0, 0.5*res.width,
0, 0.5*res.height, 0.5*res.height,
0, 0, 1);
Mat K = Mat_<double>({3, 3}, {
0.5*res.width, 0, 0.5*res.width,
0, 0.5*res.height, 0.5*res.height,
0, 0, 1
});
// Expected corner coordinates adjusted by -0.5px after fixing the systematic offset bug
// The fix removes the incorrect +0.5 offset that was added after cornerSubPix
Mat expected_corners = (Mat_<float>(9,2) <<
199.5, 199.5,
249.5, 199.5,
299.5, 199.5,
199.5, 249.5,
249.5, 249.5,
299.5, 249.5,
199.5, 299.5,
249.5, 299.5,
299.5, 299.5
);
Mat expected_corners = Mat_<float>({9, 2}, {
199.5, 199.5,
249.5, 199.5,
299.5, 199.5,
199.5, 249.5,
249.5, 249.5,
299.5, 249.5,
199.5, 299.5,
249.5, 299.5,
299.5, 299.5
});
aruco::Dictionary dict = cv::aruco::getPredefinedDictionary(aruco::DICT_4X4_50);
+5 -8
View File
@@ -452,11 +452,9 @@ bool CV_ChessboardDetectorTest::checkByGenerator()
randu(bg, Scalar::all(0), Scalar::all(255));
GaussianBlur(bg, bg, Size(5, 5), 0.0);
Mat_<float> camMat(3, 3);
camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
Mat_<float> camMat({3, 3}, {300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f});
Mat_<float> distCoeffs(1, 5);
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
Mat_<float> distCoeffs({1, 5}, {1.2f, 0.2f, 0.f, 0.f, 0.f});
const Size sizes[] = { Size(6, 6), Size(8, 6), Size(11, 12), Size(5, 4) };
const size_t sizes_num = sizeof(sizes)/sizeof(sizes[0]);
@@ -527,8 +525,7 @@ bool CV_ChessboardDetectorTest::checkByGenerator()
Point2f c = std::accumulate(cg.begin(), cg.end(), Point2f(), std::plus<Point2f>()) * (1.f/cg.size());
Mat_<double> aff(2, 3);
aff << 1.0, 0.0, -(double)c.x, 0.0, 1.0, 0.0;
Mat_<double> aff({2, 3}, {1.0, 0.0, -(double)c.x, 0.0, 1.0, 0.0});
Mat sh;
warpAffine(cb, sh, aff, cb.size());
@@ -603,7 +600,7 @@ bool CV_ChessboardDetectorTest::checkByGeneratorHighAccuracy()
for(auto &&pt : pts1_all)
{
// calc camera ray
cv::Vec3f ray(float((pt.x-center.x)*fxi),float((pt.y-center.y)*fyi),1.0F);
cv::Vec3f ray(float((pt.x-center.x)*fxi),float((pt.y-(double)center.y)*fyi),1.0F);
ray /= cv::norm(ray);
// intersect ray with virtual plane
@@ -629,7 +626,7 @@ bool CV_ChessboardDetectorTest::checkByGeneratorHighAccuracy()
// project 3d points to new camera
Vec3f rvec(0.0F,0.05F,float(float(i)/180.0*CV_PI));
Vec3f tvec(0,0,0);
cv::Mat k = (cv::Mat_<double>(3,3) << fx/2,0,center.x*2, 0,fy/2,center.y, 0,0,1);
cv::Mat k = cv::Mat_<double>({3, 3}, {fx/2,0,(double)center.x*2, 0,fy/2,(double)center.y, 0,0,1});
cv::projectPoints(pts3d,rvec,tvec,k,cv::Mat(),pts2_all);
// get perspective transform using four correspondences and wrap original image
@@ -77,10 +77,8 @@ protected:
void CV_ChessboardDetectorBadArgTest::run( int /*start_from */)
{
Mat bg(800, 600, CV_8U, Scalar(0));
Mat_<float> camMat(3, 3);
camMat << 300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f;
Mat_<float> distCoeffs(1, 5);
distCoeffs << 1.2f, 0.2f, 0.f, 0.f, 0.f;
Mat_<float> camMat({3, 3}, {300.f, 0.f, bg.cols/2.f, 0, 300.f, bg.rows/2.f, 0.f, 0.f, 1.f});
Mat_<float> distCoeffs({1, 5}, {1.2f, 0.2f, 0.f, 0.f, 0.f});
ChessBoardGenerator cbg(Size(8,6));
vector<Point2f> exp_corn;
@@ -234,8 +234,8 @@ void CV_ChessboardSubpixelTest::generateIntrinsicParams()
double p2 = 0.05*cvtest::randReal(rng);
double k3 = 0.0;
intrinsic_matrix_ = (Mat_<double>(3, 3) << fx, 0.0, cx, 0.0, fy, cy, 0.0, 0.0, 1.0);
distortion_coeffs_ = (Mat_<double>(1, 5) << k1, k2, p1, p2, k3);
intrinsic_matrix_ = Mat_<double>({3, 3}, {fx, 0.0, cx, 0.0, fy, cy, 0.0, 0.0, 1.0});
distortion_coeffs_ = Mat_<double>({1, 5}, {k1, k2, p1, p2, k3});
}
TEST(Calib3d_ChessboardSubPixDetector, accuracy) { CV_ChessboardSubpixelTest test; test.safe_run(); }
+6 -6
View File
@@ -352,10 +352,10 @@ Mat XYZ::cam_(IllumObserver sio, IllumObserver dio, ChromaticAdaptationType meth
* Chromatic adaption matrices.
*/
static const Mat Von_Kries = (Mat_<double>(3, 3) << 0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822);
static const Mat Bradford = (Mat_<double>(3, 3) << 0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296);
static const std::map<ChromaticAdaptationType, std::vector<Mat>> MAs = {
{ IDENTITY, { Mat::eye(Size(3, 3), CV_64FC1), Mat::eye(Size(3, 3), CV_64FC1) } },
static const Matx33d Von_Kries(0.40024, 0.7076, -0.08081, -0.2263, 1.16532, 0.0457, 0., 0., 0.91822);
static const Matx33d Bradford(0.8951, 0.2664, -0.1614, -0.7502, 1.7135, 0.0367, 0.0389, -0.0685, 1.0296);
static const std::map<ChromaticAdaptationType, std::vector<Matx33d>> MAs = {
{ IDENTITY, { Matx33d::eye(), Matx33d::eye() } },
{ VON_KRIES, { Von_Kries, Von_Kries.inv() } },
{ BRADFORD, { Bradford, Bradford.inv() } }
};
@@ -365,8 +365,8 @@ Mat XYZ::cam_(IllumObserver sio, IllumObserver dio, ChromaticAdaptationType meth
Mat XYZWd = Mat(getIlluminants(sio));
XYZws = XYZws.reshape(1, (int)XYZws.total());
XYZWd = XYZWd.reshape(1, (int)XYZWd.total());
Mat MA = MAs.at(method)[0];
Mat MA_inv = MAs.at(method)[1];
Matx33d MA = MAs.at(method)[0];
Matx33d MA_inv = MAs.at(method)[1];
Mat M = MA_inv * Mat::diag((MA * XYZws) / (MA * XYZWd)) * MA;
cams[std::make_tuple(dio, sio, method)] = M;
cams[std::make_tuple(sio, dio, method)] = M.inv();
+125 -114
View File
@@ -9,7 +9,7 @@ namespace opencv_test
namespace
{
Mat s = (Mat_<Vec3d>(24, 1) <<
Mat s = Mat_<Vec3d>({24, 1}, {
Vec3d(214.11, 98.67, 37.97),
Vec3d(231.94, 153.1, 85.27),
Vec3d(204.08, 143.71, 78.46),
@@ -33,128 +33,135 @@ Mat s = (Mat_<Vec3d>(24, 1) <<
Vec3d(236.49, 175.87, 88.86),
Vec3d(212.19, 133.49, 54.79),
Vec3d(181.17, 102.94, 36.18),
Vec3d(115.1, 53.77, 15.23));
Vec3d(115.1, 53.77, 15.23)
});
TEST(Photo_ColorCorrection, test_model)
{
cv::ccm::ColorCorrectionModel model(s / 255, cv::ccm::COLORCHECKER_MACBETH);
Mat colorCorrectionMat = model.compute();
Mat srcRgbl = (Mat_<Vec3d>(24, 1) <<
Vec3d(0.68078957, 0.12382801, 0.01514889),
Vec3d(0.81177942, 0.32550452, 0.089818),
Vec3d(0.61259378, 0.2831933, 0.07478902),
Vec3d(0.52696493, 0.20105976, 0.00958657),
Vec3d(0.80402284, 0.30419523, 0.12989841),
Vec3d(0.78658646, 0.63184111, 0.12062068),
Vec3d(0.78999637, 0.25520249, 0.03462853),
Vec3d(0.51866697, 0.16114393, 0.1078387),
Vec3d(0.74820768, 0.11770076, 0.06862177),
Vec3d(0.59776825, 0.05765816, 0.02886627),
Vec3d(0.8793145, 0.56346033, 0.0403954),
Vec3d(0.84124847, 0.42120746, 0.03287592),
Vec3d(0.23333214, 0.06780408, 0.05612276),
Vec3d(0.5176423, 0.41210976, 0.01896255),
Vec3d(0.73888613, 0.06575388, 0.06181293),
Vec3d(0.88326036, 0.58018751, 0.04321991),
Vec3d(0.75922531, 0.13149072, 0.1282041),
Vec3d(0.4345097, 0.32331019, 0.10494139),
Vec3d(0.94110142, 0.77941419, 0.26946323),
Vec3d(0.88438952, 0.5949049 , 0.17536928),
Vec3d(0.84722687, 0.44160449, 0.09834799),
Vec3d(0.66743106, 0.24076803, 0.03394333),
Vec3d(0.47141286, 0.13592419, 0.01362205),
Vec3d(0.17377101, 0.03256864, 0.00203026));
Mat srcRgbl = Mat_<Vec3d>({24, 1}, {
Vec3d(0.68078957, 0.12382801, 0.01514889),
Vec3d(0.81177942, 0.32550452, 0.089818),
Vec3d(0.61259378, 0.2831933, 0.07478902),
Vec3d(0.52696493, 0.20105976, 0.00958657),
Vec3d(0.80402284, 0.30419523, 0.12989841),
Vec3d(0.78658646, 0.63184111, 0.12062068),
Vec3d(0.78999637, 0.25520249, 0.03462853),
Vec3d(0.51866697, 0.16114393, 0.1078387),
Vec3d(0.74820768, 0.11770076, 0.06862177),
Vec3d(0.59776825, 0.05765816, 0.02886627),
Vec3d(0.8793145, 0.56346033, 0.0403954),
Vec3d(0.84124847, 0.42120746, 0.03287592),
Vec3d(0.23333214, 0.06780408, 0.05612276),
Vec3d(0.5176423, 0.41210976, 0.01896255),
Vec3d(0.73888613, 0.06575388, 0.06181293),
Vec3d(0.88326036, 0.58018751, 0.04321991),
Vec3d(0.75922531, 0.13149072, 0.1282041),
Vec3d(0.4345097, 0.32331019, 0.10494139),
Vec3d(0.94110142, 0.77941419, 0.26946323),
Vec3d(0.88438952, 0.5949049 , 0.17536928),
Vec3d(0.84722687, 0.44160449, 0.09834799),
Vec3d(0.66743106, 0.24076803, 0.03394333),
Vec3d(0.47141286, 0.13592419, 0.01362205),
Vec3d(0.17377101, 0.03256864, 0.00203026)
});
EXPECT_MAT_NEAR(srcRgbl, model.getSrcLinearRGB(), 1e-4);
Mat dstRgbl = (Mat_<Vec3d>(24, 1) <<
Vec3d(0.17303173, 0.08211037, 0.05672686),
Vec3d(0.56832031, 0.29269488, 0.21835529),
Vec3d(0.10365019, 0.19588357, 0.33140475),
Vec3d(0.10159676, 0.14892193, 0.05188294),
Vec3d(0.22159627, 0.21584476, 0.43461196),
Vec3d(0.10806379, 0.51437196, 0.41264213),
Vec3d(0.74736423, 0.20062878, 0.02807988),
Vec3d(0.05757947, 0.10516793, 0.40296109),
Vec3d(0.56676218, 0.08424805, 0.11969461),
Vec3d(0.11099515, 0.04230796, 0.14292554),
Vec3d(0.34546869, 0.50872001, 0.04944204),
Vec3d(0.79461323, 0.35942459, 0.02051968),
Vec3d(0.01710416, 0.05022043, 0.29220674),
Vec3d(0.05598012, 0.30021149, 0.06871162),
Vec3d(0.45585457, 0.03033727, 0.04085654),
Vec3d(0.85737614, 0.56757335, 0.0068503),
Vec3d(0.53348585, 0.08861148, 0.30750446),
Vec3d(-0.0374061, 0.24699498, 0.40041217),
Vec3d(0.91262695, 0.91493909, 0.89367049),
Vec3d(0.57981916, 0.59200418, 0.59328881),
Vec3d(0.35490581, 0.36544831, 0.36755375),
Vec3d(0.19007357, 0.19186587, 0.19308397),
Vec3d(0.08529188, 0.08887994, 0.09257601),
Vec3d(0.0303193, 0.03113818, 0.03274845));
Mat dstRgbl = Mat_<Vec3d>({24, 1}, {
Vec3d(0.17303173, 0.08211037, 0.05672686),
Vec3d(0.56832031, 0.29269488, 0.21835529),
Vec3d(0.10365019, 0.19588357, 0.33140475),
Vec3d(0.10159676, 0.14892193, 0.05188294),
Vec3d(0.22159627, 0.21584476, 0.43461196),
Vec3d(0.10806379, 0.51437196, 0.41264213),
Vec3d(0.74736423, 0.20062878, 0.02807988),
Vec3d(0.05757947, 0.10516793, 0.40296109),
Vec3d(0.56676218, 0.08424805, 0.11969461),
Vec3d(0.11099515, 0.04230796, 0.14292554),
Vec3d(0.34546869, 0.50872001, 0.04944204),
Vec3d(0.79461323, 0.35942459, 0.02051968),
Vec3d(0.01710416, 0.05022043, 0.29220674),
Vec3d(0.05598012, 0.30021149, 0.06871162),
Vec3d(0.45585457, 0.03033727, 0.04085654),
Vec3d(0.85737614, 0.56757335, 0.0068503),
Vec3d(0.53348585, 0.08861148, 0.30750446),
Vec3d(-0.0374061, 0.24699498, 0.40041217),
Vec3d(0.91262695, 0.91493909, 0.89367049),
Vec3d(0.57981916, 0.59200418, 0.59328881),
Vec3d(0.35490581, 0.36544831, 0.36755375),
Vec3d(0.19007357, 0.19186587, 0.19308397),
Vec3d(0.08529188, 0.08887994, 0.09257601),
Vec3d(0.0303193, 0.03113818, 0.03274845)
});
EXPECT_MAT_NEAR(dstRgbl, model.getRefLinearRGB(), 1e-4);
Mat mask = Mat::ones(24, 1, CV_8U);
EXPECT_MAT_NEAR(model.getMask(), mask, 0.0);
Mat refColorMat = (Mat_<double>(3, 3) <<
0.37406520, 0.02066507, 0.05804047,
0.12719672, 0.77389268, -0.01569404,
-0.27627010, 0.00603427, 2.74272981);
Mat refColorMat = Mat_<double>({3, 3}, {
0.37406520, 0.02066507, 0.05804047,
0.12719672, 0.77389268, -0.01569404,
-0.27627010, 0.00603427, 2.74272981
});
EXPECT_MAT_NEAR(colorCorrectionMat, refColorMat, 1e-4);
}
TEST(Photo_ColorCorrection, test_model_with_color_patches_mask)
{
Mat dstData = (Mat_<Vec3d>(24, 1) <<
Vec3d(37.986, 13.555, 14.059),
Vec3d(65.711, 18.13, 17.81),
Vec3d(49.927, -4.88, -21.925),
Vec3d(43.139, -13.095, 21.905),
Vec3d(55.112, 8.843999999999999, -25.399),
Vec3d(70.71899999999999, -33.397, -0.199),
Vec3d(62.661, 36.067, 57.096),
Vec3d(40.02, 10.41, -45.964),
Vec3d(51.124, 48.239, 16.248),
Vec3d(30.325, 22.976, -21.587),
Vec3d(72.532, -23.709, 57.255),
Vec3d(71.941, 19.363, 67.857),
Vec3d(28.778, 14.179, -50.297),
Vec3d(55.261, -38.342, 31.37),
Vec3d(42.101, 53.378, 28.19),
Vec3d(81.733, 4.039, 79.819),
Vec3d(51.935, 49.986, -14.574),
Vec3d(51.038, -28.631, -28.638),
Vec3d(96.539, -0.425, 1.186),
Vec3d(81.25700000000001, -0.638, -0.335),
Vec3d(66.76600000000001, -0.734, -0.504),
Vec3d(50.867, -0.153, -0.27),
Vec3d(35.656, -0.421, -1.231),
Vec3d(20.461, -0.079, -0.973)
);
Mat dstData = Mat_<Vec3d>({24, 1}, {
Vec3d(37.986, 13.555, 14.059),
Vec3d(65.711, 18.13, 17.81),
Vec3d(49.927, -4.88, -21.925),
Vec3d(43.139, -13.095, 21.905),
Vec3d(55.112, 8.843999999999999, -25.399),
Vec3d(70.71899999999999, -33.397, -0.199),
Vec3d(62.661, 36.067, 57.096),
Vec3d(40.02, 10.41, -45.964),
Vec3d(51.124, 48.239, 16.248),
Vec3d(30.325, 22.976, -21.587),
Vec3d(72.532, -23.709, 57.255),
Vec3d(71.941, 19.363, 67.857),
Vec3d(28.778, 14.179, -50.297),
Vec3d(55.261, -38.342, 31.37),
Vec3d(42.101, 53.378, 28.19),
Vec3d(81.733, 4.039, 79.819),
Vec3d(51.935, 49.986, -14.574),
Vec3d(51.038, -28.631, -28.638),
Vec3d(96.539, -0.425, 1.186),
Vec3d(81.25700000000001, -0.638, -0.335),
Vec3d(66.76600000000001, -0.734, -0.504),
Vec3d(50.867, -0.153, -0.27),
Vec3d(35.656, -0.421, -1.231),
Vec3d(20.461, -0.079, -0.973)
});
Mat coloredMask = (Mat_<uchar>(24, 1) <<
1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0);
Mat coloredMask = Mat_<uchar>({24, 1}, {
1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1,
0, 0, 0, 0, 0, 0
});
cv::ccm::ColorCorrectionModel model(s/255, dstData, cv::ccm::COLOR_SPACE_LAB_D50_2, coloredMask);
Mat colorCorrectionMat = model.compute();
Mat refColorMat = (Mat_<double>(3, 3) <<
0.37406520, 0.02066507, 0.05804047,
0.12719672, 0.77389268, -0.01569404,
-0.27627010, 0.00603427, 2.74272981);
Mat refColorMat = Mat_<double>({3, 3}, {
0.37406520, 0.02066507, 0.05804047,
0.12719672, 0.77389268, -0.01569404,
-0.27627010, 0.00603427, 2.74272981
});
EXPECT_MAT_NEAR(colorCorrectionMat, refColorMat, 1e-4);
}
TEST(Photo_ColorCorrection, test_masks_weights_1)
{
Mat weightsList_ = (Mat_<double>(24, 1) <<
1.1, 0, 0, 1.2, 0, 0,
1.3, 0, 0, 1.4, 0, 0,
0.5, 0, 0, 0.6, 0, 0,
0.7, 0, 0, 0.8, 0, 0);
Mat weightsList_ = Mat_<double>({24, 1}, {
1.1, 0, 0, 1.2, 0, 0,
1.3, 0, 0, 1.4, 0, 0,
0.5, 0, 0, 0.6, 0, 0,
0.7, 0, 0, 0.8, 0, 0
});
cv::ccm::ColorCorrectionModel model1(s / 255,cv::ccm::COLORCHECKER_MACBETH);
model1.setColorSpace(cv::ccm::COLOR_SPACE_SRGB);
model1.setCcmType(cv::ccm::CCM_LINEAR);
@@ -166,16 +173,18 @@ TEST(Photo_ColorCorrection, test_masks_weights_1)
model1.setWeightsList(weightsList_);
model1.setWeightCoeff(1.5);
Mat colorCorrectionMat = model1.compute();
Mat weights = (Mat_<double>(8, 1) <<
1.15789474, 1.26315789, 1.36842105, 1.47368421,
0.52631579, 0.63157895, 0.73684211, 0.84210526);
Mat weights = Mat_<double>({8, 1}, {
1.15789474, 1.26315789, 1.36842105, 1.47368421,
0.52631579, 0.63157895, 0.73684211, 0.84210526
});
EXPECT_MAT_NEAR(model1.getWeights(), weights, 1e-4);
Mat mask = (Mat_<uchar>(24, 1) <<
true, false, false, true, false, false,
true, false, false, true, false, false,
true, false, false, true, false, false,
true, false, false, true, false, false);
Mat mask = Mat_<uchar>({24, 1}, {
true, false, false, true, false, false,
true, false, false, true, false, false,
true, false, false, true, false, false,
true, false, false, true, false, false
});
EXPECT_MAT_NEAR(model1.getMask(), mask, 0.0);
}
@@ -191,18 +200,20 @@ TEST(Photo_ColorCorrection, test_masks_weights_2)
model2.setWeightsList(Mat());
model2.setWeightCoeff(1.5);
Mat colorCorrectionMat = model2.compute();
Mat weights = (Mat_<double>(20, 1) <<
0.65554256, 1.49454705, 1.00499244, 0.79735434, 1.16327759,
1.68623868, 1.37973155, 0.73213388, 1.0169629, 0.47430246,
1.70312161, 0.45414218, 1.15910007, 0.7540434, 1.05049802,
1.04551645, 1.54082353, 1.02453421, 0.6015915, 0.26154558);
Mat weights = Mat_<double>({20, 1}, {
0.65554256, 1.49454705, 1.00499244, 0.79735434, 1.16327759,
1.68623868, 1.37973155, 0.73213388, 1.0169629, 0.47430246,
1.70312161, 0.45414218, 1.15910007, 0.7540434, 1.05049802,
1.04551645, 1.54082353, 1.02453421, 0.6015915, 0.26154558
});
EXPECT_MAT_NEAR(model2.getWeights(), weights, 1e-4);
Mat mask = (Mat_<uchar>(24, 1) <<
true, true, true, true, true, true,
true, true, true, true, false, true,
true, true, true, false, true, true,
false, false, true, true, true, true);
Mat mask = Mat_<uchar>({24, 1}, {
true, true, true, true, true, true,
true, true, true, true, false, true,
true, true, true, false, true, true,
false, false, true, true, true, true
});
EXPECT_MAT_NEAR(model2.getMask(), mask, 0.0);
}
+1 -1
View File
@@ -17,7 +17,7 @@ float focal_length = 525;
float cx = W / 2.f + 0.5f;
float cy = H / 2.f + 0.5f;
static Mat K() { static Mat res = (Mat_<double>(3, 3) << focal_length, 0, cx, 0, focal_length, cy, 0, 0, 1); return res; }
static Mat K() { static Mat res = Mat_<double>({3, 3}, {focal_length, 0, cx, 0, focal_length, cy, 0, 0, 1}); return res; }
static Mat Kinv() { static Mat res = K().inv(); return res; }
void points3dToDepth16U(const Mat_<Vec4f>& points3d, Mat& depthMap);
+2 -2
View File
@@ -24,7 +24,7 @@ public:
// Test sentinel value handling, occlusion, and dilation
{
// K from a VGA Kinect
Mat K = (Mat_<float>(3, 3) << 525., 0., 319.5, 0., 525., 239.5, 0., 0., 1.);
Mat K = Mat_<float>({3, 3}, {525., 0., 319.5, 0., 525., 239.5, 0., 0., 1.});
int width = 640, height = 480;
@@ -54,7 +54,7 @@ public:
void noOpRandomRegistrationTest(DepthDepth minDepth, DepthDepth maxDepth)
{
// K from a VGA Kinect
Mat K = (Mat_<float>(3, 3) << 525., 0., 319.5, 0., 525., 239.5, 0., 0., 1.);
Mat K = Mat_<float>({3, 3}, {525., 0., 319.5, 0., 525., 239.5, 0., 0., 1.});
// Create a random depth image
RNG rng;
+14 -10
View File
@@ -29,23 +29,25 @@ PERF_TEST_P(ECCPerfTest, findTransformECC,
double angle;
switch (transform_type) {
case MOTION_TRANSLATION:
warpGround = (Mat_<float>(2, 3) << 1.f, 0.f, 7.234f, 0.f, 1.f, 11.839f);
warpGround = Mat_<float>({2, 3}, {1.f, 0.f, 7.234f, 0.f, 1.f, 11.839f});
warpAffine(img, templateImage, warpGround, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_EUCLIDEAN:
angle = CV_PI / 30;
warpGround = (Mat_<float>(2, 3) << (float)cos(angle), (float)-sin(angle), 12.123f, (float)sin(angle),
(float)cos(angle), 14.789f);
warpGround = Mat_<float>({2, 3}, {
(float)cos(angle), (float)-sin(angle), 12.123f, (float)sin(angle),
(float)cos(angle), 14.789f
});
warpAffine(img, templateImage, warpGround, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_AFFINE:
warpGround = (Mat_<float>(2, 3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f);
warpGround = Mat_<float>({2, 3}, {0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f});
warpAffine(img, templateImage, warpGround, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_HOMOGRAPHY:
warpGround = (Mat_<float>(3, 3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f, 0.0002f, 0.0003f, 1.f);
warpGround = Mat_<float>({3, 3}, {0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f, 0.0002f, 0.0003f, 1.f});
warpPerspective(img, templateImage, warpGround, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
break;
}
@@ -87,22 +89,24 @@ PERF_TEST_P(ECCPerfTestMS, findTransformECCMultiScale,
double angle;
switch (transform_type) {
case MOTION_TRANSLATION:
warpGround = (Mat_<float>(2, 3) << 1.f, 0.f, 7.234f, 0.f, 1.f, 11.839f);
warpGround = Mat_<float>({2, 3}, {1.f, 0.f, 7.234f, 0.f, 1.f, 11.839f});
warpAffine(img, templateImage, warpGround, img.size(), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_EUCLIDEAN:
angle = CV_PI / 30;
warpGround = (Mat_<float>(2, 3) << (float)cos(angle), (float)-sin(angle), 12.123f, (float)sin(angle),
(float)cos(angle), 14.789f);
warpGround = Mat_<float>({2, 3}, {
(float)cos(angle), (float)-sin(angle), 12.123f, (float)sin(angle),
(float)cos(angle), 14.789f
});
warpAffine(img, templateImage, warpGround, img.size(), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_AFFINE:
warpGround = (Mat_<float>(2, 3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f);
warpGround = Mat_<float>({2, 3}, {0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f});
warpAffine(img, templateImage, warpGround, img.size(), INTER_LINEAR + WARP_INVERSE_MAP);
break;
case MOTION_HOMOGRAPHY:
warpGround = (Mat_<float>(3, 3) << 0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f, 0.0002f, 0.0003f, 1.f);
warpGround = Mat_<float>({3, 3}, {0.98f, 0.03f, 15.523f, -0.02f, 0.95f, 10.456f, 0.0002f, 0.0003f, 1.f});
warpPerspective(img, templateImage, warpGround, img.size(), INTER_LINEAR + WARP_INVERSE_MAP);
break;
}
+24 -18
View File
@@ -147,25 +147,31 @@ bool CV_ECC_Test::test(const Mat img)
switch(motionType)
{
case MOTION_TRANSLATION:
groundMap = (Mat_<float>(2, 3) << 1, 0, (rng.uniform(10.f, 20.f)), 0, 1, (rng.uniform(10.f, 20.f)));
groundMap = Mat_<float>({2, 3}, {1, 0, (rng.uniform(10.f, 20.f)), 0, 1, (rng.uniform(10.f, 20.f))});
break;
case MOTION_EUCLIDEAN:
{
double angle = CV_PI / 30 + CV_PI * rng.uniform((double)-2.f, (double)2.f) / 180;
groundMap = (Mat_<float>(2, 3) << cos(angle), -sin(angle), (rng.uniform(10.f, 20.f)), sin(angle),
cos(angle), (rng.uniform(10.f, 20.f)));
groundMap = Mat_<float>({2, 3}, {
(float)cos(angle), (float)-sin(angle), (rng.uniform(10.f, 20.f)), (float)sin(angle),
(float)cos(angle), (rng.uniform(10.f, 20.f))
});
break;
}
case MOTION_AFFINE:
groundMap = (Mat_<float>(2, 3) << (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)));
groundMap = Mat_<float>({2, 3}, {
(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))
});
break;
case MOTION_HOMOGRAPHY:
groundMap =
(Mat_<float>(3, 3) << (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.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f);
Mat_<float>({3, 3}, {
(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.0001f, 0.0003f)), (rng.uniform(0.0001f, 0.0003f)), 1.f
});
break;
default:
CV_Error(Error::StsBadArg, "Incorrect motion type");
@@ -183,7 +189,7 @@ bool CV_ECC_Test::test(const Mat img)
else
{
warpAffine(img, warpedImage, groundMap, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
foundMap = Mat((Mat_<float>(2, 3) << 1, 0, 0, 0, 1, 0));
foundMap = Mat(Mat_<float>({2, 3}, {1, 0, 0, 0, 1, 0}));
}
@@ -277,13 +283,13 @@ bool CV_ECC_Test_Mask::test(const Mat testImg) {
ts->update_context(this, k, true);
progress = update_progress(progress, k, ntests, 0);
Mat translationGround = (Mat_<float>(2, 3) << 1, 0, (rng.uniform(10.f, 20.f)), 0, 1, (rng.uniform(10.f, 20.f)));
Mat translationGround = Mat_<float>({2, 3}, {1, 0, (rng.uniform(10.f, 20.f)), 0, 1, (rng.uniform(10.f, 20.f))});
Mat warpedImage;
warpAffine(testImg, warpedImage, translationGround, Size(200, 200), INTER_LINEAR + WARP_INVERSE_MAP);
Mat mapTranslation = (Mat_<float>(2, 3) << 1, 0, 0, 0, 1, 0);
Mat mapTranslation = Mat_<float>({2, 3}, {1, 0, 0, 0, 1, 0});
Mat_<unsigned char> mask = Mat_<unsigned char>::ones(testImg.rows, testImg.cols);
Rect region(testImg.cols * 2 / 3, testImg.rows * 2 / 3, testImg.cols / 3, testImg.rows / 3);
@@ -348,13 +354,13 @@ void CV_ECC_BigPictureTest::run(int)
roiMask0 = imread(string(ts->get_data_path()) + "shared/halmosh0mask.png", IMREAD_GRAYSCALE);
roiMask1 = imread(string(ts->get_data_path()) + "shared/halmosh2mask.png", IMREAD_GRAYSCALE);
readError = largeGray0.empty() || largeGray1.empty() || roiMask0.empty() || roiMask1.empty();
expectedRes = (Mat_<float>(3, 3) << 1.0225, 0.0606, -28.6452, -0.0475, 1.0314, 11.819, 8.21e-06, -3.65e-07, 1);
Mat_<double>({3, 3}, {1.0225, 0.0606, -28.6452, -0.0475, 1.0314, 11.819, 8.21e-06, -3.65e-07, 1}).convertTo(expectedRes, CV_32F);
}
else
{
largeGray1 = imread(string(ts->get_data_path()) + "shared/halmosh1.jpg", IMREAD_GRAYSCALE);
readError = largeGray0.empty() || largeGray1.empty();
expectedRes = (Mat_<float>(3, 3) << 0.9756, -0.0319, 24.685, 0.013, 0.9808, 7.7453, -2.35e-05, -9.12e-06, 1);
Mat_<double>({3, 3}, {0.9756, -0.0319, 24.685, 0.013, 0.9808, 7.7453, -2.35e-05, -9.12e-06, 1}).convertTo(expectedRes, CV_32F);
}
if(readError)
@@ -441,8 +447,8 @@ TEST(Video_ECC_Test_Compute, properties) {
}
TEST(Video_ECC_Test_Compute, accuracy) {
Mat testImg = (Mat_<float>(3, 3) << 1, 0, 0, 1, 0, 0, 1, 0, 0);
Mat warpedImage = (Mat_<float>(3, 3) << 0, 1, 0, 0, 1, 0, 0, 1, 0);
Mat testImg = Mat_<float>({3, 3}, {1, 0, 0, 1, 0, 0, 1, 0, 0});
Mat warpedImage = Mat_<float>({3, 3}, {0, 1, 0, 0, 1, 0, 0, 1, 0});
Mat_<unsigned char> mask = Mat_<unsigned char>::ones(testImg.rows, testImg.cols);
double ecc = computeECC(warpedImage, testImg, mask);
@@ -455,7 +461,7 @@ TEST(Video_ECC_Test_Compute, bug_14657) {
* it results in 1, 1, 1, 0 for the unsigned int case - compare to 1, 1, 1, -3 in the signed case.
* For this reason, when the same matrix was provided as the input and the template, we didn't get 1 as expected.
*/
Mat img = (Mat_<uint8_t>(2, 2) << 10, 10, 10, 6);
Mat img = Mat_<uint8_t>({2, 2}, {10, 10, 10, 6});
EXPECT_NEAR(computeECC(img, img), 1.0f, 1e-5f);
}
@@ -480,7 +486,7 @@ TEST(Video_ECC_BoolMask, matches_uchar_mask) {
templateImage(Rect(j * 8, i * 8, 8, 8)) = 200;
GaussianBlur(templateImage, templateImage, Size(5, 5), 0);
Mat shift = (Mat_<float>(2, 3) << 1, 0, 2, 0, 1, 1);
Mat shift = Mat_<float>({2, 3}, {1, 0, 2, 0, 1, 1});
Mat inputImage;
warpAffine(templateImage, inputImage, shift, templateImage.size());
@@ -285,18 +285,18 @@ int main(int argc, char *argv[])
*/
/*
kernel = (Mat_<double>(5, 5) << 1, 1, 1, 1, 1,
kernel = Mat_<double>({5, 5}, { 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 });
kernel /= 100;
*/
/*
kernel = (Mat_<double>(3, 3) << 1, 1, 1,
kernel = Mat_<double>({3, 3}, { 1, 1, 1,
0, 0, 0,
-1, -1, -1);
-1, -1, -1 });
*/