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

  • SEARCH
  • Home
  • 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 8382613
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T16:58:09+00:00 2026-06-09T16:58:09+00:00

I wrote the following code: int _tmain(int argc, _TCHAR* argv[]) { int vals[]={1,2,3,4,5,6,7,8,9}; CvMat

  • 0

I wrote the following code:

int _tmain(int argc, _TCHAR* argv[])
{

int vals[]={1,2,3,4,5,6,7,8,9};

CvMat mat = cvMat(3,3,CV_8UC1,vals);

for(int i=0;i<mat.rows;i++)
{
    int* ptr = (int*) (mat.data.ptr + i* mat.step);

    for(int j=0;j<mat.cols;j++)
    {
                printf("%d\t",*ptr++);

    }
    printf("\n");
}

return 0;
}

The output I got is:

1              2               3
512            768             1024
196608         262144          327680

The matrix is not initialized properly. The pointer ptr points to the beginning of each row and incrementing it gives the element in corresponding column. Is my assumption correct? Is there any mistake with the cvMat constructor used or the access method of elements?

  • 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-06-09T16:58:10+00:00Added an answer on June 9, 2026 at 4:58 pm

    Why dont you use the cv::Matclass?

    It has some handy functions which handle memory better.

    for declaring and initializing cv::Mat in your case the code will look like this:

    int main()
    {
       int vals[] = {1,2,3,4,5,6,7,8,9};
    
        Mat mat = cv::Mat(3, 3, CV_8UC1, vals).clone();
    
        for(int i = 0; i < mat.rows; i++)
        {
            for(int j = 0; j < mat.cols; j++)
            {
                 cout << mat.at<uchar>(j,i) << " ";
            }
            cout << endl;
        }
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using the following code to write to a file int main(int argc, char *
i wrote the following code.... #include< iostream> #include< fstream> using namespace std; int main()
I wrote the following code in a JSP file: <c:catch var=e> <% int accountNumber
For learning purposes, I wrote the following code snippet: for(int i=0;i<10;i++) { for(int j
I wrote the following code: void buildArrays(char *pLastLetter[],int length[], int size, const char str[])
I wrote the following code: int N; scanf(%d, &N); int i; for (i =
I have wrote the following code: int fd = _dup(fileno(stdout)); FILE* tmp = freopen(tmp,w+,stdout);
I made a simple experiment, I wrote the following code in Xcode: int main(int
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':

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.