mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
merged 2.4 into trunk
This commit is contained in:
@@ -1186,8 +1186,12 @@ struct CountNonZeroOp : public BaseElemWiseOp
|
||||
|
||||
struct MeanStdDevOp : public BaseElemWiseOp
|
||||
{
|
||||
Scalar sqmeanRef;
|
||||
int cn;
|
||||
|
||||
MeanStdDevOp() : BaseElemWiseOp(1, FIX_ALPHA+FIX_BETA+FIX_GAMMA+SUPPORT_MASK+SCALAR_OUTPUT, 1, 1, Scalar::all(0))
|
||||
{
|
||||
cn = 0;
|
||||
context = 7;
|
||||
};
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat& mask)
|
||||
@@ -1202,6 +1206,9 @@ struct MeanStdDevOp : public BaseElemWiseOp
|
||||
cvtest::multiply(temp, temp, temp);
|
||||
Scalar mean = cvtest::mean(src[0], mask);
|
||||
Scalar sqmean = cvtest::mean(temp, mask);
|
||||
|
||||
sqmeanRef = sqmean;
|
||||
cn = temp.channels();
|
||||
|
||||
for( int c = 0; c < 4; c++ )
|
||||
sqmean[c] = std::sqrt(std::max(sqmean[c] - mean[c]*mean[c], 0.));
|
||||
@@ -1212,7 +1219,11 @@ struct MeanStdDevOp : public BaseElemWiseOp
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
return 1e-6;
|
||||
CV_Assert(cn > 0);
|
||||
double err = sqmeanRef[0];
|
||||
for(int i = 1; i < cn; ++i)
|
||||
err = std::max(err, sqmeanRef[i]);
|
||||
return 3e-7 * err;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1226,7 +1237,20 @@ struct NormOp : public BaseElemWiseOp
|
||||
};
|
||||
int getRandomType(RNG& rng)
|
||||
{
|
||||
return cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 4);
|
||||
int type = cvtest::randomType(rng, DEPTH_MASK_ALL_BUT_8S, 1, 4);
|
||||
for(;;)
|
||||
{
|
||||
normType = rng.uniform(1, 8);
|
||||
if( normType == NORM_INF || normType == NORM_L1 ||
|
||||
normType == NORM_L2 || normType == NORM_L2SQR ||
|
||||
normType == NORM_HAMMING || normType == NORM_HAMMING2 )
|
||||
break;
|
||||
}
|
||||
if( normType == NORM_HAMMING || normType == NORM_HAMMING2 )
|
||||
{
|
||||
type = CV_8U;
|
||||
}
|
||||
return type;
|
||||
}
|
||||
void op(const vector<Mat>& src, Mat& dst, const Mat& mask)
|
||||
{
|
||||
@@ -1242,7 +1266,6 @@ struct NormOp : public BaseElemWiseOp
|
||||
}
|
||||
void generateScalars(int, RNG& rng)
|
||||
{
|
||||
normType = 1 << rng.uniform(0, 3);
|
||||
}
|
||||
double getMaxErr(int)
|
||||
{
|
||||
|
||||
@@ -79,10 +79,12 @@ protected:
|
||||
bool check_full(int type); // compex test for symmetric matrix
|
||||
virtual void run (int) = 0; // main testing method
|
||||
|
||||
private:
|
||||
protected:
|
||||
|
||||
float eps_val_32, eps_vec_32;
|
||||
float eps_val_64, eps_vec_64;
|
||||
int ntests;
|
||||
|
||||
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index = -1, int high_index = -1);
|
||||
bool check_pair_count(const cv::Mat& src, const cv::Mat& evalues, const cv::Mat& evectors, int low_index = -1, int high_index = -1);
|
||||
bool check_pairs_order(const cv::Mat& eigen_values); // checking order of eigen values & vectors (it should be none up)
|
||||
@@ -140,8 +142,7 @@ Core_EigenTest_Scalar_64::~Core_EigenTest_Scalar_64() {}
|
||||
|
||||
void Core_EigenTest_Scalar_32::run(int)
|
||||
{
|
||||
const size_t MATRIX_COUNT = 500;
|
||||
for (size_t i = 0; i < MATRIX_COUNT; ++i)
|
||||
for (int i = 0; i < ntests; ++i)
|
||||
{
|
||||
float value = cv::randu<float>();
|
||||
cv::Mat src(1, 1, CV_32FC1, Scalar::all((float)value));
|
||||
@@ -151,8 +152,7 @@ void Core_EigenTest_Scalar_32::run(int)
|
||||
|
||||
void Core_EigenTest_Scalar_64::run(int)
|
||||
{
|
||||
const size_t MATRIX_COUNT = 500;
|
||||
for (size_t i = 0; i < MATRIX_COUNT; ++i)
|
||||
for (int i = 0; i < ntests; ++i)
|
||||
{
|
||||
float value = cv::randu<float>();
|
||||
cv::Mat src(1, 1, CV_64FC1, Scalar::all((double)value));
|
||||
@@ -163,7 +163,9 @@ void Core_EigenTest_Scalar_64::run(int)
|
||||
void Core_EigenTest_32::run(int) { check_full(CV_32FC1); }
|
||||
void Core_EigenTest_64::run(int) { check_full(CV_64FC1); }
|
||||
|
||||
Core_EigenTest::Core_EigenTest() : eps_val_32(1e-3f), eps_vec_32(1e-2f), eps_val_64(1e-4f), eps_vec_64(1e-3f) {}
|
||||
Core_EigenTest::Core_EigenTest()
|
||||
: eps_val_32(1e-3f), eps_vec_32(1e-2f),
|
||||
eps_val_64(1e-4f), eps_vec_64(1e-3f), ntests(100) {}
|
||||
Core_EigenTest::~Core_EigenTest() {}
|
||||
|
||||
bool Core_EigenTest::check_pair_count(const cv::Mat& src, const cv::Mat& evalues, int low_index, int high_index)
|
||||
@@ -382,14 +384,13 @@ bool Core_EigenTest::test_values(const cv::Mat& src)
|
||||
|
||||
bool Core_EigenTest::check_full(int type)
|
||||
{
|
||||
const int MATRIX_COUNT = 500;
|
||||
const int MAX_DEGREE = 7;
|
||||
|
||||
srand((unsigned int)time(0));
|
||||
|
||||
for (int i = 1; i <= MATRIX_COUNT; ++i)
|
||||
for (int i = 0; i < ntests; ++i)
|
||||
{
|
||||
int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE+1)*1.0));
|
||||
int src_size = (int)(std::pow(2.0, (rand()%MAX_DEGREE)+1.));
|
||||
|
||||
cv::Mat src(src_size, src_size, type);
|
||||
|
||||
|
||||
@@ -1802,6 +1802,7 @@ Core_MatrixTest( 1, 4, false, false, 1 ),
|
||||
flags(0), have_u(false), have_v(false), symmetric(false), compact(false), vector_w(false)
|
||||
{
|
||||
test_case_count = 100;
|
||||
max_log_array_size = 8;
|
||||
test_array[TEMP].push_back(NULL);
|
||||
test_array[TEMP].push_back(NULL);
|
||||
test_array[TEMP].push_back(NULL);
|
||||
|
||||
@@ -74,11 +74,17 @@ protected:
|
||||
bool TestSparseMat();
|
||||
bool TestVec();
|
||||
bool TestMatxMultiplication();
|
||||
bool TestSubMatAccess();
|
||||
bool operations1();
|
||||
|
||||
void checkDiff(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) != 0) throw test_excep(s); }
|
||||
void checkDiffF(const Mat& m1, const Mat& m2, const string& s) { if (norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s); }
|
||||
|
||||
void checkDiff(const Mat& m1, const Mat& m2, const string& s)
|
||||
{
|
||||
if (norm(m1, m2, NORM_INF) != 0) throw test_excep(s);
|
||||
}
|
||||
void checkDiffF(const Mat& m1, const Mat& m2, const string& s)
|
||||
{
|
||||
if (norm(m1, m2, NORM_INF) > 1e-5) throw test_excep(s);
|
||||
}
|
||||
};
|
||||
|
||||
CV_OperationsTest::CV_OperationsTest()
|
||||
@@ -438,6 +444,41 @@ bool CV_OperationsTest::SomeMatFunctions()
|
||||
}
|
||||
|
||||
|
||||
bool CV_OperationsTest::TestSubMatAccess()
|
||||
{
|
||||
try
|
||||
{
|
||||
Mat_<float> T_bs(4,4);
|
||||
Vec3f cdir(1.f, 1.f, 0.f);
|
||||
Vec3f ydir(1.f, 0.f, 1.f);
|
||||
Vec3f fpt(0.1f, 0.7f, 0.2f);
|
||||
T_bs.setTo(0);
|
||||
T_bs(Range(0,3),Range(2,3)) = 1.0*Mat(cdir); // wierd OpenCV stuff, need to do multiply
|
||||
T_bs(Range(0,3),Range(1,2)) = 1.0*Mat(ydir);
|
||||
T_bs(Range(0,3),Range(0,1)) = 1.0*Mat(cdir.cross(ydir));
|
||||
T_bs(Range(0,3),Range(3,4)) = 1.0*Mat(fpt);
|
||||
T_bs(3,3) = 1.0;
|
||||
//std::cout << "[Nav Grok] S frame =" << std::endl << T_bs << std::endl;
|
||||
|
||||
// set up display coords, really just the S frame
|
||||
std::vector<float>coords;
|
||||
|
||||
for (int i=0; i<16; i++)
|
||||
{
|
||||
coords.push_back(T_bs(i));
|
||||
//std::cout << T_bs1(i) << std::endl;
|
||||
}
|
||||
CV_Assert( norm(coords, T_bs.reshape(1,1), NORM_INF) == 0 );
|
||||
}
|
||||
catch (const test_excep& e)
|
||||
{
|
||||
ts->printf(cvtest::TS::LOG, "%s\n", e.s.c_str());
|
||||
ts->set_failed_test_info(cvtest::TS::FAIL_MISMATCH);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CV_OperationsTest::TestTemplateMat()
|
||||
{
|
||||
try
|
||||
@@ -754,12 +795,35 @@ bool CV_OperationsTest::TestMatxMultiplication()
|
||||
{
|
||||
try
|
||||
{
|
||||
Matx33f mat(1, 0, 0, 0, 1, 0, 0, 0, 1); // Identity matrix
|
||||
Matx33f mat(1, 1, 1, 0, 1, 1, 0, 0, 1); // Identity matrix
|
||||
Point2f pt(3, 4);
|
||||
Point3f res = mat * pt; // Correctly assumes homogeneous coordinates
|
||||
if(res.x != 3.0) throw test_excep();
|
||||
if(res.y != 4.0) throw test_excep();
|
||||
if(res.z != 1.0) throw test_excep();
|
||||
|
||||
Vec3f res2 = mat*Vec3f(res.x, res.y, res.z);
|
||||
|
||||
if(res.x != 8.0) throw test_excep();
|
||||
if(res.y != 5.0) throw test_excep();
|
||||
if(res.z != 1.0) throw test_excep();
|
||||
|
||||
if(res2[0] != 14.0) throw test_excep();
|
||||
if(res2[1] != 6.0) throw test_excep();
|
||||
if(res2[2] != 1.0) throw test_excep();
|
||||
|
||||
Matx44f mat44f(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1);
|
||||
Matx44d mat44d(1, 1, 1, 1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 0, 0, 1);
|
||||
Scalar s(4, 3, 2, 1);
|
||||
Scalar sf = mat44f*s;
|
||||
Scalar sd = mat44d*s;
|
||||
|
||||
if(sf[0] != 10.0) throw test_excep();
|
||||
if(sf[1] != 6.0) throw test_excep();
|
||||
if(sf[2] != 3.0) throw test_excep();
|
||||
if(sf[3] != 1.0) throw test_excep();
|
||||
|
||||
if(sd[0] != 10.0) throw test_excep();
|
||||
if(sd[1] != 6.0) throw test_excep();
|
||||
if(sd[2] != 3.0) throw test_excep();
|
||||
if(sd[3] != 1.0) throw test_excep();
|
||||
}
|
||||
catch(const test_excep&)
|
||||
{
|
||||
@@ -877,6 +941,9 @@ void CV_OperationsTest::run( int /* start_from */)
|
||||
|
||||
if (!TestMatxMultiplication())
|
||||
return;
|
||||
|
||||
if (!TestSubMatAccess())
|
||||
return;
|
||||
|
||||
if (!operations1())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user