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


C++ Mat_::total方法代码示例

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


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

示例1: writeMat

void writeMat(cv::Mat_<T>& mat, char* file){
	ofstream* ofile = new ofstream(file,ofstream::out|ofstream::binary);
	(*ofile)<<mat.rows<<" ";
	(*ofile)<<mat.cols<<" ";
	(*ofile)<<mat.type()<<" ";
	(*ofile)<<mat.total()*mat.elemSize();
	
	ofile->write((char*) mat.data,mat.total()*mat.elemSize());
	ofile->close();
}
开发者ID:bkap,项目名称:Mobile_Robotics,代码行数:10,代码来源:cvFuncs.cpp

示例2: result

cv::Mat_<cv::Vec3b> getWrongColorSegmentationImage(cv::Mat_<int>& labels, int labelcount)
{
	std::vector<cv::Vec3b> colors;
	colors.reserve(labelcount);

	std::srand(0);

	for(int i = 0; i < labelcount; ++i)
	{
		cv::Vec3b ccolor;
		ccolor[0] = std::rand() % 256;
		ccolor[1] = std::rand() % 256;
		ccolor[2] = std::rand() % 256;
		colors.push_back(ccolor);
	}

	cv::Mat result(labels.size(), CV_8UC3);

	cv::Vec3b *dst_ptr = result.ptr<cv::Vec3b>(0);
	int *src_ptr = labels[0];

	for(std::size_t i = 0; i < labels.total(); ++i)
	{
		int label = *src_ptr++;
		assert(label < (int)colors.size());
		*dst_ptr++ = colors[label];
	}
	return result;
}
开发者ID:klindworth,项目名称:disparity_estimation,代码行数:29,代码来源:segmentation.cpp

示例3: predict

float SVMClassifier::predict( const cv::Mat_<float>& z) const
{
    if ( svmp.isLinear())
        return (z.dot(linx) - b)/linx.total();  // Normalise by the vector length

    double result = -b;

    KernelThreadFunc ktf( as, kernel, xs);
    ktf.calcResult( 0, numSVs, &z);
    result += ktf.getResult();
    return result / z.total();

    /*
    static const int nthreads = boost::thread::hardware_concurrency();   // CPU threads available
    const int segSz = numSVs / nthreads;
    int rem = numSVs % nthreads;

    boost::thread_group tgroup;
    vector<KernelThreadFunc*> tobjs(nthreads);
    int segOffset = 0;
    for ( int i = 0; i < nthreads; ++i)
    {
        int ssz = segSz;
        if ( rem > 0)
        {
            ssz++;
            rem--;
        }   // end if

        tobjs[i] = new KernelThreadFunc( as, kernel, xs);
        tgroup.create_thread( boost::bind( &KernelThreadFunc::calcResult, tobjs[i], segOffset, ssz, &z));  // Start thread
        segOffset += ssz; // Offset for next thread
    }   // end for
    tgroup.join_all();    // All processing done

    // Collect the result for return
    for ( int i = 0; i < nthreads; ++i)
    {
        result += tobjs[i]->getResult();
        delete tobjs[i];
    }   // end for

    return result / z.total();   // Normalise by the vector length
    */
}   // end predict
开发者ID:richeytastic,项目名称:rlearning,代码行数:45,代码来源:SVMClassifier.cpp

示例4: convolve

	void convolve(cv::Mat_<float> &im, const int axis, const float* kernel)
	{
		if(axis >= im.dims)
			throw std::invalid_argument("Matrix dimension is too small to convolve along this axis");
		assert(im.isContinuous());
		Convolver co(im.size[axis]);
		unsigned long int step = im.step1(axis);
		//whatever the real dimension, we fall back to a 3d situation where the axis of interest is y
		//and either x or z can be of size 1
		int nbplanes = 1;
		for(int d=0; d<axis; ++d)
			nbplanes *= im.size[d];
		int planestep = im.total()/nbplanes;
		//for each plane
		for(int i=0; i<nbplanes; ++i)
			//for each line
			for(size_t j=0; j<step; ++j)
				co(reinterpret_cast<float*>(im.data) + i*planestep + j, step, kernel);
	}
开发者ID:MathieuLeocmach,项目名称:colloids,代码行数:19,代码来源:deconvolution.cpp

示例5: invalid_argument

	std::vector<float> get_spectrum_1d(const cv::Mat_<float> &im, const int axis, const bool windowing)
	{
		if(axis >= im.dims)
			throw std::invalid_argument("Matrix dimension is too small to compute the spectrum along this axis");
		assert(im.isContinuous());
		Convolver co(im.size[axis]);
		if(windowing)
			co.set_hanning();
		std::vector<float> spectrum(co.fourier_size());
		std::vector<double> tot(co.fourier_size(), 0.0);
		std::vector<std::complex<double> > totf(co.fourier_size(), 0.0);
		unsigned long int step = im.step1(axis);
		//whatever the real dimension, we fall back to a 3d situation where the axis of interest is y
		//and either x or z can be of size 1
		int nbplanes = 1;
		for(int d=0; d<axis; ++d)
			nbplanes *= im.size[d];
		int planestep = im.total()/nbplanes;
		//for each plane
		for(int i=0; i<nbplanes; ++i)
		{
			//for each line
			for(size_t j=0; j<step; ++j)
			{
				co.spectrum(reinterpret_cast<float* const>(im.data) + i*planestep + j, step, &spectrum[0]);
				for(size_t u=0; u<spectrum.size(); ++u)
					tot[u] += spectrum[u];
				for(size_t u=0; u<spectrum.size(); ++u)
					totf[u] += co.get_fourier()[u];
			}
		}
		const double icount = 1.0 / (nbplanes * step);
		for(size_t i=0; i<tot.size(); ++i)
			spectrum[i] = tot[i]*icount - std::norm(totf[i]*icount);
		return spectrum;
	}
开发者ID:MathieuLeocmach,项目名称:colloids,代码行数:36,代码来源:deconvolution.cpp

示例6: if

float singleeyefitter::cvx::histKmeans(const cv::Mat_<float>& hist, int bin_min, int bin_max, int K, float init_centres[], cv::Mat_<uchar>& labels, cv::TermCriteria termCriteria)
{
    using namespace math;

    CV_Assert( hist.rows == 1 || hist.cols == 1 && K > 0 );

    labels = cv::Mat_<uchar>::zeros(hist.size());
    int nbins = hist.total();
    float binWidth = (bin_max - bin_min)/nbins;
    float binStart = bin_min + binWidth/2;

    cv::Mat_<float> centres(K, 1, init_centres, 4);

    int iters = 0;
    bool finalRun = false;
    while (true)
    {
        ++iters;
        cv::Mat_<float> old_centres = centres.clone();

        int i_bin;
        cv::Mat_<float>::const_iterator i_hist;
        cv::Mat_<uchar>::iterator i_labels;
        cv::Mat_<float>::iterator i_centres;
        uchar label;

        float sumDist = 0;
        int movedCount = 0;

        // Step 1. Assign each element a label
        for (i_bin = 0, i_labels = labels.begin(), i_hist = hist.begin();
             i_bin < nbins;
             ++i_bin, ++i_labels, ++i_hist)
        {
            float bin_val = binStart + i_bin*binWidth;
            float minDist = sq(bin_val - centres(*i_labels));
            int curLabel = *i_labels;

            for (label = 0; label < K; ++label)
            {
                float dist = sq(bin_val - centres(label));
                if (dist < minDist)
                {
                    minDist = dist;
                    *i_labels = label;
                }
            }

            if (*i_labels != curLabel)
                movedCount++;

            sumDist += (*i_hist) * std::sqrt(minDist);
        }

        if (finalRun)
            return sumDist;

        // Step 2. Recalculate centres
        cv::Mat_<float> counts(K, 1, 0.0f);
        for (i_bin = 0, i_labels = labels.begin(), i_hist = hist.begin();
             i_bin < nbins;
             ++i_bin, ++i_labels, ++i_hist)
        {
            float bin_val = binStart + i_bin*binWidth;

            centres(*i_labels) += (*i_hist) * bin_val;
            counts(*i_labels) += *i_hist;
        }
        for (label = 0; label < K; ++label)
        {
            if (counts(label) == 0)
                return std::numeric_limits<float>::infinity();

            centres(label) /= counts(label);
        }

        // Step 3. Detect termination criteria
        if (movedCount == 0)
            finalRun = true;
        else if (termCriteria.type | cv::TermCriteria::COUNT && iters >= termCriteria.maxCount)
            finalRun = true;
        else if (termCriteria.type | cv::TermCriteria::EPS)
        {
            float max_movement = 0;
            for (label = 0; label < K; ++label)
            {
                max_movement = std::max(max_movement, sq(centres(label) - old_centres(label)));
            }
            if (sqrt(max_movement) < termCriteria.epsilon)
                finalRun = true;
        }
    }
    return std::numeric_limits<float>::infinity();
}
开发者ID:LeszekSwirski,项目名称:singleeyefitter,代码行数:94,代码来源:cvx.cpp

示例7: randomIndex

static void randomIndex(cv::Mat_<int> &randIdx)
{
    for (size_t i=0; i<randIdx.total(); i++)
        randIdx(i) = i;
    cv::randShuffle(randIdx);
}
开发者ID:serge-m,项目名称:uniform-lbp,代码行数:6,代码来源:net.cpp


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