问题描述
- opencv cvGEMM总是报错,附代码,求大神纠正
- 在第一个cvGEMM那里就报错了,控制台也没提示错误地方
float x y; float a1 a2 a3 a4 a5 b1; float data[10][5]; float dab[10]; CvMat* curve_p = cvCreateMat(51CV_32FC1); CvMat* A = cvCreateMat(n 5 CV_32FC1); CvMat* b = cvCreateMat(n 1 CV_32FC1); //获取十个数据 for (int i = 1; i <= 10; i++) { int pt = (20 - 1)*i / 10; x = 2; y = 6; a1 = x*x - y*y; a2 = x*y; a3 = x; a4 = y; a5 = 1; b1 = -y*y; data[i - 1][0] = a1; data[i - 1][1] = a2; data[i - 1][2] = a3; data[i - 1][3] = a4; data[i - 1][4] = a5; dab[i - 1] = b1; } cvSetData(A data A->step); cvSetData(b dab b->step); CvMat *E1 *E2 *E3; E1 = cvCreateMat(5 5 CV_32FC1); E2 = cvCreateMat(5 5 CV_32FC1); E3 = cvCreateMat(5 n CV_32FC1); cvGEMM(A A 1 NULL 0 E1 CV_GEMM_A_T); cvInvert(E1 E2 0); cvGEMM(E2 A 1 NULL 0 E3 CV_GEMM_B_T); cvGEMM(E3 b 1 NULL 0 curve_p); cvReleaseMat(&A); cvReleaseMat(&b); cvReleaseMat(&E1); cvReleaseMat(&E2); cvReleaseMat(&E3);
解决方案
应该还是会有异常信息的,要不试试用try catch抓一下看。
或者可以先试试一个好用的程序看
#include
#include
#include
#include
using namespace std;
int main()
{
double a[3][3] =
{
{100}
{020}
{003}
};
CvMat va=cvMat(33 CV_64FC1a);
cout<<""目标矩阵1:""<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
printf(""%ft""cvmGet(&vaij));
cout << endl;
}
double b[3][3] =
{
{111}
{111}
{111}
};
CvMat vb =cvMat(3 3 CV_64FC1 b);
cout<<""目标矩阵2:""<<endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
printf(""%ft""cvmGet(&vbij));
cout << endl;
}
double c[3][3] = {000000000};
CvMat vc = cvMat(33 CV_64FC1 c);
cvGEMM(&va&vb1&vc1&vc);
cout << ""结果矩阵:""<< endl;
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
printf(""%ft""cvmGet(&vcij));
cout << endl;
}
getchar();
return 0;
}