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


C++ Mat_d类代码示例

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


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

示例1: getNCCBlocks

void getNCCBlocks(const ImgG& scaledImg, Mat_d& pts, PtrVec<NCCBlock>& nccBlks,
		double scale) {
	if (pts.empty())
		return;

	nccBlks.clear();
	nccBlks.reserve(pts.rows * 2);

	int bw = 2 * SL_NCCBLK_HW + 1;

	if (scale == 1.0) {
		cv::Mat cvImg(scaledImg.rows, scaledImg.cols, CV_8UC1, scaledImg.data);
		cv::Size patchSize(bw, bw);
		cv::Mat patch;

		for (int i = 0; i < pts.rows; i++) {
			double x = pts.data[2 * i];
			double y = pts.data[2 * i + 1];
			cv::getRectSubPix(cvImg, patchSize, cv::Point2d(x, y), patch);
			NCCBlock* blk = new NCCBlock(0);
			/* copy image block */
			for (int j = 0; j < SL_NCCBLK_LEN; ++j) {
				blk->I[j] = patch.data[j];
			}
			/* compute NCC parameters */
			double a = 0, b = 0;
			blk->avgI = 0;
			for (int j = 0; j < SL_NCCBLK_LEN; ++j) {
				a += blk->I[j];
				b += double(blk->I[j]) * blk->I[j];
				blk->avgI += blk->I[j];
			}
			blk->A = a;
			blk->B = b;
			blk->C = 1 / sqrt(SL_NCCBLK_LEN * b - a * a);
			blk->avgI /= SL_NCCBLK_LEN;
			nccBlks.push_back(blk);
		}
	} else {
		cv::Mat cvOrgImg(scaledImg.rows, scaledImg.cols, CV_8UC1,
				scaledImg.data);
		cv::Mat cvImg;
		cv::resize(cvOrgImg, cvImg, cv::Size(), scale, scale);
		cv::Size patchSize(bw, bw);
		cv::Mat patch;

		for (int i = 0; i < pts.rows; i++) {
			double x = pts.data[2 * i] * scale;
			double y = pts.data[2 * i + 1] * scale;
			cv::getRectSubPix(cvImg, patchSize, cv::Point2d(x, y), patch);
			NCCBlock* blk = new NCCBlock(0);

			/* copy image block */
			for (int j = 0; j < SL_NCCBLK_LEN; ++j) {
				blk->I[j] = patch.data[j];
			}
			/* compute NCC parameters */
			double a = 0, b = 0;
			blk->avgI = 0;
			for (int j = 0; j < SL_NCCBLK_LEN; ++j) {
				a += blk->I[j];
				b += double(blk->I[j]) * blk->I[j];
				blk->avgI += blk->I[j];
			}
			blk->A = a;
			blk->B = b;
			blk->C = 1 / sqrt(SL_NCCBLK_LEN * b - a * a);
			blk->avgI /= SL_NCCBLK_LEN;
			nccBlks.push_back(blk);
		}
	}
}
开发者ID:caomw,项目名称:CoSLAM_for_Target_Following,代码行数:72,代码来源:SL_NCCBlock.cpp

示例2: matOnes

void matOnes(int m, int n, Mat_d& mat) {
	mat.resize(m, n);
	mat.fill(1);
}
开发者ID:jacobperron,项目名称:LibVisualSLAM,代码行数:4,代码来源:SL_Matrix.cpp

示例3: matZeros

void matZeros(int m, int n, Mat_d& mat) {
	mat.resize(m, n);
	mat.fill(0);
}
开发者ID:jacobperron,项目名称:LibVisualSLAM,代码行数:4,代码来源:SL_Matrix.cpp

示例4: mixingtypes

template<int SizeAtCompileType> void mixingtypes(int size = SizeAtCompileType)
{
  typedef std::complex<float>   CF;
  typedef std::complex<double>  CD;
  typedef Matrix<float, SizeAtCompileType, SizeAtCompileType> Mat_f;
  typedef Matrix<double, SizeAtCompileType, SizeAtCompileType> Mat_d;
  typedef Matrix<std::complex<float>, SizeAtCompileType, SizeAtCompileType> Mat_cf;
  typedef Matrix<std::complex<double>, SizeAtCompileType, SizeAtCompileType> Mat_cd;
  typedef Matrix<float, SizeAtCompileType, 1> Vec_f;
  typedef Matrix<double, SizeAtCompileType, 1> Vec_d;
  typedef Matrix<std::complex<float>, SizeAtCompileType, 1> Vec_cf;
  typedef Matrix<std::complex<double>, SizeAtCompileType, 1> Vec_cd;

  Mat_f mf    = Mat_f::Random(size,size);
  Mat_d md    = mf.template cast<double>();
  Mat_cf mcf  = Mat_cf::Random(size,size);
  Mat_cd mcd  = mcf.template cast<complex<double> >();
  Vec_f vf    = Vec_f::Random(size,1);
  Vec_d vd    = vf.template cast<double>();
  Vec_cf vcf  = Vec_cf::Random(size,1);
  Vec_cd vcd  = vcf.template cast<complex<double> >();
  float           sf  = internal::random<float>();
  double          sd  = internal::random<double>();
  complex<float>  scf = internal::random<complex<float> >();
  complex<double> scd = internal::random<complex<double> >();


  mf+mf;
  VERIFY_RAISES_ASSERT(mf+md);
#ifndef EIGEN_HAS_STD_RESULT_OF
  // this one does not even compile with C++11
  VERIFY_RAISES_ASSERT(mf+mcf);
#endif
  // the following do not even compile since the introduction of evaluators
//   VERIFY_RAISES_ASSERT(vf=vd);
//   VERIFY_RAISES_ASSERT(vf+=vd);
//   VERIFY_RAISES_ASSERT(mcd=md);
  
  // check scalar products
  VERIFY_IS_APPROX(vcf * sf , vcf * complex<float>(sf));
  VERIFY_IS_APPROX(sd * vcd, complex<double>(sd) * vcd);
  VERIFY_IS_APPROX(vf * scf , vf.template cast<complex<float> >() * scf);
  VERIFY_IS_APPROX(scd * vd, scd * vd.template cast<complex<double> >());

  // check dot product
  vf.dot(vf);
#if 0 // we get other compilation errors here than just static asserts
  VERIFY_RAISES_ASSERT(vd.dot(vf));
#endif
  VERIFY_IS_APPROX(vcf.dot(vf), vcf.dot(vf.template cast<complex<float> >()));

  // check diagonal product
  VERIFY_IS_APPROX(vf.asDiagonal() * mcf, vf.template cast<complex<float> >().asDiagonal() * mcf);
  VERIFY_IS_APPROX(vcd.asDiagonal() * md, vcd.asDiagonal() * md.template cast<complex<double> >());
  VERIFY_IS_APPROX(mcf * vf.asDiagonal(), mcf * vf.template cast<complex<float> >().asDiagonal());
  VERIFY_IS_APPROX(md * vcd.asDiagonal(), md.template cast<complex<double> >() * vcd.asDiagonal());
//   vd.asDiagonal() * mf;    // does not even compile
//   vcd.asDiagonal() * mf;   // does not even compile

  // check inner product
  VERIFY_IS_APPROX((vf.transpose() * vcf).value(), (vf.template cast<complex<float> >().transpose() * vcf).value());

  // check outer product
  VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());

  // coeff wise product

  VERIFY_IS_APPROX((vf * vcf.transpose()).eval(), (vf.template cast<complex<float> >() * vcf.transpose()).eval());

  Mat_cd mcd2 = mcd;
  VERIFY_IS_APPROX(mcd.array() *= md.array(), mcd2.array() *= md.array().template cast<std::complex<double> >());
  
  // check matrix-matrix products

  VERIFY_IS_APPROX(sd*md*mcd, (sd*md).template cast<CD>().eval()*mcd);
  VERIFY_IS_APPROX(sd*mcd*md, sd*mcd*md.template cast<CD>());
  VERIFY_IS_APPROX(scd*md*mcd, scd*md.template cast<CD>().eval()*mcd);
  VERIFY_IS_APPROX(scd*mcd*md, scd*mcd*md.template cast<CD>());
  
  VERIFY_IS_APPROX(sf*mf*mcf, sf*mf.template cast<CF>()*mcf);
  VERIFY_IS_APPROX(sf*mcf*mf, sf*mcf*mf.template cast<CF>());
  VERIFY_IS_APPROX(scf*mf*mcf, scf*mf.template cast<CF>()*mcf);
  VERIFY_IS_APPROX(scf*mcf*mf, scf*mcf*mf.template cast<CF>());
  
  VERIFY_IS_APPROX(sd*md.adjoint()*mcd, (sd*md).template cast<CD>().eval().adjoint()*mcd);
  VERIFY_IS_APPROX(sd*mcd.adjoint()*md, sd*mcd.adjoint()*md.template cast<CD>());
  VERIFY_IS_APPROX(sd*md.adjoint()*mcd.adjoint(), (sd*md).template cast<CD>().eval().adjoint()*mcd.adjoint());
  VERIFY_IS_APPROX(sd*mcd.adjoint()*md.adjoint(), sd*mcd.adjoint()*md.template cast<CD>().adjoint());
  VERIFY_IS_APPROX(sd*md*mcd.adjoint(), (sd*md).template cast<CD>().eval()*mcd.adjoint());
  VERIFY_IS_APPROX(sd*mcd*md.adjoint(), sd*mcd*md.template cast<CD>().adjoint());
  
  VERIFY_IS_APPROX(sf*mf.adjoint()*mcf, (sf*mf).template cast<CF>().eval().adjoint()*mcf);
  VERIFY_IS_APPROX(sf*mcf.adjoint()*mf, sf*mcf.adjoint()*mf.template cast<CF>());
  VERIFY_IS_APPROX(sf*mf.adjoint()*mcf.adjoint(), (sf*mf).template cast<CF>().eval().adjoint()*mcf.adjoint());
  VERIFY_IS_APPROX(sf*mcf.adjoint()*mf.adjoint(), sf*mcf.adjoint()*mf.template cast<CF>().adjoint());
  VERIFY_IS_APPROX(sf*mf*mcf.adjoint(), (sf*mf).template cast<CF>().eval()*mcf.adjoint());
  VERIFY_IS_APPROX(sf*mcf*mf.adjoint(), sf*mcf*mf.template cast<CF>().adjoint());

  VERIFY_IS_APPROX(sf*mf*vcf, (sf*mf).template cast<CF>().eval()*vcf);
  VERIFY_IS_APPROX(scf*mf*vcf,(scf*mf.template cast<CF>()).eval()*vcf);
//.........这里部分代码省略.........
开发者ID:Aerobota,项目名称:eigen,代码行数:101,代码来源:mixingtypes.cpp


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