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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:27:03+00:00 2026-05-12T10:27:03+00:00

well i have most probably an extremly stupid problem but could not figure it

  • 0

well i have most probably an extremly stupid problem but could not figure it out and I m about to lose my sanity hope someone can help

vector<CvMat*> sample;
for(int x = 0; x < 29; x += 2)
{
    for(int b = 0; b < 22; b += 2)
    {
      cvmSet(g, 0, b, cvmGet(NormalVector, 0, x + b));
      cvmSet(g, 0, b + 1, cvmGet(NormalVector, 0, x + b + 1));
    }
    sample.push_back(g);
}

Well i m using OpenCv for some matrix calculations basiacllay what I m doing is I m creating some small matrices from a big matrix and putting them into a Vector called “sample” in here.First loop is just a counter based thing and second loop for creating the small matrices after the second loop i m putting them to the vector

But the problem is after these loops when i try to reach one of the matrices in the vector I always get the one that was put into the vector at last.
I use these methods to access the vector elements
sample[0];
sample.at(6);
For these two I get the same matrix that was added to the vector at the end .What is the thing I am doing wrong?

  • 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-12T10:27:04+00:00Added an answer on May 12, 2026 at 10:27 am

    Since your sample vector is a list of pointers, you will need to make sure that you create a new instance of CvMat for each element that you add to the vector. Otherwise, it sounds like all your elements are pointing to the same thing (g).

    If CvMat has a copy constructor, you may be able to fix it by doing this:

    vector <CvMat> sample;
    for(int x =0 ; x<29; x+=2) {
        // ...
        sample.push_back(*g);
    }
    

    This creates a vector of CvMat objects, and the push_back(*g) makes a copy of the matrix and pushes it on to the back of the vector.

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

Sidebar

Related Questions

I have an interesting situation, well it's probably not that unique at all, but
I have this question on the Wordpress stack exchange as well, but not having
This is probably trivial, and I do have a solution but I'm not happy
My title is probably not really describing the problem real well. I do not
We're using Infragistics grid (most probably, we'll have 8.2 version at the end) and
I probably won't be able to explain this well enough, but here it goes...
First, I understand the how of iteratees, well enough that I could probably write
I have recently read about how cursors should be avoided. Well, I would like
A SQL question, probably not the most difficult. I'm making a view from a
I've tried searching for this, but can't find anything similar. Most questions are about

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.