TEST(MathLib, GlobalDenseMatrix)
{
	const std::size_t n_rows(5);
	const std::size_t n_cols(5);
	MathLib::GlobalDenseMatrix<double, std::size_t> mat0(n_rows,n_cols);
	MathLib::GlobalDenseMatrix<double, std::size_t> mat1(n_rows,n_cols);
	MathLib::GlobalDenseMatrix<double, std::size_t> mat2(n_rows,n_cols-1);

	for (std::size_t i(0); i<n_rows; i++) {
		for (std::size_t j(0); j<n_cols; j++) {
			mat0(i,j) = 1.0 / (i+1.0+j+1.0);
		}
	}

	mat1.setZero();
	mat1 = mat0;
	for (std::size_t i(0); i<n_rows; i++) {
		for (std::size_t j(0); j<n_cols; j++) {
			ASSERT_NEAR(1.0/(i+j+2.0), mat1(i,j), std::numeric_limits<double>::epsilon());
		}
	}

	ASSERT_THROW(mat2 = mat1, std::range_error);

}
Beispiel #2
0
int main() {
  // Defines two 10x10 matrices of type long double
  // The first has elements set to 1
  // The second has elements set to 2
  Matrix<long double> mat1(10, 10, 1.0);
  Matrix<long double> mat2(10, 10, 4.0);

  mat1(3,4) = 10.0;
  mat2(1,2) = -15.0;

  // a third matrix is product of the first two

   Matrix<long double> mat3 = mat1 -mat2 ;
  save(mat3, "test.csv");

  // Print the third matrix 
  for (int i=0; i<mat3.get_rows(); i++) {
    for (int j=0; j<mat3.get_cols(); j++) {
      std::cout << mat3(i,j) << ", ";
    }
    std::cout << std::endl;
  }

  return 0;
}
Beispiel #3
0
void
TestMatrix::runSubTest7(double& res, double& expected, std::string& subTestName)
{
    Math::Matrix<double> mat(2, 3, 5), mat1(3, 4, 7);

    Math::Matrix<double> mat2 = mat * mat1;

    res = mat2(1, 3);
    expected = mat(0, 0) * mat1(0, 0) * mat.cols();
    subTestName = "simple_multiply";
}
Beispiel #4
0
void
TestMatrix::runSubTest17(double& res, double& expected, std::string& subTestName)
{
    Math::SymmetricMatrix<double> mat(3, 3, 5), mat1(3, 3, 7);

    Math::Matrix<double> mat2 = mat * mat1;

    res = mat2(1, 2);
    expected = mat(0, 1) * mat1(2, 0) * mat.rows();
    subTestName = "simple_symmetric_multiply";
}
void
ColumnMajorMatrixTest::equalMatrix()
{
  ColumnMajorMatrix mat(1, 1);
  ColumnMajorMatrix mat1(1, 1);

  mat(0, 0) = 2;
  mat1(0, 0) = 2;

  CPPUNIT_ASSERT( !(*a == *t) );
  CPPUNIT_ASSERT( mat == mat1 );
}
void
ColumnMajorMatrixTest::notEqualMatrix()
{
  ColumnMajorMatrix mat(1, 1);
  ColumnMajorMatrix mat1(1, 1);

  mat(0, 0) = 2;
  mat1(0, 0) = 2;

  CPPUNIT_ASSERT( *a != *t );
  CPPUNIT_ASSERT( !(mat != mat1) );
}
Beispiel #7
0
void
TestMatrix::runSubTest5(double& res, double& expected, std::string& subTestName)
{
    Math::Matrix<int> mat(2, 3), mat1(2, 3);

    mat(0, 1) = -7;
    mat1(0, 1) = 5;

    Math::Matrix<int> mat2 = mat;
    mat2 -= mat1;

    res = mat2(0, 1);
    expected = mat(0, 1) - mat1(0, 1);
    subTestName = "simple_subtract";
}
Beispiel #8
0
void
TestMatrix::runSubTest15(double& res, double& expected, std::string& subTestName)
{
    Math::SymmetricMatrix<int> mat(2, 2, 10), mat1(2, 2, -20);

    mat(0, 1) = -7;
    mat1(0, 1) = 5;

    Math::SymmetricMatrix<int> mat2 = mat;
    mat2 -= mat1;

    res = mat2(0, 1);
    expected = mat(1, 0) - mat1(0, 1);
    subTestName = "simple_symmetric_subtract";
}
int test_cvtColor_RGB2RGB()
{
	cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);
	if (!mat.data) {
		std::cout << "read image fail" << std::endl;
		return -1;
	}

	int width = mat.cols;
	int height = mat.rows;

	// uchar
	fbc::Mat3BGR mat1(height, width, mat.data);
	fbc::Mat3BGR mat2(mat1);
	fbc::Mat_<uchar, 4> mat3(height, width);
	fbc::cvtColor(mat2, mat3, fbc::CV_BGR2BGRA);

	cv::Mat mat1_(height, width, CV_8UC3, mat.data);
	cv::Mat mat2_;
	mat1_.copyTo(mat2_);
	cv::Mat mat3_(height, width, CV_8UC4);
	cv::cvtColor(mat2_, mat3_, CV_BGR2BGRA);

	assert(mat3.step == mat3_.step);
	for (int y = 0; y < mat3.rows; y++) {
		const fbc::uchar* p = mat3.ptr(y);
		const uchar* p_ = mat3_.ptr(y);

		for (int x = 0; x < mat3.step; x++) {
			assert(p[x] == p_[x]);
		}
	}

	// float
	cv::Mat matf;
	mat.convertTo(matf, CV_32FC3);

	fbc::Mat_<float, 3> mat4(height, width, matf.data);
	fbc::Mat_<float, 3> mat5(mat4);
	fbc::Mat_<float, 4> mat6(height, width);
	fbc::cvtColor(mat5, mat6, fbc::CV_BGR2BGRA);

	cv::Mat mat4_(height, width, CV_32FC3, matf.data);
	cv::Mat mat5_;
	mat4_.copyTo(mat5_);
	cv::Mat mat6_(height, width, CV_32FC4);
	cv::cvtColor(mat5_, mat6_, CV_BGR2BGRA);

	assert(mat6.step == mat6_.step);
	for (int y = 0; y < mat6.rows; y++) {
		const fbc::uchar* p = mat6.ptr(y);
		const uchar* p_ = mat6_.ptr(y);

		for (int x = 0; x < mat6.step; x++) {
			assert(p[x] == p_[x]);
		}
	}

	return 0;
}
void test_eigen2_product_large()
{
  for(int i = 0; i < g_repeat; i++) {
    CALL_SUBTEST_1( product(MatrixXf(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST_2( product(MatrixXd(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST_3( product(MatrixXi(ei_random<int>(1,320), ei_random<int>(1,320))) );
    CALL_SUBTEST_4( product(MatrixXcf(ei_random<int>(1,50), ei_random<int>(1,50))) );
    CALL_SUBTEST_5( product(Matrix<float,Dynamic,Dynamic,RowMajor>(ei_random<int>(1,320), ei_random<int>(1,320))) );
  }

#ifdef EIGEN_TEST_PART_6
  {
    // test a specific issue in DiagonalProduct
    int N = 1000000;
    VectorXf v = VectorXf::Ones(N);
    MatrixXf m = MatrixXf::Ones(N,3);
    m = (v+v).asDiagonal() * m;
    VERIFY_IS_APPROX(m, MatrixXf::Constant(N,3,2));
  }

  {
    // test deferred resizing in Matrix::operator=
    MatrixXf a = MatrixXf::Random(10,4), b = MatrixXf::Random(4,10), c = a;
    VERIFY_IS_APPROX((a = a * b), (c * b).eval());
  }

  {
    MatrixXf mat1(10,10); mat1.setRandom();
    MatrixXf mat2(32,10); mat2.setRandom();
    MatrixXf result = mat1.row(2)*mat2.transpose();
    VERIFY_IS_APPROX(result, (mat1.row(2)*mat2.transpose()).eval());
  }
#endif
}
Beispiel #11
0
void
TestMatrix::runSubTest14(double& res, double& expected, std::string& subTestName)
{
    Math::SymmetricMatrix<int> mat(2, 2, 5), mat1(2, 2, 3);

    mat(0, 1) = -7;
    mat1(1, 0) = 5;

    //Math::SymmetricMatrix<int> mat2 = mat + mat1;
    Math::SymmetricMatrix<int> mat2;
    Math::SymmetricMatrix<int>::addMatrices(mat, mat1, &mat2);

    res = mat2(1, 0);
    expected = mat(1, 0) + mat1(0, 1);
    subTestName = "simple_symmetric_add";
}
Matrix<double> BspCurvBasisFuncSet::CreateMatrixIntegral(int lev) const
{

	KnotSet kset = KnotSet(*kts,ord,num).CreateKnotSetDeriv(lev);
	
	Matrix<double> mat(kset.GetNum()-(ord-lev),kset.GetNum()-(ord-lev));
	
	BspCurvBasisFuncSet basis(kset.GetKnots(),ord-lev,kset.GetNum());

	Matrix<double> mat1(kset.GetNum()-ord+lev,kset.GetNum()-ord+lev,0.0);
	for (int i=0; i<kset.GetNum()-ord+lev; i++)
		for (int j=0; j<=i; j++) {
			// create the two std::sets representing the two knot std::sets
			
			Vector<double> temp1((*(basis.b))[i].GetKnots());
			Vector<double> temp2((*(basis.b))[j].GetKnots());
			std::set<double> s1(temp1.begin(),temp1.end());
			std::set<double> s2(temp2.begin(),temp2.end());
			
			// if there is an intersection
			if (*(--s2.end()) > *(s1.begin())) {
				// form the intersection
				std::set<double> s3;
				std::set_intersection(s1.begin(),s1.end(),s2.begin(),s2.end(),std::inserter(s3,s3.begin()));
			
				// if there is an intersection
				if (s3.size() > 1) {
					Vector<double> v(s3.size());
					std::set<double>::iterator s = s3.begin();

					// copy the elements into a vector
					for (unsigned int k=0; k<s3.size(); k++) v[k] = *s++;

					// create the compbezcurvs
					Vector<BezCurv<double> > vec1(s3.size()-1);
					Vector<BezCurv<double> > vec2(s3.size()-1);

					BspCurv<double> b1((*(basis.b))[i].GetBspCurv()), b2((*(basis.b))[j].GetBspCurv());
					// find the segments of intersection
					for (unsigned int k=0; k<s3.size()-1; k++) {
						int segb1 = b1.GetKnotSet().Find_segment(v[k]);
						int segb2 = b2.GetKnotSet().Find_segment(v[k]);
						vec1[k] = b1.GetSegment(segb1);
						vec2[k] = b2.GetSegment(segb2);
					}
				
					CompBezCurv<double> cb1(vec1,s3.size()-1,v);
					CompBezCurv<double> cb2(vec2,s3.size()-1,v);
					CompBezCurv<double> prod = cb1.Product(cb2);
	
					mat1[i][j] = prod.ConvertBspCurv().Integrate((*kts)[ord-1],(*kts)[num-ord]);
				}
			}
		}
	for (int i=0; i<kset.GetNum()-ord+lev-1; i++)
		for (int j=i+1; j<kset.GetNum()-ord+lev; j++) mat1[i][j] = mat1[j][i];
	
	return mat1;
}
Beispiel #13
0
    static void go()
    {
        CPPUNIT_ASSERT( ROWS <= 5 &&  COLS <= 5 );
        gmtl::Matrix<T, ROWS, COLS> mat1, mat2;
        T array[] = { (T)0.78, (T) 1.4,   (T) 2.9,  (T)3.45,
                      (T)4.21, (T)57.9,  (T) 65.9,  (T)74.6,
                      (T)89.2, (T)99.2,  (T) 10.9,  (T)11.9,
                      (T)12.5, (T)13.9,  (T)14.78,  (T)15.6,
                      (T)4.21, (T)57.9,  (T) 65.9,  (T)74.6,
                      (T)89.2, (T)99.2,  (T) 10.9,  (T)11.9,
                      (T)89.2, (T)99.2,  (T) 10.9,  (T)11.9
                    };
        mat1.set( array );
        mat1 = mat2;
        CPPUNIT_ASSERT( mat1 == mat2 );
        CPPUNIT_ASSERT( mat2 == mat1 );

        // Test that != works on all elements
        for (int i = 0; i < ROWS; ++i)
        {
            for (int j = 0; j < COLS; ++j)
            {
                mat2( i, j ) = (T)1221.0f;
                CPPUNIT_ASSERT(  (mat1 != mat2) );
                CPPUNIT_ASSERT( !(mat1 == mat2) );
                mat2( i, j ) = mat1( i, j ); // put it back
            }
        }

        // Test for epsilon equals working
        CPPUNIT_ASSERT( gmtl::isEqual( mat1, mat2 ) );
        CPPUNIT_ASSERT( gmtl::isEqual( mat1, mat2, (T)0.0f ) );
        CPPUNIT_ASSERT( gmtl::isEqual( mat2, mat1, (T)0.0f ) );
        CPPUNIT_ASSERT( gmtl::isEqual( mat2, mat1, (T)100000.0f ) );
        T eps = (T)10.0;
        for (int i = 0; i < ROWS; ++i)
        {
            for (int j = 0; j < COLS; ++j)
            {
                mat2( i, j ) = mat1( i, j ) - (eps / (T)2.0);
                CPPUNIT_ASSERT(  gmtl::isEqual( mat1, mat2, eps ) );
                CPPUNIT_ASSERT( !gmtl::isEqual( mat1, mat2, (T)(eps / 3.0) ) );
                mat2( i, j ) = mat1( i, j ); // put it back
            }
        }
    }
Beispiel #14
0
TEST(Math, MatrixMul1) {
	Mat4 mat1(1.0f);
	Mat4 mat2(1.0f);
	Mat4 mat = mat1*mat2;
	ASSERT_EQ(1, mat.get(0,0));	ASSERT_EQ(0, mat.get(1,0));	ASSERT_EQ(0, mat.get(2,0));	ASSERT_EQ(0, mat.get(3,0));
	ASSERT_EQ(0, mat.get(0,1));	ASSERT_EQ(1, mat.get(1,1));	ASSERT_EQ(0, mat.get(2,1));	ASSERT_EQ(0, mat.get(3,1));
	ASSERT_EQ(0, mat.get(0,2));	ASSERT_EQ(0, mat.get(1,2));	ASSERT_EQ(1, mat.get(2,2));	ASSERT_EQ(0, mat.get(3,2));
	ASSERT_EQ(0, mat.get(0,3));	ASSERT_EQ(0, mat.get(1,3));	ASSERT_EQ(0, mat.get(2,3));	ASSERT_EQ(1, mat.get(3,3));
}
Beispiel #15
0
int main () {

  // Define symmetric matrix
  PLMD::Matrix<double> mat1(3,3); PLMD::OFile out; out.open("output");
  mat1(0,0)=1.0; mat1(0,1)=0.2; mat1(0,2)=0.3;
  mat1(1,0)=0.2; mat1(1,1)=0.2; mat1(1,2)=0.6;
  mat1(2,0)=0.3; mat1(2,1)=0.6; mat1(2,2)=0.4;

  // Test diagonalize
  std::vector<double> eigval(3); PLMD::Matrix<double> eigvec(3,3); 
  diagMat( mat1, eigval, eigvec ); 
  out<<"Eigenvalues "<<eigval[0]<<" "<<eigval[1]<<" "<<eigval[2]<<"\n";
  out<<"Eigenvectors : \n";
  for(unsigned i=0;i<3;++i){
      out<<eigvec(i,0)<<" "<<eigvec(i,1)<<" "<<eigvec(i,2)<<"\n";
  }

  // Test inverse
  out<<"Inverse : \n";
  PLMD::Matrix<double> inverse(3,3); Invert( mat1, inverse );
  for(unsigned i=0;i<3;++i){ 
      for(unsigned j=0;j<3;++j) out<<inverse(i,j)<<" ";
      out<<"\n";
  }

  // Test pseudoinverse 
  out<<"Pseudoinverse : \n";
  PLMD::Matrix<double> mat(3,2);
  mat(0,0)=0.1; mat(0,1)=0.2; 
  mat(1,0)=0.3; mat(1,1)=0.5;
  mat(2,0)=0.4; mat(2,1)=0.6;
  PLMD::Matrix<double> pseu(2,3);
  pseudoInvert( mat, pseu );
  for(unsigned i=0;i<pseu.nrows();++i){
     for(unsigned j=0;j<pseu.ncols();++j) out<<" "<<pseu(i,j);
     out<<"\n";
  }
  out.close();

  return 0;
}
Beispiel #16
0
        static void run (LinearAlgebraUnitTest& u)
        {
            const ElementType data1[] = { 1,  2, 3,  4,  5,  6,  7,  8 };
            const ElementType data2[] = { 1, -1, 3, -1,  5, -1,  7, -1 };
            const ElementType data3[] = { 50, -10, 114, -26 };

            Matrix<ElementType> mat1 (2, 4, data1);
            Matrix<ElementType> mat2 (4, 2, data2);
            Matrix<ElementType> mat3 (2, 2, data3);

            u.expect((mat1 * mat2) == mat3);
        }
Beispiel #17
0
        static void run (LinearAlgebraUnitTest& u)
        {
            const ElementType data1[] = { 1,  2, 3,  4, 5,  6, 7,  8 };
            const ElementType data2[] = { 1, -1, 3, -1, 5, -1, 7, -1 };
            const ElementType data3[] = { 0,  3, 0,  5, 0,  7, 0,  9 };

            Matrix<ElementType> mat1 (2, 4, data1);
            Matrix<ElementType> mat2 (2, 4, data2);
            Matrix<ElementType> mat3 (2, 4, data3);

            u.expect((mat1 - mat2) == mat3);
        }
Beispiel #18
0
        static void run (LinearAlgebraUnitTest& u)
        {
            const ElementType data1[] = { 1,  2, 3,  4,  5,  6,  7,  8 };
            const ElementType data2[] = { 1, -1, 3, -1,  5, -1,  7, -1 };
            const ElementType data3[] = { 1, -2, 9, -4, 25, -6, 49, -8 };

            Matrix<ElementType> mat1 (2, 4, data1);
            Matrix<ElementType> mat2 (2, 4, data2);
            Matrix<ElementType> mat3 (2, 4, data3);

            u.expect (Matrix<ElementType>::hadarmard (mat1, mat2) == mat3);
        }
static Matrix<double> ReadInMatrix(istream& in)
{
String str1;
String str2;
String word1;
int DIM1, DIM2;
int i, j;

cout << " read in DIM1"  << endl;
 cout << "----------------------------- \n";
 str1.ReadFullLine(in);
 str1.IsolateNextWord(word1, ' ');
 DIM1=word1.ToInteger();
 cout << "this is DIM1 "  << DIM1 << endl;
 cout << "----------------------------- \n";
 cout << " read in DIM2"  << endl;
 cout << "----------------------------- \n";
// str1.IsolateNextWord(word1, ' ');
 DIM2=str1.ToInteger();
 cout << "this is DIM2 "  << DIM2 << endl;
 cout << "----------------------------- \n";
cout << " constructing matrix with DIM1, DIM2 " << endl;
Matrix<double> mat1(DIM1, DIM2);
cout << " checking dimensions of matrix" << endl;
cout << " DIM1=mat1.size()= " << mat1.size() << endl;
cout << "----------------------------- \n";
cout << " DIM2=mat1[0].size()= " << mat1[0].size() << endl;
cout << "----------------------------- \n";
cout << " read in matrix mat1 " << endl;
cout << "----------------------------- \n";
for(i=0;i<DIM1;i++)
  {
   str1.ReadFullLine(in);
   cout << " str1 " << str1 << endl;
   
   for(j=0; j<DIM2-1; j++)
      {
      str1.IsolateNextWord(word1, ' ');
      mat1[i][j]=word1.ToFloat(); 
      };
   mat1[i][j]=str1.ToFloat(); 
  }; 
cout << "----------------------------- \n";
cout << " now print out matrix mat1 " << endl;
cout << mat1;
cout << " end of test" << endl;

return mat1;


}
Beispiel #20
0
//---------------------------------------
TEST_F(Matrix3Test, Constructor)
{
    ASSERT_9REALS_MAT_EQ( 0,1,2, 3,4,5, 6,7,8, m2_ );

    fsm::Real set[9] = { 9,8,7,
                         6,5,4,
                         3,2,1 };

    fsm::Matrix3 mat1 (set);
    ASSERT_9REALS_MAT_EQ( 9,8,7,6,5,4,3,2,1, mat1 );

    fsm::Matrix3 mat2 (set, fsm::Matrix3::kColMajor);
    ASSERT_9REALS_MAT_EQ( 9,6,3,8,5,2,7,4,1, mat2 );
}
Beispiel #21
0
int test_ray_tracking()
{
	// Blog: http://blog.csdn.net/fengbingchun/article/details/76135606
	const int spheres{ 20 };
	std::unique_ptr<float[]> A(new float[spheres * 3]);
	std::unique_ptr<float[]> B(new float[spheres * 3]);
	std::unique_ptr<float[]> C(new float[spheres]);

	generator_random_number(A.get(), spheres * 3, 0.f, 1.f);
	generator_random_number(B.get(), spheres * 3, -400.f, 400.f);
	generator_random_number(C.get(), spheres, 20.f, 120.f);

	float elapsed_time1{ 0.f }, elapsed_time2{ 0.f }; // milliseconds

	const int width{ 512 }, height = width;
	cv::Mat mat1(height, width, CV_8UC4), mat2(height, width, CV_8UC4);

	int ret = ray_tracking_cpu(A.get(), B.get(), C.get(), spheres, mat1.data, width, height, &elapsed_time1);
	if (ret != 0) PRINT_ERROR_INFO(ray_tracking_cpu);

	ret = ray_tracking_gpu(A.get(), B.get(), C.get(), spheres, mat2.data, width, height, &elapsed_time2);
	if (ret != 0) PRINT_ERROR_INFO(ray_tracking_gpu);

	for (int y = 0; y < height; ++y) {
		for (int x = 0; x < width; ++x) {
			cv::Vec4b val1 = mat1.at<cv::Vec4b>(y, x);
			cv::Vec4b val2 = mat2.at<cv::Vec4b>(y, x);

			for (int i = 0; i < 4; ++i) {
				if (val1[i] != val2[i]) {
					fprintf(stderr, "their values are different at (%d, %d), i: %d, val1: %d, val2: %d\n",
						x, y, i, val1[i], val2[i]);
					//return -1;
				}
			}
		}
	}

#ifdef __linux__
	const std::string save_image_name{ "test_data/ray_tracking.jpg" };
#else
	const std::string save_image_name{ "E:/GitCode/CUDA_Test/ray_tracking.jpg" };
#endif
	cv::imwrite(save_image_name, mat2);

	fprintf(stderr, "ray tracking: cpu run time: %f ms, gpu run time: %f ms\n", elapsed_time1, elapsed_time2);

	return 0;
}
int test_rotate90()
{
#ifdef _MSC_VER
	cv::Mat matSrc = cv::imread("E:/GitCode/OpenCV_Test/test_images/1.jpg", 1);
#else	
	cv::Mat matSrc = cv::imread("test_images/1.jpg", 1);
#endif
	if (!matSrc.data) {
		std::cout << "read image fail" << std::endl;
		return -1;
	}

	int width = matSrc.cols;
	int height = matSrc.rows;

	fbc::Mat_<uchar, 3> mat1(height, width, matSrc.data);
	fbc::Mat_<uchar, 3> matTranspose(width, height);
	fbc::transpose(mat1, matTranspose);

	// clockwise rotation  90
	fbc::Mat_<uchar, 3> matRotate90(width, height);
	fbc::flip(matTranspose, matRotate90, 1);
	cv::Mat tmp2(width, height, CV_8UC3, matRotate90.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_90.jpg", tmp2);
#else	
	cv::imwrite("test_images/rotate_90.jpg", tmp2);
#endif

	// clockwise rotation 180
	fbc::Mat_<uchar, 3> matRotate180(height, width);
	fbc::flip(mat1, matRotate180, -1);
	cv::Mat tmp3(height, width, CV_8UC3, matRotate180.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_180.jpg", tmp3);
#else
	cv::imwrite("test_images/rotate_180.jpg", tmp3);
#endif
	// clockwise rotation 270
	fbc::Mat_<uchar, 3> matRotate270(width, height);
	fbc::flip(matTranspose, matRotate270, 0);
	cv::Mat tmp4(matTranspose.rows, matTranspose.cols, CV_8UC3, matRotate270.data);
#ifdef _MSC_VER
	cv::imwrite("E:/GitCode/OpenCV_Test/test_images/rotate_270.jpg", tmp4);
#else
	cv::imwrite("test_images/rotate_270.jpg", tmp4);
#endif
	return 0;
}
Beispiel #23
0
int main() {
  // Define two 10x10 matrices with element types of long double
  // The first has all elements set to 1.0
  // The second has all elements set to 2.0
  Matrix<long double> mat1(10, 10, 1.0);
  Matrix<long double> mat2(10, 10, 2.0);

  // Set a few elements differently as a test of accessors
  mat1(3,4) = 10.0;
  mat2(1,2) = -15.0;

  // Define a third matrix as the sum of the first two
  Matrix<long double> mat3 = mat1 + mat2;

  // Print out the third matrix as a text array
  for (int i=0; i<mat3.get_rows(); i++) {
    for (int j=0; j<mat3.get_cols(); j++) {
      std::cout << mat3(i,j) << ", ";
    }
    std::cout << std::endl;
  }

  return 0;
}
Beispiel #24
0
int test_split_float()
{
	cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);
	if (!mat.data) {
		std::cout << "read image fail" << std::endl;
		return -1;
	}
	mat.convertTo(mat, CV_32FC3);
	//cv::cvtColor(mat, mat, CV_BGR2GRAY);

	int chs = mat.channels();
	int width = mat.cols;
	int height = mat.rows;

	fbc::Mat_<float, 3> mat1(height, width, mat.data);
	std::vector<fbc::Mat_<float, 1>> vecMat2;
	fbc::Mat_<float, 1>* mat2 = new fbc::Mat_<float, 1>[chs];
	for (int i = 0; i < chs; i++) {
		mat2[i] = fbc::Mat_<float, 1>(height, width);
		vecMat2.push_back(mat2[i]);
	}

	fbc::split(mat1, vecMat2);

	cv::Mat mat1_(height, width, CV_32FC3, mat.data);
	std::vector<cv::Mat> vecMat2_;
	cv::split(mat1_, vecMat2_);

	assert(vecMat2.size() == vecMat2_.size());
	for (int i = 0; i < vecMat2.size(); i++) {
		assert(vecMat2[i].rows == vecMat2_[i].rows && vecMat2[i].cols == vecMat2_[i].cols);
		assert(vecMat2[i].step == vecMat2_[i].step);
		assert(vecMat2[i].channels == vecMat2_[i].channels());

		for (int y = 0; y < vecMat2[i].rows; y++) {
			const fbc::uchar* p = vecMat2[i].ptr(y);
			const uchar* p_ = vecMat2_[i].ptr(y);

			for (int x = 0; x < vecMat2[i].step; x++) {
				assert(p[x] == p_[x]);
			}
		}
	}

	delete[] mat2;

	return 0;
}
Beispiel #25
0
void Turret::getCameraTransform(float camDist, TMat3F *transform)
{
   if(!image.shape)
      return;
   image.shape->animate();
	int node = cameraNode;
   if(node != -1)
   {
      const TMat3F &nodeTrans = image.shape->getTransform(node);
      TMat3F mat1(EulerF(turretElevation, 0, turretRotation), nodeTrans.p);
      m_mul(mat1, getTransform(), transform);
	   validateEyePoint (transform, camDist * 1.3);
   }
   else
      *transform = getTransform();
}
Beispiel #26
0
bool Turret::getMuzzleTransform(int, TMat3F *transform)
{
   if(!image.shape)
      return false;
   image.shape->animate();
   int node = gunNode;
   if(node != -1)
   {
      const TMat3F &nodeTrans = image.shape->getTransform(node);
      TMat3F mat1(EulerF(turretElevation, 0, turretRotation), nodeTrans.p);
      m_mul(mat1, getTransform(), transform);
   }
   else
      *transform = getTransform();
   return true;
}
Beispiel #27
0
void _bm_dynmat_op(unsigned round, double &timer)
{
	wyc::xcode_timer ct;
	MATRIX_T mat1(R,C), mat2(R,C);
	FUNCTOR ftor;
	timer=0;
	printf("executing %d matrix %s...\n",round,ftor.name());
	for(unsigned i=0; i<round; ++i) {
		rand_matrix<MATRIX_T,R,C>(mat1);
		rand_matrix<MATRIX_T,R,C>(mat2);
		ct.start();
		ftor(mat2,mat1);
		ct.stop();
		timer+=ct.get_time();
	}
}
Beispiel #28
0
int main () 
{
  Matrix mat0 (3, 4);
  Matrix mat1 (3, 2);

  mat0 [0] = 1;
  mat0 [1] = 2;
  mat0 [2] = 3;
  mat0 [3] = 4;
  mat0 [4] = 5;
  mat0 [5] = 6;
  mat0 [6] = 7;
  mat0 [7] = 8;
  mat0 [8] = 9;
  mat0 [9] = 4;
  mat0 [10] = 5;
  mat0 [11] = 6;
  mat1 (0,0) = 9.5;
  mat1 (0,1) = 8.5;
  mat1 (1,0) = 7.5;
  mat1 (1,1) = 6.5;
  mat1 (2,0) = 5.5;
  mat1 (2,1) = 4.5;
  
  MatrixOperation::print (mat0);
  MatrixOperation::print (mat1);

  std::vector<double > a (3);
  a[0] = 9;
  a[1] = 8;
  a[2] = 7;
  
  std::vector<double > b (2);
  b[0] = 4.5;
  b[1] = 5.5;

//   MatrixOperation::mv (a, 1.5, 2.1, mat0, true, b);
  
//   print (a);

  Matrix C;
  MatrixOperation::mm (C, 2.2, mat0, true, mat1, false);

  MatrixOperation::print (C);
  

  
}
void shoot(Terrain* const t, const QString& img){
    Vector3D o(-3400, 2800, -2200);
    Vector3D d(1,-1,1);

    Vector3D soleil(100000000,0,0);
    QMatrix3x3 mat1;
    mat1(0,0)=cos(3*M_PI/4);
    mat1(0,1)=-sin(3*M_PI/4);
    mat1(0,2)=0;
    mat1(1,0)=sin(3*M_PI/4);
    mat1(1,1)=cos(3*M_PI/4);
    mat1(1,2)=0;
    mat1(2,0)=0;
    mat1(2,1)=0;
    mat1(2,2)=1;
    soleil.rotate(mat1);

    Vector3D dirCam(500,0,500);
    Vector3D dist(o+d);
    Camera cam(o, dirCam, o.distanceToPoint(dist)*4);
    QImage result = cam.printScreen(t,soleil,192*10,108*10);
    result.save(img);
}
int test_cvtColor_YUV2BGR()
{
#ifdef _MSC_VER
	cv::Mat mat = cv::imread("E:/GitCode/OpenCV_Test/test_images/lena.png", 1);
#else	
	cv::Mat mat = cv::imread("test_images/lena.png", 1);
#endif
	if (!mat.data) {
		std::cout << "read image fail" << std::endl;
		return -1;
	}

	cv::cvtColor(mat, mat, CV_BGR2YUV_I420);

	int width = mat.cols;
	int height = mat.rows;
	int newHeight = height * 2 / 3;

	// uchar
	fbc::Mat_<uchar, 1> mat1(height, width, mat.data);
	fbc::Mat_<uchar, 1> mat2(mat1);
	fbc::Mat_<uchar, 3> mat3(newHeight, width);
	fbc::cvtColor(mat2, mat3, fbc::CV_YUV2BGR_I420);

	cv::Mat mat1_(height, width, CV_8UC1, mat.data);
	cv::Mat mat2_;
	mat1_.copyTo(mat2_);
	cv::Mat mat3_(newHeight, width, CV_8UC3);
	cv::cvtColor(mat2_, mat3_, CV_YUV2BGR_I420);

	assert(mat3.step == mat3_.step);
	for (int y = 0; y < mat3.rows; y++) {
		const fbc::uchar* p = mat3.ptr(y);
		const uchar* p_ = mat3_.ptr(y);

		for (int x = 0; x < mat3.step; x++) {
			assert(p[x] == p_[x]);
		}
	}

	return 0;
}