OpenCV 获取CvMat的数据(用double数组设置CvMat矩阵)

直接上code吧,注意采用数组设置矩阵比较方便


#include<cv.h>
#include<highgui.h>
#include<cvaux.h>
#include<cxcore.h>


#include<iostream>
#include<fstream>
using namespace std;


#pragma comment(lib,"cv.lib");
#pragma comment(lib,"cvaux.lib");
#pragma comment(lib,"cxcore.lib");
#pragma comment(lib,"highgui.lib");




int main()
{
/*double objPoints[24] = { 3.5,    60,  0,
-3.5,    60,  0,
-175,    3.5, 0,
-175,   -3.5, 0,
175,   -3.5, 0,
175,    +3.5, 0,
0,      0,   0,
0,      0,   -100
};*/


/*double objPoints[2][3] = {3.5,    60,  0,-3.5,    60,  0};*/




double objPoints[8][3];
for (int i=0;i<8;i++)
{
for (int j=0;j<3;j++)
{
objPoints[i][j] = i*3+j; 
}
}


CvMat object_points = cvMat(8,3,CV_64FC1,objPoints);


double *p1 = (double*)object_points.data.ptr;
for (int i=0;i<8;i++)
{
for (int j=0;j<3;j++)
{
cout<<*(p1+i*3+j)<<" ";
}
cout<<endl;
}
    


double temp_data[3] = {1, 2, 3};


CvMat temp = cvMat(3,1,CV_64FC1,temp_data);


double result1_data[8] = { 0};


CvMat result1 = cvMat(8,1,CV_64FC1,result1_data);


CvMat *org1 = &object_points;
CvMat *org2 = &temp;
CvMat *ress1 = &result1;


cvMatMul(org1,org2,ress1);


double *p2 = (double*)result1.data.ptr;
for(int i=0;i<8;i++)
{
for (int j=0;j<1;j++)
{
cout<<*(p2+i*1+j)<<" ";
}
cout<<endl;
}
for (int i=0;i<8;i++)
{
cout<<result1_data[i]<<endl;
}
cout<<"result is above"<<endl;

}

你可能感兴趣的:(OpenCV 获取CvMat的数据(用double数组设置CvMat矩阵))