当前位置: 首页>>代码示例>>C++>>正文


C++ Mat::Rows方法代码示例

本文整理汇总了C++中Mat::Rows方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::Rows方法的具体用法?C++ Mat::Rows怎么用?C++ Mat::Rows使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Mat的用法示例。


在下文中一共展示了Mat::Rows方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: lagrange2D

// This routine evaluates the Lagrange interpolating polynomial,
// defined over a set of data points (x_i,y_i), i=0,...,n, at a point z.
//
// Usage: p = lagrange(x, y, z);
//
// inputs:   x     Mat vector of length n+1, containing the interpolation nodes
//           y     Mat vector of length n+1, containing the interpolation data
//           z     double location to evaluate polynomial
// outputs:  p     value of p(z)
//
double lagrange2D(Mat &x, Mat &y, Mat&z, double a,double b)
{

  // check input arguments (lengths of x and y)
  if (x.Rows()*x.Cols() != y.Rows()*y.Cols()) {
    cerr << "lagrange2d error: x and y have different lengths!\n";
    return 0.0;
  }

  // get m
  int m = x.Rows()*x.Cols() - 1;

  // get n
  int n = y.Rows()*y.Cols() - 1;

  // evaluate p
  double p = 0.0;                // initialize result
  for(int i=0;i<=m;i++){
	  for (int j=0; j<=n; j++)       // loop over data values
		p += z(i,j)*lagrange_basis2D(x, i, a)*lagrange_basis2D(y, j, b);  // update result with next term
  }
  // return final result
  return p;

} // end of function
开发者ID:TylerJackson,项目名称:SciCompRepo,代码行数:35,代码来源:lagrange2D.cpp

示例2: result

Mat operator - (const Mat &m)
{
    Mat result(m.Rows(), m.Cols());
    Int     i;

    for (i = 0; i < m.Rows(); i++)
        result[i] = -m[i];

    return(result);
}
开发者ID:jyunming-chen,项目名称:svl-1.5,代码行数:10,代码来源:Mat.cpp

示例3: BackSub

// performs backwards substitution on the linear system U*x = b, filling in the input Mat x
int BackSub(Mat &U, Mat &x, Mat &b) {
  // check that matrix sizes match
  if (U.Rows() != b.Rows() || U.Rows() != U.Cols() ||
      b.Cols() != 1 || x.Rows() != U.Rows() || x.Cols() != 1) {
    fprintf(stderr,"BackSub error, illegal matrix/vector dimensions\n");
    fprintf(stderr,"  Mat is %li x %li,  sol is %li x %li,  rhs is %li x %li\n",
	    U.Rows(), U.Cols(), x.Rows(), x.Cols(), b.Rows(), b.Cols());
    return 1;
  }

  // copy b into x
  x = b;

  // perform column-oriented Backwards Substitution algorithm
  for (long int j=U.Rows()-1; j>=0; j--) {

    // solve for this row of solution
    x(j) = x(j)/U(j,j);

    // update all subsequent rhs
    for (long int i=0; i<j; i++)
      x(i) -= U(i,j)*x(j);

  }

  // return success
  return 0;
}
开发者ID:TylerJackson,项目名称:SciCompRepo,代码行数:29,代码来源:Mat.cpp

示例4: trans

Mat trans(const Mat &m)
{
    Int     i,j;
    Mat result(m.Cols(), m.Rows());

    for (i = 0; i < m.Rows(); i++)
        for (j = 0; j < m.Cols(); j++)
            result.Elt(j,i) = m.Elt(i,j);

    return(result);
}
开发者ID:jyunming-chen,项目名称:svl-1.5,代码行数:11,代码来源:Mat.cpp

示例5: Assert

Vec operator * (const Vec &v, const Mat &m)         // v * m
{
    Assert(v.Elts() == m.Rows(), "(Mat::v*m) vector/matrix sizes don't match");

    Vec     result(m.Cols(), vl_zero);
    Int     i;

    for (i = 0; i < m.Rows(); i++)
        result += m[i] * v[i];

    return(result);
}
开发者ID:jyunming-chen,项目名称:svl-1.5,代码行数:12,代码来源:Mat.cpp

示例6: BGRAtoRGB

void ColorSpace::BGRAtoRGB(const Mat& color1, Mat& color2)
{
    color2.Create (color1.Rows(), color1.Cols(), MAT_TBYTE3);
	int d=0;
	uchar* psrc=color1.data.ptr[0];
	uchar* pdst=color2.data.ptr[0];
    int datalen=color1.Rows()*color1.Cols()*3;
	for (int i=0; i<datalen; i+=3, d+=4)
	{
		pdst[i]=psrc[d+2];
		pdst[i+1]=psrc[d+1];
		pdst[i+2]=psrc[d];
	}
}
开发者ID:ArchieGoodwin,项目名称:OnTimeMed,代码行数:14,代码来源:ColorSpace.cpp

示例7:

// copy constructor
Mat::Mat(const Mat& A) {
  nrows = A.Rows();
  ncols = A.Cols();
  data = new double[ncols*nrows];
  own_data = true;
  for (long int i=0; i<nrows*ncols; i++)  data[i] = A.data[i];
}
开发者ID:conradhappeliv,项目名称:schoolwork,代码行数:8,代码来源:mat.cpp

示例8: Dot

// dot-product of x and y
double Dot(Mat &x, Mat &y) {
  // check that array sizes match
  if (y.Rows() != x.Rows() || y.Cols() != x.Cols()) {
    fprintf(stderr,"Dot error, matrix size mismatch\n");
    fprintf(stderr,"  Mat 1 is %li x %li,  Mat 2 is %li x %li\n",
	    x.Rows(), x.Cols(), y.Rows(), y.Cols());
    return 0.0;
  }

  // perform operation and return
  double sum=0.0;
  for (long int j=0; j<x.Cols(); j++)
    for (long int i=0; i<x.Rows(); i++)
      sum += x(i,j)*y(i,j);
  return sum;
}
开发者ID:TylerJackson,项目名称:SciCompRepo,代码行数:17,代码来源:Mat.cpp

示例9: GraytoRGB

void ColorSpace::GraytoRGB (const Mat& gray, Mat& color)
{
	if (gray.Channels()==3)
	{
		color.Create (gray, TRUE);
		return;
	}
	if (gray.SizeObject() != color.SizeObject() || color.Channels()==3)
	{
		color.Release();
		color.Create (gray.SizeObject(), (TYPE)CVLIB_MAKETYPE(gray.Type(), 3));
	}
	int nH = color.Rows(), nW = color.Cols();
	int elemsize=CVLIB_ELEM_SIZE(gray.Type());
	for (int i = 0; i < nH; i ++)
	{
		uchar* pcolor=color.data.ptr[i];
		uchar* pgray=gray.data.ptr[i];
		for (int k=0; k<nW; k++)
		{
			memcpy (&pcolor[3*k*elemsize], &pgray[k*elemsize], elemsize);
			memcpy (&pcolor[(3*k+1)*elemsize], &pgray[k*elemsize], elemsize);
			memcpy (&pcolor[(3*k+2)*elemsize], &pgray[k*elemsize], elemsize);
		}
	}
}
开发者ID:ArchieGoodwin,项目名称:OnTimeMed,代码行数:26,代码来源:ColorSpace.cpp

示例10: lagrange_basis

// Utility function to evaluate a given Lagrange basis function at a point.
//
// Usage: l = lagrange_basis(x, i, z);
//
// inputs:   x     Mat vector of length n+1, containing the interpolation nodes
//           i     integer indicating which Lagrange basis function to evaluate
//           z     double location to evaluate basis function
// outputs:  p     value of l(z)
// 
double lagrange_basis(Mat &x, int i, double z) {
  double l = 1.0;              // initialize basis function
  double *xd = x.get_data();   // access data array (for increased speed)
  for (int j=0; j<x.Rows()*x.Cols(); j++)
    if (j != i)  l *= (z - xd[j]) / (xd[i] - xd[j]);
  return l;
}
开发者ID:TylerJackson,项目名称:SciCompRepo,代码行数:16,代码来源:lagrange.cpp

示例11: Dot

// compute the dot-product of two compatible vectors x and y
double Dot(Mat &x, Mat &y) {

  // check that array sizes match
  if (y.Rows() != x.Rows() || y.Cols() != x.Cols()) {
    cerr << "Dot error, matrix size mismatch\n";
    cerr << "  Mat 1 is " << x.Rows() << " x " << x.Cols() 
	 << ",  Mat 2 is " << y.Rows() << " x " << y.Cols() << endl;
    return 0.0;
  }
  
  // perform operation and return
  double sum=0.0;
  for (long int j=0; j<x.Cols(); j++)  
    for (long int i=0; i<x.Rows(); i++)  
      sum += x(i,j)*y(i,j);
  return sum;
}
开发者ID:conradhappeliv,项目名称:schoolwork,代码行数:18,代码来源:mat.cpp

示例12: trace

Real trace(const Mat &m)
{
    Int     i;
    Real    result = vl_0;

    for (i = 0; i < m.Rows(); i++)
        result += m.Elt(i,i);

    return(result);
}
开发者ID:jyunming-chen,项目名称:svl-1.5,代码行数:10,代码来源:Mat.cpp

示例13: BackSub

// performs backwards substitution on the linear system U*x = b, filling in the input Mat x
int BackSub(Mat &Umat, Mat &xvec, Mat &bvec) {

  // check that matrix sizes match
  if (Umat.Rows() != bvec.Rows() || Umat.Rows() != Umat.Cols() || bvec.Cols() != 1 || 
      xvec.Rows() != Umat.Rows() || xvec.Cols() != 1) {
    cerr << "BackSub error, illegal matrix/vector dimensions\n";
    cerr << "  Mat is " << Umat.Rows() << " x " << Umat.Cols() 
	 << ",  rhs is " << bvec.Rows() << " x " << bvec.Cols()
	 << ",  solution is " << xvec.Rows() << " x " << xvec.Cols() << endl;
    return 1;
  }
  
  // get the matrix size 
  long int n = Umat.Rows();
  
  // access the data arrays
  double *U = Umat.get_data();
  double *x = xvec.get_data();
  double *b = bvec.get_data();

  // copy b into x
  xvec = bvec;

  // analyze matrix for typical nonzero magnitude
  double Umax = Umat.MaxNorm();

  // perform column-oriented Backwards Substitution algorithm
  for (long int j=n-1; j>=0; j--) {

    // check for nonzero matrix diagonal
    if (fabs(U[IDX(j,j,n)]) < STOL*Umax) {
      cerr << "BackSub error: numerically singular matrix!\n";
      return 1;
    }

    // solve for this row of solution
    x[j] /= U[IDX(j,j,n)];

    // update all remaining rhs
    for (long int i=0; i<j; i++)
      x[i] -= U[IDX(i,j,n)]*x[j];

  }

  // return success
  return 0;
}
开发者ID:conradhappeliv,项目名称:schoolwork,代码行数:48,代码来源:mat.cpp

示例14: FwdSub

// performs forwards substitution on the linear system L*x = b, filling in the input Mat x
int FwdSub(Mat &Lmat, Mat &xvec, Mat &bvec) {

  // check that matrix sizes match
  if (Lmat.Rows() != bvec.Rows() || Lmat.Rows() != Lmat.Cols() || bvec.Cols() != 1 || 
      xvec.Rows() != Lmat.Rows() || xvec.Cols() != 1) {
    cerr << "FwdSub error, illegal matrix/vector dimensions\n";
    cerr << "  Mat is " << Lmat.Rows() << " x " << Lmat.Cols() 
	 << ",  rhs is " << bvec.Rows() << " x " << bvec.Cols()
	 << ",  solution is " << xvec.Rows() << " x " << xvec.Cols() << endl;
    return 1;
  }
  
  // get the matrix size 
  long int n = Lmat.Rows();
  
  // access the data arrays
  double *L = Lmat.get_data();
  double *x = xvec.get_data();
  double *b = bvec.get_data();

  // copy b into x
  xvec = bvec;

  // analyze matrix for typical nonzero magnitude
  double Lmax = Lmat.MaxNorm();

  // perform column-oriented Forwards Substitution algorithm
  for (long int j=0; j<n; j++) {

    // check for nonzero matrix diagonal
    if (fabs(L[IDX(j,j,n)]) < STOL*Lmax) {
      cerr << "FwdSub error: singular matrix!\n";
      return 1;
    }

    // solve for this row of solution
    x[j] /= L[IDX(j,j,n)];

    // update all remaining rhs
    for (long int i=j+1; i<n; i++)
      x[i] -= L[IDX(i,j,n)]*x[j];

  }

  // return success
  return 0;
}
开发者ID:conradhappeliv,项目名称:schoolwork,代码行数:48,代码来源:mat.cpp

示例15: lagrange

// This routine evaluates the Lagrange interpolating polynomial, 
// defined over a set of data points (x_i,y_i), i=0,...,n, at a point z.
//
// Usage: p = lagrange(x, y, z);
//
// inputs:   x     Mat vector of length n+1, containing the interpolation nodes
//           y     Mat vector of length n+1, containing the interpolation data
//           z     double location to evaluate polynomial
// outputs:  p     value of p(z)
// 
double lagrange(Mat &x, Mat &y, double z) 
{

  // check input arguments (lengths of x and y)
  if (x.Rows()*x.Cols() != y.Rows()*y.Cols()) {
    cerr << "lagrange error: x and y have different lengths!\n";
    return 0.0;
  }

  // get n
  int n = x.Rows()*x.Cols() - 1;

  // evaluate p
  double p = 0.0;                // initialize result
  for (int i=0; i<=n; i++)       // loop over data values
    p += y(i)*lagrange_basis(x, i, z);  // update result with next term

  // return final result
  return p;

} // end of function
开发者ID:TylerJackson,项目名称:SciCompRepo,代码行数:31,代码来源:lagrange.cpp


注:本文中的Mat::Rows方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。