程序:
代码:
#include "cv.h" #include "cxcore.h" #include "highgui.h" #include <iostream> int GetDiag(int argc,char** argv) { IplImage *src=cvLoadImage("e:\\picture\\4.jpg",0); CvMat *submat=cvCreateMatHeader(1,1,CV_8UC1); //这里的行数和列数不重要,等一下cvGetDiag;还会初始化 cvGetDiag(src,submat); std::cout<<"rows:"<<submat->rows<<std::endl; std::cout<<"cols:"<<submat->cols<<std::endl; for(int x=0;x<submat->rows;x++) { uchar *pt=(uchar *)(submat->data.ptr+x*submat->step); for(int y=0;y<submat->cols;y++) { uchar* pt2=(uchar *)(pt+y*src->nChannels); std::cout<<(int)*pt2<<" "; } } return 0; }
结论:
submat被cvGetDiag创建为对角线行,1列的矩阵
本文出自 “flyclc” 博客,请务必保留此出处http://flyclc.blog.51cto.com/1385758/1539965
原文地址:http://flyclc.blog.51cto.com/1385758/1539965