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


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

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


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

示例1: triangulateFromUpVp

void Triangulator::triangulateFromUpVp(cv::Mat &up, cv::Mat &vp, cv::Mat &xyz){

    std::cerr << "WARNING! NOT FULLY IMPLEMENTED!" << std::endl;
    int N = up.rows * up.cols;

    cv::Mat projPointsCam(2, N, CV_32F);
    uc.reshape(0,1).copyTo(projPointsCam.row(0));
    vc.reshape(0,1).copyTo(projPointsCam.row(1));

    cv::Mat projPointsProj(2, N, CV_32F);
    up.reshape(0,1).copyTo(projPointsProj.row(0));
    vp.reshape(0,1).copyTo(projPointsProj.row(1));

    cv::Mat Pc(3,4,CV_32F,cv::Scalar(0.0));
    cv::Mat(calibration.Kc).copyTo(Pc(cv::Range(0,3), cv::Range(0,3)));

    cv::Mat Pp(3,4,CV_32F), temp(3,4,CV_32F);
    cv::Mat(calibration.Rp).copyTo(temp(cv::Range(0,3), cv::Range(0,3)));
    cv::Mat(calibration.Tp).copyTo(temp(cv::Range(0,3), cv::Range(3,4)));
    Pp = cv::Mat(calibration.Kp) * temp;

    cv::Mat xyzw;
    cv::triangulatePoints(Pc, Pp, projPointsCam, projPointsProj, xyzw);

    xyz.create(3, N, CV_32F);
    for(int i=0; i<N; i++){
        xyz.at<float>(0,i) = xyzw.at<float>(0,i)/xyzw.at<float>(3,i);
        xyz.at<float>(1,i) = xyzw.at<float>(1,i)/xyzw.at<float>(3,i);
        xyz.at<float>(2,i) = xyzw.at<float>(2,i)/xyzw.at<float>(3,i);
    }

    xyz = xyz.t();
    xyz = xyz.reshape(3, up.rows);
}
开发者ID:immermachen,项目名称:slstudio,代码行数:34,代码来源:Triangulator.cpp

示例2: removeMean

//===========================================================================
void removeMean(cv::Mat &shape, double &tx, double &ty)
{
  cv::Mat avg;
  int n = shape.rows;
  shape = shape.reshape(0,2);
  cv::reduce(shape, avg, 1, CV_REDUCE_AVG);
  shape.row(0) = shape.row(0) - avg.rl(0,0);
  shape.row(1) = shape.row(1) - avg.rl(1,0);

  shape = shape.reshape(0, n);

  tx = avg.rl(0,0);
  ty = avg.rl(1,0);
}
开发者ID:23119841,项目名称:face-analysis-sdk,代码行数:15,代码来源:Detector.cpp

示例3: _tmp

// Compute histogram and CDF for an image with mask
void Preprocessor::do1ChnHist(const cv::Mat &_i, const cv::Mat &mask, double* h, double* cdf)
{
    cv::Mat _t = _i.reshape(1,1);
    cv::Mat _tm;

    mask.copyTo(_tm);
    _tm = _tm.reshape(1,1);

    for(int p=0;p<_t.cols;p++)
    {
        if(_tm.at<uchar>(0,p) > 0)
        {
            uchar c = _t.at<uchar>(0,p);
            h[c] += 1.0;
        }
    }

    //normalize hist
    Mat _tmp(1,256,CV_64FC1,h);
    double minVal,maxVal;
    cv::minMaxLoc(_tmp,&minVal,&maxVal);
    _tmp = _tmp / maxVal;

    cdf[0] = h[0];
    for(int j=1;j<256;j++)
    {
        cdf[j] = cdf[j-1]+h[j];
    }

    //normalize CDF
    _tmp.data = (uchar*)cdf;
    cv::minMaxLoc(_tmp,&minVal,&maxVal);
    _tmp = _tmp / maxVal;
}
开发者ID:mavenx,项目名称:mopet,代码行数:35,代码来源:preprocessor.cpp

示例4: preProcessImage

void DigitRecognizer::preProcessImage(const cv::Mat& inImage, cv::Mat& outImage)
{
    cv::Mat grayImage,blurredImage,thresholdImage,contourImage,regionOfInterest;
    std::vector<std::vector<cv::Point> > contours;

    if (inImage.channels()==3) {
        cv::cvtColor(inImage,grayImage , CV_BGR2GRAY);
    } else {
        inImage.copyTo(grayImage);
    }
    blurredImage = grayImage;
    //cv::GaussianBlur(grayImage, blurredImage, cv::Size(3, 3), 2, 2);
    cv::adaptiveThreshold(blurredImage, thresholdImage, 255, cv::ADAPTIVE_THRESH_GAUSSIAN_C, cv::THRESH_BINARY_INV, 3, 0);

    int rows = thresholdImage.rows;
    int cols = thresholdImage.cols;
    for (int r=0; r<rows; r++) {
        for (int c=0; c<cols; c++) {
            uchar p = thresholdImage.at<uchar>(r,c);
            if (p==0) continue;
            bool allZeros = true;

            for (int i=-1; i<=1; i++) {
                for (int j=-1; j<=1; j++) {
                    if (i==0 && j==0) continue;
                    if (allZeros && (r+i>-1) && (r+i<rows) && (c+j>-1) && (c+j<cols)
                            && (thresholdImage.at<uchar>(r+i,c+j)==p)) {
                        allZeros = false;
                    }
                }
            }
            if (allZeros == true) {
                thresholdImage.at<uchar>(r,c) = 0;
            }
        }
    }

    thresholdImage.copyTo(contourImage);
    cv::findContours(contourImage, contours, cv::RETR_LIST, cv::CHAIN_APPROX_SIMPLE);

    int idx = 0;
    size_t area = 0;
    for (size_t i = 0; i < contours.size(); i++)
    {
        if (area < contours[i].size() )
        {
            idx = i;
            area = contours[i].size();
        }
    }

    cv::Rect rec = cv::boundingRect(contours[idx]);

    regionOfInterest = thresholdImage(rec);
    cv::resize(regionOfInterest,outImage, cv::Size(sizex, sizey));
    outImage = outImage.reshape(0, sizeimage).t();
}
开发者ID:Belial2010,项目名称:PeopleCount,代码行数:57,代码来源:digitrecognizer.cpp

示例5: rotateFlowCloud

void rotateFlowCloud(cv::Mat & out_flow, const cv::Mat & in_flow, const cv::Mat & transform_mat)
{
	Mat flow_reshaped;
	flow_reshaped = in_flow.reshape(1, in_flow.rows * in_flow.cols);

	//transform
	out_flow = transform_mat*flow_reshaped.t();
	out_flow.convertTo(out_flow, CV_32FC1);
}
开发者ID:danfeiX,项目名称:interaction_flow,代码行数:9,代码来源:flow_utils.cpp

示例6: computeDescriptorForPoints

const cv::Mat descriptor::SIFTDescriptor::ComputeDescriptor(const cv::Mat& image, const cv::Mat& position)
{
  const PointArrayPtr points = MatHelper::matToPoints(position);
  const cv::Mat descriptor = computeDescriptorForPoints(image, points);
  const cv::Mat resultDescriptor = descriptor.reshape(0, 1).t();
  
  const double kExtendedPart = 1;
  cv::Mat extendedDescriptor = resultDescriptor;
  extendedDescriptor.push_back(kExtendedPart);
  
  return extendedDescriptor;
}
开发者ID:Lokinoid,项目名称:MasterCode,代码行数:12,代码来源:SIFTDescriptor.cpp

示例7: cameraToWorld

void cameraToWorld(const cv::Mat &R_in, const cv::Mat &T_in, const cv::Mat & in_points_ori,
                   cv::Mat &points_out) {
  cv::Mat_<float> R, T, in_points;
  R_in.convertTo(R, CV_32F);
  T_in.reshape(1, 1).convertTo(T, CV_32F);
  if (in_points_ori.empty() == false)
  {
    in_points_ori.reshape(1, in_points_ori.size().area()).convertTo(in_points, CV_32F);
    cv::Mat_<float> T_repeat;
    cv::repeat(T, in_points.rows, 1, T_repeat);

    // Apply the inverse translation/rotation
    cv::Mat points = (in_points - T_repeat) * R;
    // Reshape to the original size
    points_out = points.reshape(3, in_points_ori.rows);
  }
  else
  {
    points_out = cv::Mat();
  }
}
开发者ID:edgarriba,项目名称:tod,代码行数:21,代码来源:training.cpp

示例8: median

float sg::median( cv::Mat const & matrix )
{
  cv::Mat vec = matrix.reshape( 0, 1 );
  cv::sort( vec, vec, 0 );

  size_t half = vec.cols / 2;
  float y = vec.at<float>( 0, half + 1 );

  if( ( 2 * half ) == vec.cols )
    y = ( vec.at<float>( 0, half ) + y ) / 2.0f;

  return y;
}
开发者ID:UCSD-AUVSI,项目名称:SalientGreenGPU-Deprecated,代码行数:13,代码来源:Utility.cpp

示例9: countViolations

static int countViolations(const cv::Mat& expected, const cv::Mat& actual, const cv::Mat& diff, double eps, double* max_violation = 0, double* max_allowed = 0)
{
    cv::Mat diff64f;
    diff.reshape(1).convertTo(diff64f, CV_64F);

    cv::Mat expected_abs = cv::abs(expected.reshape(1));
    cv::Mat actual_abs = cv::abs(actual.reshape(1));
    cv::Mat maximum, mask;
    cv::max(expected_abs, actual_abs, maximum);
    cv::multiply(maximum, cv::Vec<double, 1>(eps), maximum, CV_64F);
    cv::compare(diff64f, maximum, mask, cv::CMP_GT);

    int v = cv::countNonZero(mask);

    if (v > 0 && max_violation != 0 && max_allowed != 0)
    {
        int loc[10];
        cv::minMaxIdx(maximum, 0, max_allowed, 0, loc, mask);
        *max_violation = diff64f.at<double>(loc[1], loc[0]);
    }

    return v;
}
开发者ID:Belial2010,项目名称:opencv,代码行数:23,代码来源:ts_perf.cpp

示例10: transformCoordsToImage

// -----------------------------------------------------------------------------
//
// Purpose and Method: 
// Inputs: 
// Outputs: 
// Dependencies:
// Restrictions and Caveats:
//
//    The motion params are always from template to current image and with this
//    method we have to use the inverse motion model.
// -----------------------------------------------------------------------------  
cv::Mat
Homography2D::transformCoordsToTemplate
  (
  cv::Mat coords,
  cv::Mat params   
  )
{
  cv::Mat H = params.reshape(1,3).t();
  cv::Mat invH      = H.inv().t();                                        

  cv::Mat inv_params = invH.reshape(1,9);
  
  return transformCoordsToImage(coords, inv_params);  
};
开发者ID:caomw,项目名称:img_align_lib,代码行数:25,代码来源:homography_2d.cpp

示例11: randu

static void randu(cv::Mat& m)
{
    const int bigValue = 0x00000FFF;
    if (m.depth() < CV_32F)
    {
        int minmax[] = {0, 256};
        cv::Mat mr = cv::Mat(m.rows, (int)(m.cols * m.elemSize()), CV_8U, m.ptr(), m.step[0]);
        cv::randu(mr, cv::Mat(1, 1, CV_32S, minmax), cv::Mat(1, 1, CV_32S, minmax + 1));
    }
    else if (m.depth() == CV_32F)
    {
        //float minmax[] = {-FLT_MAX, FLT_MAX};
        float minmax[] = {-bigValue, bigValue};
        cv::Mat mr = m.reshape(1);
        cv::randu(mr, cv::Mat(1, 1, CV_32F, minmax), cv::Mat(1, 1, CV_32F, minmax + 1));
    }
    else
    {
        //double minmax[] = {-DBL_MAX, DBL_MAX};
        double minmax[] = {-bigValue, bigValue};
        cv::Mat mr = m.reshape(1);
        cv::randu(mr, cv::Mat(1, 1, CV_64F, minmax), cv::Mat(1, 1, CV_64F, minmax + 1));
    }
}
开发者ID:Belial2010,项目名称:opencv,代码行数:24,代码来源:ts_perf.cpp

示例12: getOffset

void getOffset(cv::Mat& src1,cv::Mat& src2,int offset[3])
{
	int ch=src1.channels();

	cv::Mat Vector1,Vector2;
	Vector1=src1.reshape(3,src1.rows*src1.cols);
	Vector2=src2.reshape(3,src2.rows*src2.cols);
	std::vector<cv::Mat> singleVector1,singleVector2;
	cv::split(Vector1,singleVector1);
	cv::split(Vector2,singleVector2);

	int iAve1[3],iAve2[3];

	for(int i=0;i<ch;i++)
	{
		cv::Mat cvAve1,cvAve2;
		cv::reduce(singleVector1[i],cvAve1,0,CV_REDUCE_AVG); 
		cv::reduce(singleVector2[i],cvAve2,0,CV_REDUCE_AVG); 

		iAve1[i]=cvAve1.at<uchar>(0.0);
		iAve2[i]=cvAve2.at<uchar>(0.0);
		offset[i]=iAve1[i]-iAve2[i];
	}
}
开发者ID:robinson1990,项目名称:Fractal,代码行数:24,代码来源:getOffset.cpp

示例13: lieAlgebraMat

	//transform coordinates in the Lie algebra basis to a matrix in the Lie group
	inline cv::Mat algebra2group(const cv::Mat &lieAlgebraCoords) const
	{
		Mat coords = lieAlgebraCoords.reshape(0, 1);
		assert( coords.cols == basis.size() );
		assert( coords.type() == CV_64FC1 );

		const int dim = 3;
		Mat lieAlgebraMat(dim, dim, CV_64F, Scalar(0));
		for (size_t i = 0; i < basis.size(); i++) {
			lieAlgebraMat += basis[i].vector2mat(coords.at<double> (0, i));
		}

		Mat lieGroupMat = matrixExp(lieAlgebraMat);
		return lieGroupMat;
	}
开发者ID:SkyRiderMike,项目名称:cv2cg,代码行数:16,代码来源:lie_algebra.hpp

示例14: corruptSaltPepper

void corruptSaltPepper(cv::Mat& img, const float ratio)
{
    std::srand((unsigned int)std::time(0));

    cv::Mat imgv = img.reshape(0, 1);

    for (int i = 0; i < img.cols * img.rows; i++)
    {
        const float rnd = (std::rand() % 10000) / 10000.0f;

        if (rnd <= ratio / 2.0f) {
            imgv.at<float>(i) = 0;
        } else if (rnd <= ratio) {
            imgv.at<float>(i) = 1;
        }
    }
}
开发者ID:fundamental,项目名称:sparsecoding,代码行数:17,代码来源:main.cpp

示例15: calcGradientMagnitude

cv::Mat EyeTrackProcessor::calcGradientMagnitude( const cv::Mat& im ) {
  
  // Convert gradient to vector of points
  cv::Mat grad;
  grad = im.reshape(1, im.rows*im.cols);
  cv::Mat gradMag(grad.rows, 1, CV_64FC1);
  std::vector<cv::Point2d> gradPts;
  for ( int i=0; i<grad.rows; i++) {
    gradPts.push_back(cv::Point2d(grad.at<double>(i,0), grad.at<double>(i,1)));
  }
  for ( int i=0; i<gradPts.size(); ++i ) {
    auto normVal = cv::norm(gradPts[i]);
    // gradPt *= (normVal == 0) ? 0 : 1/cv::norm(gradPt);
    gradMag.at<double>(i) = normVal;
  }
  gradMag = gradMag.reshape( 0, im.rows );
  return gradMag;
}
开发者ID:AndreySheka,项目名称:NaCl,代码行数:18,代码来源:processor_eyetrack.cpp


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