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


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

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


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

示例1: convertFalseColor

void convertFalseColor(const cv::Mat& srcmat, cv::Mat& dstmat, palette::palettetypes paltype){

	palette pal = GetPalette(paltype);

	dstmat.create(srcmat.rows, srcmat.cols, CV_8UC3);


	cv::Size sz = srcmat.size();
	const uchar* src = srcmat.data;
	uchar* dst = dstmat.data;

	if( srcmat.isContinuous() && dstmat.isContinuous() )
	{
		sz.width *= sz.height;
		sz.height = 1;
	}

	for(int i = 0;i<sz.width;++i){
		for(int j = 0;j<sz.height;++j){
			int idx = j*sz.width + i;
			uint8_t val = src[idx];
			dst[idx*dstmat.channels() + 0] = pal.colors[val].rgbBlue;
			dst[idx*dstmat.channels() + 1] = pal.colors[val].rgbGreen;
			dst[idx*dstmat.channels() + 2] = pal.colors[val].rgbRed;
		}
	}

}
开发者ID:darivianos,项目名称:irdetect,代码行数:28,代码来源:false_color.cpp

示例2: Binalize

void Binalize(const cv::Mat& depth_image, const cv::Mat& uv_map, cv::Mat1b& binary_image, short depth_threshold_mm) {

	assert(depth_image.size() == uv_map.size());
	assert(depth_image.type() == CV_16SC1);
	assert(uv_map.type() == CV_32FC2);

	cv::Size binary_size = binary_image.size();
	//Clear all pixels of binary_image
	binary_image = 0;

	cv::Size loop_size = depth_image.size();
	if(depth_image.isContinuous() && uv_map.isContinuous()) {
		loop_size.width *= loop_size.height;
		loop_size.height = 1;
	}
	for(int i = 0; i < loop_size.height; ++i) {
		const short* depth = depth_image.ptr<short>(i);
		const cv::Vec2f* uv = uv_map.ptr<cv::Vec2f>(i);
		for(int j = 0; j < loop_size.width; ++j) {
			if(depth[j] < depth_threshold_mm) {
				int x = cvRound(uv[j][0] * binary_size.width);
				int y = cvRound(uv[j][1] * binary_size.height);
				if(0 <= x && x < binary_size.width && 0 <= y && y < binary_size.height) {
					binary_image.at<unsigned char>(cv::Point(x, y)) = 255;
				}
			}
		}
	}
}
开发者ID:shikumidesign,项目名称:perc_sample,代码行数:29,代码来源:main.cpp

示例3: fhogToCol

    void fhogToCol(const cv::Mat& img, cv::Mat& cvFeatures,
                   int binSize, int colIdx, PRIMITIVE_TYPE cosFactor) {
        const int orientations = 9;
        // ensure array is continuous
        const cv::Mat& image = (img.isContinuous() ? img : img.clone());
        int channels = image.channels();
        int computeChannels = 32;
        int width = image.cols;
        int height = image.rows;
        int widthBin = width / binSize;
        int heightBin = height / binSize;

        CV_Assert(channels == 1 || channels == 3);
        CV_Assert(cvFeatures.channels() == 1 && cvFeatures.isContinuous());

        float* const H = (float*)wrCalloc(static_cast<size_t>(widthBin * heightBin * computeChannels), sizeof(float));
        float* const I = (float*)wrCalloc(static_cast<size_t>(width * height * channels), sizeof(float));
        float* const M = (float*)wrCalloc(static_cast<size_t>(width * height), sizeof(float));
        float* const O = (float*)wrCalloc(static_cast<size_t>(width * height), sizeof(float));

        // row major (interleaved) to col major (non-interleaved;clustered;block)
        float* imageData = reinterpret_cast<float*>(image.data);

        float* const redChannel = I;
        float* const greenChannel = I + width * height;
        float* const blueChannel = I + 2 * width * height;
        int colMajorPos = 0, rowMajorPos = 0;

        for (int row = 0; row < height; ++row) {
            for (int col = 0; col < width; ++col) {
                colMajorPos = col * height + row;
                rowMajorPos = row * channels * width + col * channels;

                blueChannel[colMajorPos] = imageData[rowMajorPos];
                greenChannel[colMajorPos] = imageData[rowMajorPos + 1];
                redChannel[colMajorPos] = imageData[rowMajorPos + 2];
            }
        }

        // calc fhog in col major
        gradMag(I, M, O, height, width, channels, true);
        fhog(M, O, H, height, width, binSize, orientations, -1, 0.2f);

        // the order of rows in cvFeatures does not matter
        // as long as it is the same for all columns;
        // zero channel is not copied as it is the last
        // channel in H and cvFeatures rows doesn't include it
        PRIMITIVE_TYPE* cdata = reinterpret_cast<PRIMITIVE_TYPE*>(cvFeatures.data);
        int outputWidth = cvFeatures.cols;

        for (int row = 0; row < cvFeatures.rows; ++row)
        { cdata[outputWidth * row + colIdx] = H[row] * cosFactor; }

        wrFree(H);
        wrFree(M);
        wrFree(O);
        wrFree(I);
    }
开发者ID:tracedev,项目名称:cf_tracking,代码行数:58,代码来源:gradientMex.hpp

示例4: fhogToCvColT

    void fhogToCvColT(const cv::Mat& img, cv::Mat& cvFeatures,
                      int binSize, int colIdx, PRIMITIVE_TYPE cosFactor) {
        const int orientations = 9;
        // ensure array is continuous
        const cv::Mat& image = (img.isContinuous() ? img : img.clone());
        int channels = image.channels();
        int computeChannels = 32;
        int width = image.cols;
        int height = image.rows;
        int widthBin = width / binSize;
        int heightBin = height / binSize;

        CV_Assert(channels == 1 || channels == 3);
        CV_Assert(cvFeatures.channels() == 1 && cvFeatures.isContinuous());

        float* const H = (float*)wrCalloc(static_cast<size_t>(widthBin * heightBin * computeChannels), sizeof(float));
        float* const M = (float*)wrCalloc(static_cast<size_t>(width * height), sizeof(float));
        float* const O = (float*)wrCalloc(static_cast<size_t>(width * height), sizeof(float));

        float* I = NULL;

        if (channels == 1)
        { I = reinterpret_cast<float*>(image.data); }
        else {
            I = (float*)wrCalloc(static_cast<size_t>(width * height * channels), sizeof(float));
            float* imageData = reinterpret_cast<float*>(image.data);
            float* redChannel = I;
            float* greenChannel = I + width * height;
            float* blueChannel = I + 2 * width * height;

            for (int i = 0; i < height * width; ++i) {
                blueChannel[i] = imageData[i * 3];
                greenChannel[i] = imageData[i * 3 + 1];
                redChannel[i] = imageData[i * 3 + 2];
            }
        }

        // calc fhog in col major - switch width and height
        gradMag(I, M, O, width, height, channels, true);
        fhog(M, O, H, width, height, binSize, orientations, -1, 0.2f);

        // the order of rows in cvFeatures does not matter
        // as long as it is the same for all columns;
        // zero channel is not copied as it is the last
        // channel in H and cvFeatures rows doesn't include it
        PRIMITIVE_TYPE* cdata = reinterpret_cast<PRIMITIVE_TYPE*>(cvFeatures.data);
        int outputWidth = cvFeatures.cols;

        for (int row = 0; row < cvFeatures.rows; ++row)
        { cdata[outputWidth * row + colIdx] = H[row] * cosFactor; }

        wrFree(H);
        wrFree(M);
        wrFree(O);

        if (channels != 1)
        { wrFree(I); }
    }
开发者ID:tracedev,项目名称:cf_tracking,代码行数:58,代码来源:gradientMex.hpp

示例5: fhog

void fhog(const cv::Mat& image, vector<Mat>& fhogs, int binSize,
          int orientations) {
    assert(image.type() == CV_32F || image.type() == CV_32FC3);
    assert(image.isContinuous());
    float *M = new float[image.rows * image.cols];
    float *O = new float[image.rows * image.cols];

    int hb       = image.rows / binSize;
    int wb       = image.cols / binSize;
    int nChannls = orientations * 3 + 5;

    float *H = new float[hb * wb * nChannls];
    fill_n(H, hb * wb * nChannls, 0);
    gradientMagnitude(image, M, O);

    fhog(M, O, H, image.rows, image.cols, binSize, orientations, -1, 0.2f);

    for (size_t i = 0; i < nChannls; i++) {
        Mat tmp(Size(wb, hb), CV_32FC1);
        Matlab2OpenCVC1(H + ( i * (wb * hb)), tmp);
        fhogs.push_back(tmp);
    }

    delete[] H;
    delete[] M;
    delete[] O;
}
开发者ID:joelgallant,项目名称:skcf,代码行数:27,代码来源:gradient.cpp

示例6: save

void save(Archive &ar, const cv::Mat &mat)
{
    int rows, cols, type;
    bool continuous;
    rows = mat.rows;
    cols = mat.cols;
    type = mat.type();
    continuous = mat.isContinuous();
    ar &rows &cols &type &continuous;

    if (continuous)
    {
        const int data_size = rows * cols * static_cast<int>(mat.elemSize());
        auto mat_data = cereal::binary_data(mat.ptr(), data_size);
        ar &mat_data;
    }

    else
    {
        const int row_size = cols * static_cast<int>(mat.elemSize());

        for (int i = 0; i < rows; i++)
        {
            auto row_data = cereal::binary_data(mat.ptr(i), row_size);
            ar &row_data;
        }
    }
}
开发者ID:Boazrciasn,项目名称:ImageCLEF,代码行数:28,代码来源:matcerealisation.hpp

示例7: saveMat

    // Save a matrix which is generated by OpenCV
    int saveMat( const string& filename, const cv::Mat& M)
    {
        if (M.empty())
        {
            return 0;
        }
        ofstream out(filename.c_str(), ios::out|ios::binary);
        if (!out)
            return 0;

        int cols = M.cols;
        int rows = M.rows;
        int chan = M.channels();
        int eSiz = (M.dataend-M.datastart)/(cols*rows*chan);

        // Write header
        out.write((char*)&cols,sizeof(cols));
        out.write((char*)&rows,sizeof(rows));
        out.write((char*)&chan,sizeof(chan));
        out.write((char*)&eSiz,sizeof(eSiz));

        // Write data.
        if (M.isContinuous())
        {
            out.write((char *)M.data,cols*rows*chan*eSiz);
        }
        else
        {
            return 0;
        }
        out.close();
        return 1;
    }
开发者ID:azazellochg,项目名称:scipion,代码行数:34,代码来源:movie_optical_alignment_cpu.cpp

示例8: read_one

// Read one cv::Mat from file
bool read_one(FILE * file, cv::Mat & data)
{
	bool okay = true;
	int32_t rows, cols; uint32_t type;
	okay &= read_one(file, rows);
	okay &= read_one(file, cols);
	okay &= read_one(file, type);
	if (rows <= 0 || cols <= 0 || (type & ~CV_MAT_TYPE_MASK) != 0)
		return false;
	data.create(rows, cols, type);

	// If matrix memory is continuous, we can reshape the matrix
	if (data.isContinuous()) {
		cols = rows*cols;
		rows = 1;
	}

	// Currently only supports float/double matrices!
	if (data.depth() == CV_32F)
		for (int r = 0; r < rows; ++r)
			okay &= read_n(file, data.ptr<float>(r), cols);
	else if (data.depth() == CV_64F)
		for (int r = 0; r < rows; ++r)
			okay &= read_n(file, data.ptr<double>(r), cols);
	else
		return false;

	return okay;
}
开发者ID:arvinyang,项目名称:VirtualGlasses,代码行数:30,代码来源:binary_model_file.cpp

示例9: colorReduce7

// using .ptr and * ++ and bitwise (continuous+channels)
void colorReduce7(cv::Mat &image, int div=64) {

	  int nl= image.rows; // number of lines
	  int nc= image.cols ; // number of columns

	  if (image.isContinuous())  {
		  // then no padded pixels
		  nc= nc*nl; 
		  nl= 1;  // it is now a 1D array
	   }

	  int n= static_cast<int>(log(static_cast<double>(div))/log(2.0));
	  // mask used to round the pixel value
	  uchar mask= 0xFF<<n; // e.g. for div=16, mask= 0xF0
              
      for (int j=0; j<nl; j++) {

		  uchar* data= image.ptr<uchar>(j);

          for (int i=0; i<nc; i++) {
 
            // process each pixel ---------------------
                 
            *data++= *data&mask + div/2;
            *data++= *data&mask + div/2;
            *data++= *data&mask + div/2;
 
            // end of pixel processing ----------------
 
            } // end of line                   
      }
}
开发者ID:AresRobotic,项目名称:Vision,代码行数:33,代码来源:colorReduce.cpp

示例10: showPropertiesOfMat

 //
 // showPropertiesOfMat
 //
 //   ...displays all properties of specified Mat.
 //
 void showPropertiesOfMat (const cv::Mat &src_mat)
 {
   // 行数
   std::cout << "rows:" << src_mat.rows <<std::endl;
   // 列数
   std::cout << "cols:" << src_mat.cols << std::endl;
   // 次元数
   std::cout << "dims:" << src_mat.dims << std::endl;
   // サイズ(2次元の場合)
   std::cout << "size[]:" << src_mat.size().width << "," << src_mat.size().height  << "[byte]" << std::endl;
   // ビット深度ID
   std::cout << "depth (ID):" << src_mat.depth() << "(=" << CV_64F << ")" << std::endl;
   // チャンネル数
   std::cout << "channels:" << src_mat.channels() << std::endl;
   // 1要素内の1チャンネル分のサイズ [バイト単位]
   std::cout << "elemSize1 (elemSize/channels):" << src_mat.elemSize1() << "[byte]" << std::endl;
   // 要素の総数
   std::cout << "total:" << src_mat.total() << std::endl;
   // ステップ数 [バイト単位]
   std::cout << "step:" << src_mat.step << "[byte]" << std::endl;
   // 1ステップ内のチャンネル総数
   std::cout << "step1 (step/elemSize1):" << src_mat.step1()  << std::endl;
   // データは連続か?
   std::cout << "isContinuous:" << (src_mat.isContinuous()?"true":"false") << std::endl;
   // 部分行列か?
   std::cout << "isSubmatrix:" << (src_mat.isSubmatrix()?"true":"false") << std::endl;
   // データは空か?
   std::cout << "empty:" << (src_mat.empty()?"true":"false") << std::endl;
 }
开发者ID:shingt,项目名称:cvutils,代码行数:34,代码来源:cvutils.cpp

示例11:

static inline void lbsp_computeImpl(const cv::Mat& oInputImg, const cv::Mat& oRefImg, const std::vector<cv::KeyPoint>& voKeyPoints,
                                    cv::Mat& oDesc, bool bSingleColumnDesc, size_t nThreshold) {
    static_assert(LBSP::DESC_SIZE==2,"bad assumptions in impl below");
    CV_DbgAssert(oRefImg.empty() || (oRefImg.size==oInputImg.size && oRefImg.type()==oInputImg.type()));
    CV_DbgAssert(oInputImg.type()==CV_8UC1 || oInputImg.type()==CV_8UC3);
    const size_t nChannels = (size_t)oInputImg.channels();
    const cv::Mat& oRefMat = oRefImg.empty()?oInputImg:oRefImg;
    CV_DbgAssert(oInputImg.isContinuous() && oRefMat.isContinuous());
    const size_t nKeyPoints = voKeyPoints.size();
    if(nChannels==1) {
        if(bSingleColumnDesc)
            oDesc.create((int)nKeyPoints,1,CV_16UC1);
        else
            oDesc.create(oInputImg.size(),CV_16UC1);
        for(size_t k=0; k<nKeyPoints; ++k) {
            const int x = (int)voKeyPoints[k].pt.x;
            const int y = (int)voKeyPoints[k].pt.y;
            LBSP::computeDescriptor<1>(oInputImg,oRefMat.at<uchar>(y,x),x,y,0,nThreshold,oDesc.at<ushort>((int)k));
        }
        return;
    }
    else { //nChannels==3
        if(bSingleColumnDesc)
            oDesc.create((int)nKeyPoints,1,CV_16UC3);
        else
            oDesc.create(oInputImg.size(),CV_16UC3);
        const std::array<size_t,3> anThreshold = {nThreshold,nThreshold,nThreshold};
        for(size_t k=0; k<nKeyPoints; ++k) {
            const int x = (int)voKeyPoints[k].pt.x;
            const int y = (int)voKeyPoints[k].pt.y;
            const uchar* acRef = oRefMat.data+oInputImg.step.p[0]*y+oInputImg.step.p[1]*x;
            LBSP::computeDescriptor(oInputImg,acRef,x,y,anThreshold,((ushort*)(oDesc.data+oDesc.step.p[0]*k)));
        }
    }
}
开发者ID:caomw,项目名称:litiv,代码行数:35,代码来源:LBSP.cpp

示例12: write

void cv::write(const std::string& sFilePath, const cv::Mat& _oData, cv::MatArchiveList eArchiveType) {
    lvAssert_(!sFilePath.empty() && !_oData.empty(),"output file path and matrix must both be non-empty");
    cv::Mat oData = _oData.isContinuous()?_oData:_oData.clone();
    if(eArchiveType==MatArchive_FILESTORAGE) {
        cv::FileStorage oArchive(sFilePath,cv::FileStorage::WRITE);
        lvAssert__(oArchive.isOpened(),"could not open archive at '%s' for writing",sFilePath.c_str());
        oArchive << "htag" << lv::getVersionStamp();
        oArchive << "date" << lv::getTimeStamp();
        oArchive << "matrix" << oData;
    }
    else if(eArchiveType==MatArchive_PLAINTEXT) {
        std::ofstream ssStr(sFilePath);
        lvAssert__(ssStr.is_open(),"could not open text file at '%s' for writing",sFilePath.c_str());
        ssStr << "htag " << lv::getVersionStamp() << std::endl;
        ssStr << "date " << lv::getTimeStamp() << std::endl;
        ssStr << "nDataType " << (int32_t)oData.type() << std::endl;
        ssStr << "nDataDepth " << (int32_t)oData.depth() << std::endl;
        ssStr << "nChannels " << (int32_t)oData.channels() << std::endl;
        ssStr << "nElemSize " << (uint64_t)oData.elemSize() << std::endl;
        ssStr << "nElemCount " << (uint64_t)oData.total() << std::endl;
        ssStr << "nDims " << (int32_t)oData.dims << std::endl;
        ssStr << "anSizes";
        for(int nDimIdx=0; nDimIdx<oData.dims; ++nDimIdx)
            ssStr << " " << (int32_t)oData.size[nDimIdx];
        ssStr << std::endl << std::endl;
        if(oData.depth()!=CV_64F)
            _oData.convertTo(oData,CV_64F);
        double* pdData = (double*)oData.data;
        for(int nElemIdx=0; nElemIdx<(int)oData.total(); ++nElemIdx) {
            ssStr << *pdData++;
            for(int nElemPackIdx=1; nElemPackIdx<oData.channels(); ++nElemPackIdx)
                ssStr << " " << *pdData++;
            if(((nElemIdx+1)%oData.size[oData.dims-1])==0)
                ssStr << std::endl;
            else
                ssStr << " ";
        }
        lvAssert_(ssStr,"plain text archive write failed");
    }
    else if(eArchiveType==MatArchive_BINARY) {
        std::ofstream ssStr(sFilePath,std::ios::binary);
        lvAssert__(ssStr.is_open(),"could not open binary file at '%s' for writing",sFilePath.c_str());
        const int32_t nDataType = (int32_t)oData.type();
        ssStr.write((const char*)&nDataType,sizeof(nDataType));
        const uint64_t nElemSize = (uint64_t)oData.elemSize();
        ssStr.write((const char*)&nElemSize,sizeof(nElemSize));
        const uint64_t nElemCount = (uint64_t)oData.total();
        ssStr.write((const char*)&nElemCount,sizeof(nElemCount));
        const int32_t nDims = (int32_t)oData.dims;
        ssStr.write((const char*)&nDims,sizeof(nDims));
        for(int32_t nDimIdx=0; nDimIdx<nDims; ++nDimIdx) {
            const int32_t nDimSize = (int32_t)oData.size[nDimIdx];
            ssStr.write((const char*)&nDimSize,sizeof(nDimSize));
        }
        ssStr.write((const char*)(oData.data),nElemSize*nElemCount);
        lvAssert_(ssStr,"binary archive write failed");
    }
    else
        lvError("unrecognized mat archive type flag");
}
开发者ID:plstcharles,项目名称:litiv,代码行数:60,代码来源:opencv.cpp

示例13: colorReduceCheckForContinuous

void Processor::colorReduceCheckForContinuous(const cv::Mat& image,
		cv::Mat& result, int div) {

	startTimer();
	int lines = image.rows;

	int pixels = image.cols * image.channels();

	if (image.isContinuous()) {
		pixels = pixels * lines;
		lines = 1;
		std::cout << "Image is continuous" << std::endl;
	} else {
		std::cout << "Image is not continuous" << std::endl;
	}

	result.create(image.rows, image.cols, image.type());

	for (int i = 0; i < lines; i++) {
		const uchar* data_in = image.ptr<uchar>(i);
		uchar* data_out = result.ptr<uchar>(i);

		for (int j = 0; j < pixels; j++)
			*data_out++ = *data_in++ / div * div + div / 2;
	}

	stopTimer("ColorReduceCheckForContinous");

}
开发者ID:centosGit,项目名称:OpenCV_Gaze_Detection,代码行数:29,代码来源:Processor.cpp

示例14: merge

void merge(cv::Mat &in1, cv::Mat &in2,cv::Mat &out)
{
    int nLines = in1.rows;
    int nc = in1.cols * in1.channels();
    if(in1.isContinuous())
    {
        nc = nc*nLines;
        nLines = 1;
    }
    for(int j=0;j<nLines;j++)
    {
        uchar* dataIN1 = in1.ptr<uchar>(j); //fajne :)
        uchar* dataIN2 = in2.ptr<uchar>(j);
        uchar* dataOUT = out.ptr<uchar>(j);
        for(int i=0;i<nc; i++)
        {
            if(dataIN2[i] == 0)
            {
                dataOUT[i] = dataIN1[i];
            }
            else
            {
                dataOUT[i] = dataIN2[i];
            }

        }
    }
}
开发者ID:IndhuMathiS,项目名称:1045_MobileAppBasedOnAugmentedRealityForRetailShopping,代码行数:28,代码来源:AR3.cpp

示例15: process

void TreeLiveProc::process (const cv::Mat& dmap,
                            cv::Mat&       lmap )
{
	if( dmap.depth()       != CV_16U ) TLIVEEXCEPT("depth has incorrect channel type")
	if( dmap.channels()    != 1 )      TLIVEEXCEPT("depth has incorrect channel count")
	if( dmap.size().width  != 640 )    TLIVEEXCEPT("depth has incorrect width")
	if( dmap.size().height != 480 )    TLIVEEXCEPT("depth has incorrect height")
	if( !dmap.isContinuous() )         TLIVEEXCEPT("depth has non contiguous rows")

	// alloc the buffer if it isn't done yet
	lmap.create( 480, 640, CV_8UC(1) );
	
	// copy depth to cuda
	cudaMemcpy(m_dmap_device, (const void*) dmap.data, 
	                          640*480*sizeof(uint16_t), cudaMemcpyHostToDevice);
	// process the dmap
	CUDA_runTree( 640,480, focal, 
	              m_tree->treeHeight(), 
	              m_tree->numNodes(), 
	              m_tree->nodes_device(), 
	              m_tree->leaves_device(),
	              m_dmap_device, 
	              m_lmap_device );
	// download back from cuda
	cudaMemcpy((Label*)(lmap.data), m_lmap_device,
	                             640*480*sizeof(Label), cudaMemcpyDeviceToHost);
}
开发者ID:amuetzel,项目名称:HumanDataGen,代码行数:27,代码来源:TreeLiveProc.cpp


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