OpenCV-CvMat的畫素資料讀取方法
阿新 • • 發佈:2019-01-09
#include <iostream> #include <opencv2/opencv.hpp> #include <opencv2/highgui.hpp> using namespace std; using namespace cv; int main(int argc, const char * argv[]) { // insert code here... float vals[] = {0.866025,-0.500000,0.500000,0.866025}; CvMat rotmat; cvInitMatHeader(&rotmat, 2, 2, CV_32FC1,vals); cout<<"rotmat->rows = "<<rotmat.rows<<endl; cout<<"rotmat->clos = "<<rotmat.cols<<endl; cout<<"rotmat->step = "<<rotmat.step<<endl; //表示行資料長度(單位是位元組數) for(unsigned int i = 0;i<rotmat.rows;i++) { for(unsigned int j = 0;j<rotmat.cols;j++) { cout<<i<<","<<j<<"->"<<*(rotmat.data.fl + i*rotmat.rows + j)<<endl; //普通提取 cout<<i<<","<<j<<"->"<<*((float *)(rotmat.data.ptr + i * rotmat.step) + j)<<endl; //取uchar進行強轉 偏移 } } return 1; }