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 6528509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T09:32:28+00:00 2026-05-25T09:32:28+00:00

Using the new API for OpenCV 2.3, I am having trouble assigning values to

  • 0

Using the new API for OpenCV 2.3, I am having trouble assigning values to a Mat array (or say image) inside a loop. Here is the code snippet which I am using;

    int paddedHeight = 256 + 2*padSize; 
    int paddedWidth = 256 + 2*padSize;  

    int n = 266; // padded height or width

    cv::Mat fx = cv::Mat(paddedHeight,paddedWidth,CV_64FC1);
    cv::Mat fy = cv::Mat(paddedHeight,paddedWidth,CV_64FC1);        
    float value = -n/2.0f;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            fx.at<cv::Vec2d>(i,j) = value++;                    

        value = -n/2.0f;
    }

    meshElement = -n/2.0f;

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
            fy.at<cv::Vec2d>(i,j) = value;
        value++;
    }

Now in the first loop as soon as j = 133, I get an exception which seems to be related to depth of the image, I cant figure out what I am doing wrong here.

Please Advise! Thanks!
Error is here

  • 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-25T09:32:29+00:00Added an answer on May 25, 2026 at 9:32 am

    You are accessing the data as 2-component double vector (using .at<cv::Vec2d>()), but you created the matrices to contain only 1 component doubles (using CV_64FC1). Either create the matrices to contain two components per element (with CV_64FC2) or, what seems more appropriate to your code, access the values as simple doubles, using .at<double>(). This explodes exactly at j=133 because that is half the size of your image and when treated as containing 2-component vectors when it only contains 1, it is only half as wide.

    Or maybe you can merge these two matrices into one, containing two components per element, but this depends on the way you are going to use these matrices in the future. In this case you can also merge the two loops together and really set a 2-component vector:

    cv::Mat f = cv::Mat(paddedHeight,paddedWidth,CV_64FC2);
    float yValue = -n/2.0f;
    
    for(int i=0;i<n;i++)
    {
        float xValue = -n/2.0f;
    
        for(int j=0;j<n;j++)
        {
            f.at<cv::Vec2d>(i,j)[0] = xValue++;
            f.at<cv::Vec2d>(i,j)[1] = yValue;
        }
    
        ++yValue;
    }
    

    This might produce a better memory accessing scheme if you always need both values, the one from fx and the one from fy, for the same element.

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

Sidebar

Related Questions

I am converting some old OpenCV code using the C api to the new
I am creating a map using the new(ish) v3 of the Google Maps API
I am trying to create a new branch using the API, and have used
how to develop new facebook application (login , add photos ) using the api
When you allocate an array using new [] , why can't you find out
I'm using the new API to set the width of my jqGrid like this:
I started developing a Facebook app using the new Graph API. I want to
I'm trying to implement a payment system using the new PayPal API (Adaptive Payment).
Are there any caveats or short comings to using the new Task API in
I have really simple few lines of Facebook app, using the new Facebook API:

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.