I am having a problem with my code. A snippet of my code is mentioned below
这些是我读作的一些样本价值。
116 117 77 0.170833333333333 0.341880341880342
FILE* fid= fopen("treewall","r");
while (fscanf(fid,"%f",&a)==1)
{
printf("%f
",a);
trainsamplecount=trainsamplecount+1;
}
cout<<trainsamplecount<<endl;
rewind(fid);
float td[2000][7];
int numoftestpoints;
CvMat* traindata=cvCreateMat(trainsamplecount,6,CV_32FC1);
CvMat* trainclasses=cvCreateMat(trainsamplecount,1,CV_32FC1);
CvMat* samplewts=cvCreateMat(trainsamplecount,1,CV_32FC1);
CvMat* neurallayers=cvCreateMat(4,1,CV_32SC1);
CvMat traindata1,trainclasses1,neurallayers1,samplewts1;
cvGetRows(traindata,&traindata1,0,trainsamplecount);
cvGetRows(trainclasses,&trainclasses1,0,trainsamplecount);
cvGetRows(samplewts,&samplewts1,0,trainsamplecount);
cvGetRows(neurallayers,&neurallayers1,0,4);
cvSet1D(&neurallayers1, 0, cvScalar(6));
cvSet1D(&neurallayers1,1,cvScalar(3));
cvSet1D(&neurallayers1,2,cvScalar(3));
cvSet1D(&neurallayers1, 3, cvScalar(1));
int i=0,j=0;
if(fid)
{
for(int i=0;i<trainsamplecount;i++)
fscanf(fid,"%f %f %f %f %f %f %f ",&td[i][0],&td[i][1],&td[i][2],&td[i][3],&td[i][4],&td[i][5],&td[i][6]);
for (i=0;i<trainsamplecount;i++)
{
cout<<i<<endl;
cvSetReal2D(traindata,i,0,(float)td[i][0]);
cvSetReal2D(traindata,i,1,(float)td[i][1]);
cvSetReal2D(traindata,i,2,(float)td[i][2]);
cvSetReal2D(traindata,i,3,(float)td[i][3]);
cvSetReal2D(traindata,i,4,(float)td[i][4]);
cvSetReal2D(traindata,i,5,(float)td[i][5]);
cvSet1D(&trainclasses1,i,cvRealScalar(1));
cvSet1D(&samplewts1,i,cvRealScalar(1));
}
}
It gives an error at cvSetReal2D. This gives the following error:
OpenCV Error: Bad argument (unrecognized or unsupported array type) in cvPtr2D, file /usr/local/src/OpenCV-2.3.0/modules/core/src/array.cpp, line 1830
terminate called after throwing an instance of cv::Exception
I am working in Ubuntu on eclipse in OpenCV. Please help me fix this.