• 欢迎浏览“String me = Creater\忠实的资深Linux玩家;”,请文明浏览,理性发言,有侵犯你的权益请邮件我(creater@vip.qq.com).
  • 把任何的失败都当作一次尝试,不要自卑;把所有的成功都想成是一种幸运,不要自傲。
  •    4年前 (2014-10-02)  OpenCv |   抢沙发  9 
    文章评分 0 次,平均分 0.0

    1.单通道读取

    	double a[9]={1,2,3,4,5,6,7,8,9};
    	double* data=0;
    
    	CvMat *pm=cvCreateMat(3,3,CV_64FC1);
    
    	cvInitMatHeader(pm,3,3,CV_64FC1,a);
    
    
    	cout<<"行:"<<pm->height<<"   列:"<<pm->width<<"  step: "<<pm->step<<endl;
    	for(int i=0;i<pm->height;i++)
    	{
    		data=(double*)(pm->data.ptr +i*pm->step);
    		for(int j=0;j<pm->width;j++)
    		{
    			printf("%3.1f ", *(data + j));
    		}
    		printf("\n");
    	}

    2.3通道读取

    	double a[27]={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27};
    	double* data=0;
    
    	CvMat *pm=cvCreateMat(3,3,CV_64FC3);
    
    	cvInitMatHeader(pm,3,3,CV_64FC3,a);
    	
    
    	cout<<"行:"<<pm->height<<"   列:"<<pm->width<<"  step: "<<pm->step<<endl;
    	for(int i=0;i<pm->height;i++)
    	{
    		data=(double*)(pm->data.ptr +i*pm->step);
    		for(int j=0;j<pm->width;j++)
    		{
    			printf("%3.1f %3.1f %3.1f ", *(data + j*3+0), *(data + j*3+1), *(data + j*3+2));
    		}
    		printf("\n");
    	}

    3.单通道读取

    	IplImage *dst = cvCreateImage(cvGetSize(pm),IPL_DEPTH_64F,1);
    	cvConvert(pm, dst);
    	cout<<"行:"<<dst->height<<"   列:"<<dst->width<<"  step: "<<dst->widthStep<<endl;
    	double *imgData  = 0;
    	for(int i=0;i<dst->height;i++)
    	{
    		imgData=(double*)(dst->imageData +i*dst->widthStep);
    		for(int j=0;j<dst->width;j++)
    		{
    			printf("%3.1f ", *(imgData +j));
    		}
    		printf("\n");
    	}
    

    4.多通道读取

    	IplImage *dst = cvCreateImage(cvGetSize(pm),IPL_DEPTH_64F,3);
    	cvConvert(pm, dst);
    	cout<<"行:"<<dst->height<<"   列:"<<dst->width<<"  step: "<<dst->widthStep<<endl;
    	double *imgData  = 0;
    	for(int i=0;i<dst->height;i++)
    	{
    		imgData=(double*)(dst->imageData +i*dst->widthStep);
    		for(int j=0;j<dst->width;j++)
    		{
    			printf("%3.1f %3.1f %3.1f ", *(imgData +j*dst->nChannels +0),*(imgData +j*dst->nChannels +1),*(imgData +j*dst->nChannels +2));
    		}
    		printf("\n");
    	}
    
     

    除特别注明外,本站所有文章均为String me = "Creater\忠实的资深Linux玩家";原创,转载请注明出处来自http://unix8.net/home.php/3744.html

    关于

    发表评论

    暂无评论

    切换注册

    登录

    忘记密码 ?

    切换登录

    注册

    扫一扫二维码分享