Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7050309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:07:40+00:00 2026-05-28T03:07:40+00:00

I am having a problem with my code. A snippet of my code is

  • 0

I am having a problem with my code. A snippet of my code is mentioned below

These are some sample values which I read

116 117 77 0.170833333333333 0.341880341880342 

FILE* fid= fopen("treewall","r");

            while (fscanf(fid,"%f",&a)==1)
            {
                    printf("%f\n",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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:07:41+00:00Added an answer on May 28, 2026 at 3:07 am

    Below is a simplified sample of what you are trying to do. This works correctly on my machine using OpenCV 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;
    }
    

    However, I’m not sure what you are trying to achieve with these lines:

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

    You are grabbing the entire matrix as a “submatrix”, so data1 is equivalent to data; likewise, classes1 is equivalent to classes. So, why not just use the data and classes pointers directly?

    More info is needed to completely solve your issue I think…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having a problem with the specific set of values in this code snippet.
I'm having a problem with some code I've written. I've had to anonymize it,
I'm having a problem with some code that used to work in PHP 4.X
Having a problem getting a TreeView control to display node images. The code below
Below is a small snippet the illustrates the problem I'm having related to the
I'm having a really bizarre problem wherein the watch window values for some variables
Having a problem with the dataGridView control being populated with Display members: Code: private
I'm having a problem with my Seam code and I can't seem to figure
I'm having a problem with mixing managed and unmanaged code. I have created two
I'm having a problem getting a change event to register with the following code:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.