本文整理汇总了C++中Mat::Cols方法的典型用法代码示例。如果您正苦于以下问题:C++ Mat::Cols方法的具体用法?C++ Mat::Cols怎么用?C++ Mat::Cols使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Mat
的用法示例。
在下文中一共展示了Mat::Cols方法的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
示例2: 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);
}
示例3: result
Mat operator * (const Mat &m, const Mat &n)
{
Assert(m.Cols() == n.Rows(), "(Mat::*m) matrix cols don't match");
Mat result(m.Rows(), n.Cols());
Int i;
for (i = 0; i < m.Rows(); i++)
result[i] = m[i] * n;
return(result);
}
示例4: 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];
}
}
示例5: 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;
}
示例6: 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);
}
}
}
示例7: 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;
}
示例8:
// 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];
}
示例9: 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;
}
示例10: Solve
// solves a linear system A*x = b, returning x as a new Mat
Mat Solve(Mat &A, Mat &b) {
// check that matrix sizes match
if (A.Rows() != A.Rows() || A.Rows() != A.Cols() || b.Cols() != 1) {
fprintf(stderr,"Solve error, illegal matrix/vector dimensions\n");
fprintf(stderr," Mat is %li x %li, rhs is %li x %li\n",
A.Rows(), A.Cols(), b.Rows(), b.Cols());
Mat *x = new Mat(0,0);
return *x;
}
// create new Mat for output
Mat *x = new Mat(A.Rows(),1);
// call existing Solve routine for computations
if (Solve(A, *x, b) != 0)
fprintf(stderr,"Solve Warning: error in Solve call\n");
// return result
return *x;
}
示例11: BackSub
// performs backwards substitution on the linear system U*x = b, returning x as a new Mat;
// leaves U and b untouched
Mat BackSub(Mat &U, Mat &b) {
// check that matrix sizes match
if (U.Rows() != b.Rows() || U.Rows() != U.Cols() || b.Cols() != 1) {
fprintf(stderr,"BackSub error, illegal matrix/vector dimensions\n");
fprintf(stderr," Mat is %li x %li, rhs is %li x %li\n",
U.Rows(), U.Cols(), b.Rows(), b.Cols());
Mat *x = new Mat(0,0);
return *x;
}
// create new Mat for output
Mat *x = new Mat(U.Rows(),1);
// call existing BackSub routine for computations
if (BackSub(U, *x, b) != 0)
fprintf(stderr,"BackSub Warning: error in BackSub call\n");
// return result
return *x;
}
示例12: 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
示例13: BackSub
// performs backwards substitution on the linear system U*x = b, returning x as a new Mat;
// leaves U and b untouched
Mat BackSub(Mat &U, Mat &b) {
// check that matrix sizes match
if (U.Rows() != b.Rows() || U.Rows() != U.Cols() || b.Cols() != 1) {
cerr << "BackSub error, illegal matrix/vector dimensions\n";
cerr << " Mat is " << U.Rows() << " x " << U.Cols()
<< ", rhs is " << b.Rows() << " x " << b.Cols() << endl;
Mat *x = new Mat(0,0);
return *x;
}
// create new Mat for output
Mat *x = new Mat(U.Rows(),1);
// call existing BackSub routine for computations
if (BackSub(U, *x, b) != 0)
cerr << "BackSub Warning: error in BackSub call\n";
// return result
return *x;
}
示例14: Solve
// solves a linear system A*x = b, returning x as a new Mat
Mat Solve(Mat &A, Mat &b) {
// check that matrix sizes match
if (A.Rows() != A.Rows() || A.Rows() != A.Cols() || b.Cols() != 1) {
cerr << "Solve error, illegal matrix/vector dimensions\n";
cerr << " Mat is " << A.Rows() << " x " << A.Cols()
<< ", rhs is " << b.Rows() << " x " << b.Cols() << endl;
Mat *x = new Mat(0,0);
return *x;
}
// create new Mat for output
Mat *x = new Mat(A.Rows(),1);
// call existing Solve routine for computations
if (Solve(A, *x, b) != 0)
cerr << "Solve: error in in-place Solve call\n";
// return result
return *x;
}
示例15: FwdSub
// performs forwards substitution on the linear system L*x = b, returning x as a new Mat;
// leaves L and b untouched
Mat FwdSub(Mat &L, Mat &b) {
// check that matrix sizes match
if (L.Rows() != b.Rows() || L.Rows() != L.Cols() || b.Cols() != 1) {
cerr << "FwdSub error, illegal matrix/vector dimensions\n";
cerr << " Mat is " << L.Rows() << " x " << L.Cols()
<< ", rhs is " << b.Rows() << " x " << b.Cols() << endl;
Mat *x = new Mat(0,0);
return *x;
}
// create new Mat for output
Mat *x = new Mat(L.Rows(),1);
// call existing FwdSub routine for computations
if (FwdSub(L, *x, b) != 0)
cerr << "FwdSub Warning: error in FwdSub call\n";
// return result
return *x;
}