English 中文(简体)
在试图将矩阵值定在开放式中心时点差错
原标题:Pointer error when trying to set the value of a matrix in OpenCV

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.

最佳回答

以下是你试图做的简明样本。 这在我使用开放式CV 2.3.1的机器上是正确的:

#define SAMPLE_COUNT 5

int main(int argc, char** argv)
{
    CvMat* data = cvCreateMat(SAMPLE_COUNT, 6, CV_32FC1);

    for (int i = 0; i < SAMPLE_COUNT; i++)
    {
        cout << "Adding i = " << i << endl;
        cvSetReal2D(data, i, 0, (float)i);
        cvSetReal2D(data, i, 1, (float)i);
        cvSetReal2D(data, i, 2, (float)i);
        cvSetReal2D(data, i, 3, (float)i);
        cvSetReal2D(data, i, 4, (float)i);
        cvSetReal2D(data, i, 5, (float)i);
    }


    return 0;
}

然而,我不敢肯定你努力达到这些目的:

cvGetRows(data, &data1, 0, samplecount);
cvGetRows(classes, &classes1, 0, samplecount);

页: 1 因此,为什么不直接使用<条码>数据和<条码>>等词?

更有必要彻底地解决我认为是......的问题。

问题回答

暂无回答




相关问题
Undefined reference

I m getting this linker error. I know a way around it, but it s bugging me because another part of the project s linking fine and it s designed almost identically. First, I have namespace LCD. Then I ...

C++ Equivalent of Tidy

Is there an equivalent to tidy for HTML code for C++? I have searched on the internet, but I find nothing but C++ wrappers for tidy, etc... I think the keyword tidy is what has me hung up. I am ...

Template Classes in C++ ... a required skill set?

I m new to C++ and am wondering how much time I should invest in learning how to implement template classes. Are they widely used in industry, or is this something I should move through quickly?

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

typedef ing STL wstring

Why is it when i do the following i get errors when relating to with wchar_t? namespace Foo { typedef std::wstring String; } Now i declare all my strings as Foo::String through out the program, ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

Window iconification status via Xlib

Is it possible to check with the means of pure X11/Xlib only whether the given window is iconified/minimized, and, if it is, how?

热门标签