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


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

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


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

示例1: blurRemoveMinMax_

	void blurRemoveMinMax_(const Mat& src, Mat& dest, const int r)
	{
		const Size ksize = Size(2 * r + 1, 2 * r + 1);
		if (src.data != dest.data)src.copyTo(dest);

		Mat xv;
		Mat nv;
		Mat element = Mat::ones(2 * r + 1, 2 * r + 1, CV_8U);
		dilate(src, xv, element);
		erode(src, nv, element);

		Mat mind;
		Mat maxd;
		Mat mask;
		absdiff(src, nv, mind);//can move to loop
		absdiff(src, xv, maxd);//
		min(mind, maxd, mask);//

		T* n = nv.ptr<T>(0);
		T* x = xv.ptr<T>(0);
		T* d = dest.ptr<T>(0);
		T* nd = mind.ptr<T>(0);
		T* mk = mask.ptr<T>(0);

		int remsize = src.size().area();

#if CV_SSE4_1
		if (src.depth() == CV_8U)
		{

			const int ssesize = src.size().area() / 16;
			remsize = src.size().area() - ssesize * 16;
			for (int i = 0; i < ssesize; i++)
			{
				__m128i mmk = _mm_load_si128((__m128i*)mk);
				__m128i mnd = _mm_load_si128((__m128i*)nd);

				__m128i mmn = _mm_load_si128((__m128i*)n);
				__m128i mmx = _mm_load_si128((__m128i*)x);
				__m128i msk = _mm_cmpeq_epi8(mnd, mmk);
				_mm_stream_si128((__m128i*)d, _mm_blendv_epi8(mmx, mmn, msk));
				nd += 16;
				mk += 16;
				d += 16;
				n += 16;
				x += 16;
			}
		}
		else if (src.depth() == CV_16S || src.depth() == CV_16U)
		{

			const int ssesize = src.size().area() / 8;
			remsize = src.size().area() - ssesize * 8;
			for (int i = 0; i < ssesize; i++)
			{
				__m128i mmk = _mm_load_si128((__m128i*)mk);
				__m128i mnd = _mm_load_si128((__m128i*)nd);

				__m128i mmn = _mm_load_si128((__m128i*)n);
				__m128i mmx = _mm_load_si128((__m128i*)x);
				__m128i msk = _mm_cmpeq_epi16(mnd, mmk);
				_mm_stream_si128((__m128i*)d, _mm_blendv_epi8(mmx, mmn, msk));
				nd += 8;
				mk += 8;
				d += 8;
				n += 8;
				x += 8;
			}
		}
		else if (src.depth() == CV_32F)
		{

			const int ssesize = src.size().area() / 4;
			remsize = src.size().area() - ssesize * 4;
			for (int i = 0; i < ssesize; i++)
			{
				__m128 mmk = _mm_load_ps((float*)mk);
				__m128 mnd = _mm_load_ps((float*)nd);

				__m128 mmn = _mm_load_ps((float*)n);
				__m128 mmx = _mm_load_ps((float*)x);
				__m128 msk = _mm_cmpeq_ps(mnd, mmk);
				_mm_stream_ps((float*)d, _mm_blendv_ps(mmx, mmn, msk));
				nd += 4;
				mk += 4;
				d += 4;
				n += 4;
				x += 4;
			}
		}
		else if (src.depth() == CV_64F)
		{
			const int ssesize = src.size().area() / 2;
			remsize = src.size().area() - ssesize * 2;
			for (int i = 0; i < ssesize; i++)
			{
				__m128d mmk = _mm_load_pd((double*)mk);
				__m128d mnd = _mm_load_pd((double*)nd);

				__m128d mmn = _mm_load_pd((double*)n);
//.........这里部分代码省略.........
开发者ID:ArtisticCoding,项目名称:OpenCP,代码行数:101,代码来源:minmaxfilter.cpp

示例2: getMaxVal

	float getMaxVal(const Mat& mat) {
		return getMaxVal(mat.depth());
	}
开发者ID:olekristensen,项目名称:ledDaylight,代码行数:3,代码来源:CvUtilities.cpp

示例3: fprintf

bool  Jpeg2KDecoder::readData(Mat& img) {
    bool result = false;
    int color = img.channels() > 1;
    uchar* data = img.data;
    int step = img.step;
    jas_stream_t* stream = (jas_stream_t*)m_stream;
    jas_image_t* image = (jas_image_t*)m_image;

    if (stream && image) {
        bool convert;
        int colorspace;
        if (color) {
            convert = (jas_image_clrspc(image) != JAS_CLRSPC_SRGB);
            colorspace = JAS_CLRSPC_SRGB;
        } else {
            convert = (jas_clrspc_fam(jas_image_clrspc(image)) != JAS_CLRSPC_FAM_GRAY);
            colorspace = JAS_CLRSPC_SGRAY; // TODO GENGRAY or SGRAY?
        }

        // convert to the desired colorspace
        if (convert) {
            jas_cmprof_t* clrprof = jas_cmprof_createfromclrspc(colorspace);
            if (clrprof) {
                jas_image_t* _img = jas_image_chclrspc(image, clrprof, JAS_CMXFORM_INTENT_RELCLR);
                if (_img) {
                    jas_image_destroy(image);
                    m_image = image = _img;
                    result = true;
                } else {
                    fprintf(stderr, "JPEG 2000 LOADER ERROR: cannot convert colorspace\n");
                }
                jas_cmprof_destroy(clrprof);
            } else {
                fprintf(stderr, "JPEG 2000 LOADER ERROR: unable to create colorspace\n");
            }
        } else {
            result = true;
        }

        if (result) {
            int ncmpts;
            int cmptlut[3];
            if (color) {
                cmptlut[0] = jas_image_getcmptbytype(image, JAS_IMAGE_CT_RGB_B);
                cmptlut[1] = jas_image_getcmptbytype(image, JAS_IMAGE_CT_RGB_G);
                cmptlut[2] = jas_image_getcmptbytype(image, JAS_IMAGE_CT_RGB_R);
                if (cmptlut[0] < 0 || cmptlut[1] < 0 || cmptlut[0] < 0) {
                    result = false;
                }
                ncmpts = 3;
            } else {
                cmptlut[0] = jas_image_getcmptbytype(image, JAS_IMAGE_CT_GRAY_Y);
                if (cmptlut[0] < 0) {
                    result = false;
                }
                ncmpts = 1;
            }

            if (result) {
                for (int i = 0; i < ncmpts; i++) {
                    int maxval = 1 << jas_image_cmptprec(image, cmptlut[i]);
                    int offset =  jas_image_cmptsgnd(image, cmptlut[i]) ? maxval / 2 : 0;

                    int yend = jas_image_cmptbry(image, cmptlut[i]);
                    int ystep = jas_image_cmptvstep(image, cmptlut[i]);
                    int xend = jas_image_cmptbrx(image, cmptlut[i]);
                    int xstep = jas_image_cmpthstep(image, cmptlut[i]);

                    jas_matrix_t* buffer = jas_matrix_create(yend / ystep, xend / xstep);
                    if (buffer) {
                        if (!jas_image_readcmpt(image, cmptlut[i], 0, 0, xend / xstep, yend / ystep, buffer)) {
                            if (img.depth() == CV_8U) {
                                result = readComponent8u(data + i, buffer, step, cmptlut[i], maxval, offset, ncmpts);
                            } else {
                                result = readComponent16u(((unsigned short*)data) + i, buffer, step / 2, cmptlut[i], maxval, offset, ncmpts);
                            }
                            if (!result) {
                                i = ncmpts;
                                result = false;
                            }
                        }
                        jas_matrix_destroy(buffer);
                    }
                }
            }
        } else {
            fprintf(stderr, "JPEG2000 LOADER ERROR: colorspace conversion failed\n");
        }
    }

    close();

    return result;
}
开发者ID:353,项目名称:viewercv,代码行数:94,代码来源:grfmt_jpeg2000.cpp

示例4: solvePnPRansac

bool cv::solvePnPRansac(InputArray _opoints, InputArray _ipoints,
                        InputArray _cameraMatrix, InputArray _distCoeffs,
                        OutputArray _rvec, OutputArray _tvec, bool useExtrinsicGuess,
                        int iterationsCount, float reprojectionError, double confidence,
                        OutputArray _inliers, int flags)
{

    Mat opoints = _opoints.getMat(), ipoints = _ipoints.getMat();

    int npoints = std::max(opoints.checkVector(3, CV_32F), opoints.checkVector(3, CV_64F));
    CV_Assert( npoints >= 0 && npoints == std::max(ipoints.checkVector(2, CV_32F), ipoints.checkVector(2, CV_64F)) );

    CV_Assert(opoints.isContinuous());
    CV_Assert(opoints.depth() == CV_32F || opoints.depth() == CV_64F);
    CV_Assert((opoints.rows == 1 && opoints.channels() == 3) || opoints.cols*opoints.channels() == 3);
    CV_Assert(ipoints.isContinuous());
    CV_Assert(ipoints.depth() == CV_32F || ipoints.depth() == CV_64F);
    CV_Assert((ipoints.rows == 1 && ipoints.channels() == 2) || ipoints.cols*ipoints.channels() == 2);

    _rvec.create(3, 1, CV_64FC1);
    _tvec.create(3, 1, CV_64FC1);

    Mat rvec = useExtrinsicGuess ? _rvec.getMat() : Mat(3, 1, CV_64FC1);
    Mat tvec = useExtrinsicGuess ? _tvec.getMat() : Mat(3, 1, CV_64FC1);
    Mat cameraMatrix = _cameraMatrix.getMat(), distCoeffs = _distCoeffs.getMat();

    Ptr<PointSetRegistrator::Callback> cb; // pointer to callback
    cb = makePtr<PnPRansacCallback>( cameraMatrix, distCoeffs, flags, useExtrinsicGuess, rvec, tvec);

    int model_points = 4;                             // minimum of number of model points
    if( flags == cv::SOLVEPNP_ITERATIVE ) model_points = 6;
    else if( flags == cv::SOLVEPNP_UPNP ) model_points = 6;
    else if( flags == cv::SOLVEPNP_EPNP ) model_points = 5;

    double param1 = reprojectionError;                // reprojection error
    double param2 = confidence;                       // confidence
    int param3 = iterationsCount;                     // number maximum iterations

    cv::Mat _local_model(3, 2, CV_64FC1);
    cv::Mat _mask_local_inliers(1, opoints.rows, CV_8UC1);

    // call Ransac
    int result = createRANSACPointSetRegistrator(cb, model_points, param1, param2, param3)->run(opoints, ipoints, _local_model, _mask_local_inliers);

    if( result <= 0 || _local_model.rows <= 0)
    {
        _rvec.assign(rvec);    // output rotation vector
        _tvec.assign(tvec);    // output translation vector

        if( _inliers.needed() )
            _inliers.release();

        return false;
    }
    else
    {
        _rvec.assign(_local_model.col(0));    // output rotation vector
        _tvec.assign(_local_model.col(1));    // output translation vector
    }

    if(_inliers.needed())
    {
        Mat _local_inliers;
        int count = 0;
        for (int i = 0; i < _mask_local_inliers.rows; ++i)
        {
            if((int)_mask_local_inliers.at<uchar>(i) == 1) // inliers mask
            {
                _local_inliers.push_back(count);    // output inliers vector
                count++;
            }
        }
        _local_inliers.copyTo(_inliers);
    }
    return true;
}
开发者ID:AdLantis,项目名称:opencv,代码行数:76,代码来源:solvepnp.cpp

示例5: test_threshold

static void test_threshold( const Mat& _src, Mat& _dst,
                            float thresh, float maxval, int thresh_type )
{
    int i, j;
    int depth = _src.depth(), cn = _src.channels();
    int width_n = _src.cols*cn, height = _src.rows;
    int ithresh = cvFloor(thresh);
    int imaxval, ithresh2;
    
    if( depth == CV_8U )
    {
        ithresh2 = saturate_cast<uchar>(ithresh);
        imaxval = saturate_cast<uchar>(maxval);
    }
    else if( depth == CV_16S )
    {
        ithresh2 = saturate_cast<short>(ithresh);
        imaxval = saturate_cast<short>(maxval);
    }
    else
    {
        ithresh2 = cvRound(ithresh);
        imaxval = cvRound(maxval);
    }

    assert( depth == CV_8U || depth == CV_16S || depth == CV_32F );
    
    switch( thresh_type )
    {
    case CV_THRESH_BINARY:
        for( i = 0; i < height; i++ )
        {
            if( depth == CV_8U )
            {
                const uchar* src = _src.ptr<uchar>(i);
                uchar* dst = _dst.ptr<uchar>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = (uchar)(src[j] > ithresh ? imaxval : 0);
            }
            else if( depth == CV_16S )
            {
                const short* src = _src.ptr<short>(i);
                short* dst = _dst.ptr<short>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = (short)(src[j] > ithresh ? imaxval : 0);
            }
            else
            {
                const float* src = _src.ptr<float>(i);
                float* dst = _dst.ptr<float>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = src[j] > thresh ? maxval : 0.f;
            }
        }
        break;
    case CV_THRESH_BINARY_INV:
        for( i = 0; i < height; i++ )
        {
            if( depth == CV_8U )
            {
                const uchar* src = _src.ptr<uchar>(i);
                uchar* dst = _dst.ptr<uchar>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = (uchar)(src[j] > ithresh ? 0 : imaxval);
            }
            else if( depth == CV_16S )
            {
                const short* src = _src.ptr<short>(i);
                short* dst = _dst.ptr<short>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = (short)(src[j] > ithresh ? 0 : imaxval);
            }
            else
            {
                const float* src = _src.ptr<float>(i);
                float* dst = _dst.ptr<float>(i);
                for( j = 0; j < width_n; j++ )
                    dst[j] = src[j] > thresh ? 0.f : maxval;
            }
        }
        break;
    case CV_THRESH_TRUNC:
        for( i = 0; i < height; i++ )
        {
            if( depth == CV_8U )
            {
                const uchar* src = _src.ptr<uchar>(i);
                uchar* dst = _dst.ptr<uchar>(i);
                for( j = 0; j < width_n; j++ )
                {
                    int s = src[j];
                    dst[j] = (uchar)(s > ithresh ? ithresh2 : s);
                }
            }
            else if( depth == CV_16S )
            {
                const short* src = _src.ptr<short>(i);
                short* dst = _dst.ptr<short>(i);
                for( j = 0; j < width_n; j++ )
                {
//.........这里部分代码省略.........
开发者ID:Ashwini7,项目名称:smart-python-programs,代码行数:101,代码来源:test_thresh.cpp

示例6: localMeanThreshold

// prepare a photo with CLBP_M (Completed LBP-Magnitude)
void expression_recognizer::localMeanThreshold(Mat& face, int A, int B, int P, float phase) {
	CV_Assert( face.depth() == CV_8U );
	CV_Assert( face.size().width == 48 && face.size().height == 60 );
	CV_Assert( A > 0 && B > 0 && P > 0 );

	if (A != currA || B != currB || P != currP || currPhase != phase) updateELBPkernel( A,B,P,phase );

	unsigned int fw = face.size().width;
	unsigned int fh = face.size().height;
	unsigned int marginal = (currA >= currB) ? currA : currB;

	Mat local_mean = Mat(face.size(), CV_32F);
	float total_mean=0;

	copyMakeBorder(face,face,marginal,marginal,marginal,marginal,BORDER_REPLICATE); //replication difference = 0

	// local difference mean per pixel
	for (unsigned int y = marginal; y<fh+marginal; y++) {
		for (unsigned int x = marginal; x<fw+marginal; x++) {
			float sum=0;
			access(uchar, face,y, x);
			uchar center = face.at<uchar>(y,x);

			for (unsigned int i=0; i<currP; i++) {
				unsigned int relx = ELBP_coords[i].x+x;
				unsigned int rely = ELBP_coords[i].y+y;

				access( uchar, face, rely, relx )
				uchar cmp = face.at<uchar>(rely,relx);
				sum += (float)abs(center - cmp);
			}

			sum /= (float)currP;
			access( float, local_mean, y-marginal, x-marginal )
			local_mean.at<float>(y-marginal,x-marginal) = sum;
			total_mean += sum;
		}
	}
	total_mean /= local_mean.size().area();
	//LOGD("debug: total mean %f", total_mean);

	// ELBP
	face.convertTo(face, CV_16U);
	unsigned short ELBP_code = 0;
	copyMakeBorder(local_mean,local_mean,marginal,marginal,marginal,marginal,BORDER_REPLICATE);

	for (unsigned int y=marginal;y<fh+marginal;y++) {
		for (unsigned int x=marginal;x<fw+marginal;x++) {
			ELBP_code = 0;

			for (unsigned int i=0; i<currP; i++) {
				unsigned int relx = ELBP_coords[i].x+x;
				unsigned int rely = ELBP_coords[i].y+y;

				access( float, local_mean, rely, relx )
				if (local_mean.at<float>(rely,relx) >= total_mean) ELBP_code += powtable[i];
			}

			access( unsigned short, face, y-marginal, x-marginal )
			face.at<unsigned short>(y-marginal,x-marginal) = ELBP_code;
		}
	}

	face = face.colRange(0, fw).rowRange(0, fh);
}
开发者ID:siperia,项目名称:PeopleInPhotos,代码行数:66,代码来源:expressionrecognizer.cpp

示例7: gaborLBPHistograms

// Filteres a face picture with 40 Gabor-filters, arranging the results into 3D-array-like
// structure and runs 3D-LBP operation on them. Outputs an idetification histogram after
// segmentation and concatenation in left-right, top-down order.
// If step is 0 or 1 returns a debug picture in "face". ind = index per (freq*orientation)+rot
void expression_recognizer::gaborLBPHistograms(Mat& face, Mat& hist, Mat& lut, int N, int step, int ind) {
	CV_Assert( face.depth() == CV_8U );
	CV_Assert( face.channels() == 1 );

	CV_Assert( lut.depth() == CV_8U );
	CV_Assert( lut.channels() == 1 );
	CV_Assert( lut.total() == 256 );
	CV_Assert( lut.isContinuous() );

	Mat tmppic = Mat( Size(64, 64), CV_64FC2);
	Mat holder = Mat( Size(64, 64), CV_64FC1);

	vector<Mat> planes;
	resize(face, face, Size(64,64));
	//face = face.colRange(8,80);//.clone();
	vector<Mat> doubleface;
	face.convertTo(face, CV_64FC2);

	int m = getOptimalDFTSize( face.size().height );
	int n = getOptimalDFTSize( face.size().width );
	copyMakeBorder(face, face, 0, m - face.size().height, 0, n - face.size().width, BORDER_CONSTANT, Scalar::all(0));

	doubleface.clear();
	doubleface.push_back(face);
	doubleface.push_back(face);
	merge( doubleface, face );

	dft(face, face, DFT_COMPLEX_OUTPUT + DFT_SCALE, 0);

	vector<Mat> gaborCube(scale*orientation);
	vector<Mat> binaryGaborVolume;
	for (unsigned int freq=0;freq<scale;freq++) {
		for (unsigned int rot=0;rot<orientation;rot++) {
			unsigned int index = (freq*orientation)+rot;

			Mat tmp = gaborKernels[index];
			mulSpectrums(face, tmp, tmppic, 0, false);
			idft(tmppic, tmppic, DFT_SCALE, 0);

			planes.clear();
			split(tmppic, planes);
			Mat p0=planes[0];
			Mat p1=planes[1];
			magnitude(p0,p1,holder);
			//holder = holder.colRange(0, 64).rowRange(0,64);
			// From real and imaginary parts we can get the magnitude for identification
			// add 1px borders for later, store in gabor-cube

			copyMakeBorder(holder, holder,1, 1, 1, 1, BORDER_CONSTANT, Scalar::all(0));
			gaborCube[index] = holder.clone();
		}
	}

	if (step == 0) face = gaborCube[ind];

	vector<Mat> LBP;
	Mat lbp = Mat(64,64,CV_8U);

	for (unsigned int freq=0;freq<scale;freq++) {
		for (unsigned int rot=0;rot<orientation;rot++) {

			unsigned int index = rot+(freq*orientation);
			Mat thiz = gaborCube[index];
			uchar pix = 0;

			for (unsigned int y=1;y<thiz.size().height-1;y++) {
				for (unsigned int x=1;x<thiz.size().width-1;x++) {
					pix = 0;
					double center = thiz.at<double>(y,x);

					// indices 1,3,5 and 7 are normal closest neighbor LBP
					if (thiz.at<double>(y-1,x) >= center ) pix += powtable[1];
					if (thiz.at<double>(y,x+1) >= center ) pix += powtable[3];
					if (thiz.at<double>(y+1,x) >= center ) pix += powtable[5];
					if (thiz.at<double>(y,x-1) >= center ) pix += powtable[7];

					// orientation neighbors are indices 2 and 6
					if (rot > 0) {
						Mat back = gaborCube[index-1];
						if ( back.at<double>(y,x) >= center ) pix += powtable[2];
					}
					if (rot < orientation-1) {
						Mat front = gaborCube[index+1];
						if ( front.at<double>(y,x) >= center ) pix += powtable[6];
					}
					//scale neighbors, indices 0,4
					if (freq > 0 ) {
						Mat back = gaborCube[index-orientation];
						if ( back.at<double>(y,x) >= center) pix += powtable[0];
					}

					if (freq < scale-1) {
						Mat front = gaborCube[index+orientation];
						if ( front.at<double>(y,x) >= center) pix += powtable[4];
					}

//.........这里部分代码省略.........
开发者ID:siperia,项目名称:PeopleInPhotos,代码行数:101,代码来源:expressionrecognizer.cpp

示例8: operator

void SIFT::operator()(InputArray _image, InputArray _mask,
                      vector<KeyPoint>& keypoints,
                      OutputArray _descriptors,
                      bool useProvidedKeypoints) const
{
    int firstOctave = -1, actualNOctaves = 0, actualNLayers = 0;
    Mat image = _image.getMat(), mask = _mask.getMat();

    if( image.empty() || image.depth() != CV_8U )
        CV_Error( CV_StsBadArg, "image is empty or has incorrect depth (!=CV_8U)" );

    if( !mask.empty() && mask.type() != CV_8UC1 )
        CV_Error( CV_StsBadArg, "mask has incorrect type (!=CV_8UC1)" );

    if( useProvidedKeypoints )
    {
        firstOctave = 0;
        int maxOctave = INT_MIN;
        for( size_t i = 0; i < keypoints.size(); i++ )
        {
            int octave, layer;
            float scale;
            unpackOctave(keypoints[i], octave, layer, scale);
            firstOctave = std::min(firstOctave, octave);
            maxOctave = std::max(maxOctave, octave);
            actualNLayers = std::max(actualNLayers, layer-2);
        }

        firstOctave = std::min(firstOctave, 0);
        CV_Assert( firstOctave >= -1 && actualNLayers <= nOctaveLayers );
        actualNOctaves = maxOctave - firstOctave + 1;
    }

    Mat base = createInitialImage(image, firstOctave < 0, (float)sigma);
    vector<Mat> gpyr, dogpyr;
    int nOctaves = actualNOctaves > 0 ? actualNOctaves : cvRound(log( (double)std::min( base.cols, base.rows ) ) / log(2.) - 2) - firstOctave;

    //double t, tf = getTickFrequency();
    //t = (double)getTickCount();
    buildGaussianPyramid(base, gpyr, nOctaves);
    buildDoGPyramid(gpyr, dogpyr);

    //t = (double)getTickCount() - t;
    //printf("pyramid construction time: %g\n", t*1000./tf);

    if( !useProvidedKeypoints )
    {
        //t = (double)getTickCount();
        findScaleSpaceExtrema(gpyr, dogpyr, keypoints);
        KeyPointsFilter::removeDuplicated( keypoints );

        if( nfeatures > 0 )
            KeyPointsFilter::retainBest(keypoints, nfeatures);
        //t = (double)getTickCount() - t;
        //printf("keypoint detection time: %g\n", t*1000./tf);

        if( firstOctave < 0 )
            for( size_t i = 0; i < keypoints.size(); i++ )
            {
                KeyPoint& kpt = keypoints[i];
                float scale = 1.f/(float)(1 << -firstOctave);
                kpt.octave = (kpt.octave & ~255) | ((kpt.octave + firstOctave) & 255);
                kpt.pt *= scale;
                kpt.size *= scale;
            }

        if( !mask.empty() )
            KeyPointsFilter::runByPixelsMask( keypoints, mask );
    }
    else
    {
        // filter keypoints by mask
        //KeyPointsFilter::runByPixelsMask( keypoints, mask );
    }

    if( _descriptors.needed() )
    {
        //t = (double)getTickCount();
        int dsize = descriptorSize();
        _descriptors.create((int)keypoints.size(), dsize, CV_32F);
        Mat descriptors = _descriptors.getMat();

        calcDescriptors(gpyr, keypoints, descriptors, nOctaveLayers, firstOctave);
        //t = (double)getTickCount() - t;
        //printf("descriptor extraction time: %g\n", t*1000./tf);
    }
}
开发者ID:AlexTape,项目名称:OpenMakaAndroid,代码行数:87,代码来源:sift.cpp

示例9: readData

bool  PngDecoder::readData( Mat& img )
{
    bool result = false;
    AutoBuffer<uchar*> _buffer(m_height);
    uchar** buffer = _buffer;
    int color = img.channels() > 1;
    uchar* data = img.data;
    int step = (int)img.step;

    if( m_png_ptr && m_info_ptr && m_end_info && m_width && m_height )
    {
        png_structp png_ptr = (png_structp)m_png_ptr;
        png_infop info_ptr = (png_infop)m_info_ptr;
        png_infop end_info = (png_infop)m_end_info;

        if( setjmp( png_jmpbuf ( png_ptr ) ) == 0 )
        {
            int y;

            if( img.depth() == CV_8U && m_bit_depth == 16 )
                png_set_strip_16( png_ptr );
            else if( !isBigEndian() )
                png_set_swap( png_ptr );

            if(img.channels() < 4)
            {
                /* observation: png_read_image() writes 400 bytes beyond
                 * end of data when reading a 400x118 color png
                 * "mpplus_sand.png".  OpenCV crashes even with demo
                 * programs.  Looking at the loaded image I'd say we get 4
                 * bytes per pixel instead of 3 bytes per pixel.  Test
                 * indicate that it is a good idea to always ask for
                 * stripping alpha..  18.11.2004 Axel Walthelm
                 */
                 png_set_strip_alpha( png_ptr );
            }

            if( m_color_type == PNG_COLOR_TYPE_PALETTE )
                png_set_palette_to_rgb( png_ptr );

            if( m_color_type == PNG_COLOR_TYPE_GRAY && m_bit_depth < 8 )
#if (PNG_LIBPNG_VER_MAJOR*10000 + PNG_LIBPNG_VER_MINOR*100 + PNG_LIBPNG_VER_RELEASE >= 10209) || \
    (PNG_LIBPNG_VER_MAJOR == 1 && PNG_LIBPNG_VER_MINOR == 0 && PNG_LIBPNG_VER_RELEASE >= 18)
                png_set_expand_gray_1_2_4_to_8( png_ptr );
#else
                png_set_gray_1_2_4_to_8( png_ptr );
#endif

            if( CV_MAT_CN(m_type) > 1 && color )
                png_set_bgr( png_ptr ); // convert RGB to BGR
            else if( color )
                png_set_gray_to_rgb( png_ptr ); // Gray->RGB
            else
                png_set_rgb_to_gray( png_ptr, 1, 0.299, 0.587 ); // RGB->Gray

            png_read_update_info( png_ptr, info_ptr );

            for( y = 0; y < m_height; y++ )
                buffer[y] = data + y*step;

            png_read_image( png_ptr, buffer );
            png_read_end( png_ptr, end_info );

            result = true;
        }
    }

    close();
    return result;
}
开发者ID:BRAINSia,项目名称:OpenCV_TruncatedSVN,代码行数:70,代码来源:grfmt_png.cpp

示例10: convertFromCCS

static void convertFromCCS( const Mat& _src0, const Mat& _src1, Mat& _dst, int flags )
{
    if( _dst.rows > 1 && (_dst.cols > 1 || (flags & DFT_ROWS)) )
    {
        int i, count = _dst.rows, len = _dst.cols;
        bool is2d = (flags & DFT_ROWS) == 0;
        Mat src0row, src1row, dstrow;
        for( i = 0; i < count; i++ )
        {
            int j = !is2d || i == 0 ? i : count - i;
            src0row = _src0.row(i);
            src1row = _src1.row(j);
            dstrow = _dst.row(i);
            convertFromCCS( src0row, src1row, dstrow, 0 );
        }

        if( is2d )
        {
            src0row = _src0.col(0);
            dstrow = _dst.col(0);
            convertFromCCS( src0row, src0row, dstrow, 0 );
            if( (len & 1) == 0 )
            {
                src0row = _src0.col(_src0.cols - 1);
                dstrow = _dst.col(len/2);
                convertFromCCS( src0row, src0row, dstrow, 0 );
            }
        }
    }
    else
    {
        int i, n = _dst.cols + _dst.rows - 1, n2 = (n+1) >> 1;
        int cn = _src0.channels();
        int srcstep = cn, dststep = 1;

        if( !_dst.isContinuous() )
            dststep = (int)(_dst.step/_dst.elemSize());

        if( !_src0.isContinuous() )
            srcstep = (int)(_src0.step/_src0.elemSize1());

        if( _dst.depth() == CV_32F )
        {
            Complexf* dst = _dst.ptr<Complexf>();
            const float* src0 = _src0.ptr<float>();
            const float* src1 = _src1.ptr<float>();
            int delta0, delta1;

            dst->re = src0[0];
            dst->im = 0;

            if( (n & 1) == 0 )
            {
                dst[n2*dststep].re = src0[(cn == 1 ? n-1 : n2)*srcstep];
                dst[n2*dststep].im = 0;
            }

            delta0 = srcstep;
            delta1 = delta0 + (cn == 1 ? srcstep : 1);
            if( cn == 1 )
                srcstep *= 2;

            for( i = 1; i < n2; i++, delta0 += srcstep, delta1 += srcstep )
            {
                float t0 = src0[delta0];
                float t1 = src0[delta1];

                dst[i*dststep].re = t0;
                dst[i*dststep].im = t1;

                t0 = src1[delta0];
                t1 = -src1[delta1];

                dst[(n-i)*dststep].re = t0;
                dst[(n-i)*dststep].im = t1;
            }
        }
        else
        {
            Complexd* dst = _dst.ptr<Complexd>();
            const double* src0 = _src0.ptr<double>();
            const double* src1 = _src1.ptr<double>();
            int delta0, delta1;

            dst->re = src0[0];
            dst->im = 0;

            if( (n & 1) == 0 )
            {
                dst[n2*dststep].re = src0[(cn == 1 ? n-1 : n2)*srcstep];
                dst[n2*dststep].im = 0;
            }

            delta0 = srcstep;
            delta1 = delta0 + (cn == 1 ? srcstep : 1);
            if( cn == 1 )
                srcstep *= 2;

            for( i = 1; i < n2; i++, delta0 += srcstep, delta1 += srcstep )
            {
//.........这里部分代码省略.........
开发者ID:007Indian,项目名称:opencv,代码行数:101,代码来源:test_dxt.cpp

示例11: mulComplex

static void mulComplex( const Mat& src1, const Mat& src2, Mat& dst, int flags )
{
    dst.create(src1.rows, src1.cols, src1.type());
    int i, j, depth = src1.depth(), cols = src1.cols*2;

    CV_Assert( src1.size == src2.size && src1.type() == src2.type() &&
              (src1.type() == CV_32FC2 || src1.type() == CV_64FC2) );

    for( i = 0; i < dst.rows; i++ )
    {
        if( depth == CV_32F )
        {
            const float* a = src1.ptr<float>(i);
            const float* b = src2.ptr<float>(i);
            float* c = dst.ptr<float>(i);

            if( !(flags & CV_DXT_MUL_CONJ) )
                for( j = 0; j < cols; j += 2 )
                {
                    double re = (double)a[j]*(double)b[j] - (double)a[j+1]*(double)b[j+1];
                    double im = (double)a[j+1]*(double)b[j] + (double)a[j]*(double)b[j+1];

                    c[j] = (float)re;
                    c[j+1] = (float)im;
                }
            else
                for( j = 0; j < cols; j += 2 )
                {
                    double re = (double)a[j]*(double)b[j] + (double)a[j+1]*(double)b[j+1];
                    double im = (double)a[j+1]*(double)b[j] - (double)a[j]*(double)b[j+1];

                    c[j] = (float)re;
                    c[j+1] = (float)im;
                }
        }
        else
        {
            const double* a = src1.ptr<double>(i);
            const double* b = src2.ptr<double>(i);
            double* c = dst.ptr<double>(i);

            if( !(flags & CV_DXT_MUL_CONJ) )
                for( j = 0; j < cols; j += 2 )
                {
                    double re = a[j]*b[j] - a[j+1]*b[j+1];
                    double im = a[j+1]*b[j] + a[j]*b[j+1];

                    c[j] = re;
                    c[j+1] = im;
                }
            else
                for( j = 0; j < cols; j += 2 )
                {
                    double re = a[j]*b[j] + a[j+1]*b[j+1];
                    double im = a[j+1]*b[j] - a[j]*b[j+1];

                    c[j] = re;
                    c[j+1] = im;
                }
        }
    }
}
开发者ID:007Indian,项目名称:opencv,代码行数:62,代码来源:test_dxt.cpp

示例12: imgInfo

//Prints basic info about image
void imgInfo(const Mat& img){
	std::cout << "Type: " << img.type()
					<<"  Channels: " << img.channels()
					<< "   Depth:" << img.depth()
					<< std::endl;
}
开发者ID:EDDISCODE,项目名称:EDD-App,代码行数:7,代码来源:TestUtils.cpp

示例13: replaceFace

void replaceFace(Mat &faceFrame,FaceCartoon faceCartoon){

	stringstream ss;
	ss.str("");
	string tempCartoonNum;
	ss << (faceCartoon.cartoonMatchNum + 1);
	ss >> tempCartoonNum;
	Mat srcImg = imread(prefixTest + tempCartoonNum + subfix);
	Mat src_mask = Mat::zeros(srcImg.rows, srcImg.cols, srcImg.depth());
	Mat srcResize;
	Mat src_mask_resize;
	Point center(faceCartoon.facePosition.xc, faceCartoon.facePosition.yc);	//贴图中心点       

	vector<Point> vec_points = vec_vec_points.at(faceCartoon.cartoonMatchNum);
	int contourPointNum = vec_points.size() - 1;	//最后一个不要....
	int minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN;
	//取出该动画形象的轮廓点
	Point *polyyy = new Point[contourPointNum];
	for (int i = 0; i < contourPointNum; i++)
	{
		int x = vec_points.at(i).x;
		int y = vec_points.at(i).y;
		polyyy[i] = Point(x, y);
		minx = std::min(minx, x);
		maxx = std::max(maxx, x);
		miny = std::min(miny, y);
		maxy = std::max(maxy, y);
	}
	const Point* polygons1[1] = { polyyy };
	int num_points1[] = { contourPointNum };
	fillPoly(src_mask, polygons1, num_points1, 1, Scalar(255,255,255));
	free(polyyy);
	//imshow("动画轮廓", src_mask);
	//imshow("动画形象", srcImg);

	float wScale = 1.2, hScale = 1.6;
	int width, height;	//动画脸的目标宽高
	int cartoonWidth, cartoonHeight;	//动画脸的实际宽高

	width = faceCartoon.facePosition.w * wScale;	
	height = faceCartoon.facePosition.w * hScale;	

	//计算动画脸所占宽度和高度
	cartoonWidth = maxx - minx;
	cartoonHeight = maxy -miny;

	int minxd = center.x - width / 2;
	int maxxd = center.x + width / 2;
	int minyd = center.y - height / 2;
	int maxyd = center.y + height / 2;

	//计算动画脸的需要进行的缩放比例
	double widthScale = (double)width / (double)cartoonWidth;
	double heightScale = (double)height / (double)cartoonHeight;

	Size reSize(srcImg.cols * widthScale, srcImg.rows * heightScale);
	//缩放
	resize(srcImg, srcResize, reSize, 0, 0, CV_INTER_LINEAR);
	resize(src_mask, src_mask_resize, reSize, 0, 0, CV_INTER_LINEAR);

	int minxS = minx * widthScale;
	int maxxS = maxx * widthScale;
	int minyS = miny * heightScale;
	int maxyS = maxy * heightScale;

	//如果动画脸宽度超过边界,截取未超过边界的部分显示
	int roiMask_x = minxS, roiMask_y = minyS, roiMask_width = width, roiMask_height = height;
	if (minxd < 0)
	{
		cout<<"宽度小于0"<<endl;
		roiMask_x = roiMask_x + (-1) * minxd;
		roiMask_width = width + minxd;	//minxd为负
		center.x += (-1) * minxd / 2;
	}
	if (maxxd > faceFrame.cols)
	{
		roiMask_width = width - (maxxd - faceFrame.cols);
		center.x -= (maxxd - faceFrame.cols) / 2;
	}
	//高度超过边界
	if (minyd < 0)
	{
		cout<<"高度小于0"<<endl;
		roiMask_y = roiMask_y + (-1) * minyd;
		roiMask_height = height + minyd;
		center.y += (-1) * minyd / 2;
	}
	//高度超过边界
	if (maxyd > faceFrame.rows)
	{
		roiMask_height = height - (maxyd - faceFrame.rows);
		center.y -= (maxyd - faceFrame.rows) / 2;
	}
	//截取ROI
	Rect roiMask(roiMask_x, roiMask_y, roiMask_width, roiMask_height);
	Mat src_mask_resize_roi = src_mask_resize(roiMask);
	Mat srcResize_roi = srcResize(roiMask);
	//Mat src_downScale;
	//pyrDown(srcResize_roi, src_downScale);
	// Seamlessly clone src into dst and put the results in output
//.........这里部分代码省略.........
开发者ID:underspirit,项目名称:VideoCartoon_MFC,代码行数:101,代码来源:ImageGrabAndFusion.cpp

示例14: main5ggg

int main5ggg()
{
	// Read images : src image will be cloned into dst
	Mat src = imread("airplane.jpg");
	Mat dst = imread("sky2.jpg");
	Mat img1 = imread("manhua.jpg");

	// Create a rough mask around the airplane.
	Mat src_mask = Mat::zeros(src.rows, src.cols, src.depth());

	// Define the mask as a closed polygon
	Point poly[1][7];
	poly[0][0] = Point(4, 80);
	poly[0][1] = Point(30, 54);
	poly[0][2] = Point(151,63);
	poly[0][3] = Point(254,37);
	poly[0][4] = Point(298,90);
	poly[0][5] = Point(272,134);
	poly[0][6] = Point(43,122);

	const Point* polygons[1] = { poly[0] };
	int num_points[] = { 7 };

	// Create mask by filling the polygon

	fillPoly(src_mask, polygons, num_points, 1, Scalar(255,255,255));

	// The location of the center of the src in the dst
	Point center(250,140);

	// Seamlessly clone src into dst and put the results in output
	Mat output;
	double t = (double)cvGetTickCount();
	//printf("Histogram time = %g ms\n", t / ((double)cvGetTickFrequency()*1000.));
	customCV::seamlessClone(src, dst, src_mask, center, output, 2);
	t = (double)cvGetTickCount() - t;
	printf("Histogram time = %g ms\n", t / ((double)cvGetTickFrequency()*1000.));


	Point polyyy[1][12];
	polyyy[0][0] = Point(124, 347);
	polyyy[0][1] = Point(149, 46);
	polyyy[0][2] = Point(408,43);
	polyyy[0][3] = Point(447,350);
	polyyy[0][4] = Point(544,323);
	polyyy[0][5] = Point(517,542);
	polyyy[0][6] = Point(432,534);
	polyyy[0][7] = Point(334,656);
	polyyy[0][8] = Point(214,652);
	polyyy[0][9] = Point(136,532);
	polyyy[0][10] = Point(17,526);
	polyyy[0][11] = Point(19,328);
	const Point* polygons1[1] = { polyyy[0] };
	int num_points1[] = { 12 };
	fillPoly(img1, polygons1, num_points1, 1, Scalar(255,255,255));
	imshow("img1", img1);
	//画出多边形轮廓
	fillPoly(src, polygons, num_points, 1, Scalar(255,255,255));

	imshow("src", src);
	imshow("output",output);
	waitKey(0);
	// Save result
	imwrite("opencv-seamless-cloning-example111.jpg", output);
	return 0;
}
开发者ID:underspirit,项目名称:VideoCartoon_MFC,代码行数:66,代码来源:ImageGrabAndFusion.cpp

示例15: ProcessImages

/**
 * Runs the fast, single-disparity stereo algorithm.  Returns a
 * vector of points where it found disparity matches in the image.
 *
 * @param _leftImage left camera image as a CV_8UC1
 * @param _rightImage right camera image as a CV_8UC1
 * @param hitVector a cv::vector that we will populate with cv::Point()s
 * @param state set of configuration parameters for the function.
 *      You can change these on each run of the function if you'd like.
 */
void PushbroomStereo::ProcessImages(Mat leftImage, Mat rightImage, cv::vector<Point3f> *pointVector3d, cv::vector<uchar> *pointColors, cv::vector<Point3i> *pointVector2d, PushbroomStereoState state) {

    //cout << "[main] entering process images" << endl;

    // make sure that the inputs are of the right type
    CV_Assert(leftImage.type() == CV_8UC1 && rightImage.type() == CV_8UC1);

    // we want to use the sum-of-absolute-differences (SAD) algorithm
    // on a single disparity

    // split things up so we can parallelize
    int rows = leftImage.rows;

	
	StopWatchInterface	*timer;
	sdkCreateTimer( &timer );

	sdkResetTimer( &timer );
	sdkStartTimer( &timer );

    // first parallelize remaping

    // we split these arrays up and send them into each
    // thread so at the end, each thread has written to the
    // appropriate spot in the array
    Mat remapped_left(state.mapxL.rows, state.mapxL.cols, leftImage.depth());
    Mat remapped_right(state.mapxR.rows, state.mapxR.cols, rightImage.depth());

		remap( leftImage, remapped_left, state.mapxL, Mat(), INTER_NEAREST);
		remap( rightImage, remapped_right, state.mapxR, Mat(), INTER_NEAREST);

	sdkStopTimer( &timer );
	//printf("remap timer: %.2f ms \n", sdkGetTimerValue( &timer) );

	
	sdkResetTimer( &timer );
	sdkStartTimer( &timer );

    Mat laplacian_left(remapped_left.rows, remapped_left.cols, remapped_left.depth());
    Mat laplacian_right(remapped_right.rows, remapped_right.cols, remapped_right.depth());

	    // apply interest operator
		Laplacian( remapped_left, laplacian_left, -1, 3, 1, 0, BORDER_DEFAULT);

		Laplacian( remapped_right, laplacian_right, -1, 3, 1, 0, BORDER_DEFAULT);

	sdkStopTimer( &timer );
	//printf("laplacian timer: %.2f ms \n", sdkGetTimerValue( &timer) );

	sdkResetTimer( &timer );
	sdkStartTimer( &timer );

    cv::vector<Point3f> pointVector3dArray;
    cv::vector<Point3i> pointVector2dArray;
    cv::vector<uchar> pointColorsArray;

    //cout << "[main] firing worker threads..." << endl;

    if (state.lastValidPixelRow > 0) {

        // crop image to be only include valid pixels
        rows = state.lastValidPixelRow;
    }


    int rows_round = RoundUp(rows, state.blockSize);

	RunStereoPushbroomStereo( remapped_left, remapped_right, laplacian_left, laplacian_right,
	pointVector3d, pointVector2d, pointColors,
	0, rows_round - 1, state );

		
	sdkStopTimer( &timer );
	//printf("RunStereo timer: %.2f ms \n", sdkGetTimerValue( &timer) );

    int numPoints = 0;
    // compute the required size of our return vector
    // this prevents multiple memory allocations
    numPoints = pointVector3dArray.size();
    
    pointVector3d->reserve(numPoints);
    pointColors->reserve(numPoints);

	pointVector3d->insert( pointVector3d->end(), pointVector3dArray.begin(), pointVector3dArray.end() );

	pointColors->insert( pointColors->end(), pointColorsArray.begin(), pointColorsArray.end() );

	 if (state.show_display)
	{
		pointVector2d->insert( pointVector2d->end(), pointVector2dArray.begin(), pointVector2dArray.end() );
//.........这里部分代码省略.........
开发者ID:soulsheng,项目名称:flight,代码行数:101,代码来源:pushbroom-stereo.cpp


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