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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T21:54:18+00:00 2026-06-06T21:54:18+00:00

I am pushing Mat objects into a std::vector. But, when I try to access

  • 0

I am pushing Mat objects into a std::vector.

But, when I try to access the elements (Mat) after that, it did not give me the images pushed in earlier, depending on frameOrientation.

E.g., in the case below,i get “after_push_rotated2.jpg” same as “before_push_rotated3.jpg”, which should not be.

If I set frameOrientation to all “2s” or “4s”, “after_push_rotated1/2/3.jpg” all are identical and equals “before_push_rotated3.jpg”.

What is wrong here?

#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>
#include <vector>

using namespace cv;
using namespace std;

vector<Mat> checkOrientationAndRotate()
{
    Mat frame1 = imread("1.jpg" );
    Mat frame2 = imread("2.jpg" );
    Mat frame3 = imread("3.jpg" );



    vector<Mat> frameList;
    vector<Mat> frameList_rotated;

    frameList.push_back(frame1);
    frameList.push_back(frame2);
    frameList.push_back(frame3);

    Mat transposedFrame;
    Mat rotatedFrame;

    int i=0;
    for (vector<Mat>::iterator iter = frameList.begin(); iter != frameList.end(); iter++)
    {
        //Check for orientation of that frame
        int frameOrientation;
        if (i==0) frameOrientation = 1;
        if (i==1) frameOrientation = 2;
        if (i==2) frameOrientation = 4;

        switch (frameOrientation)
        {
        case 1: //1 - no rotate
            rotatedFrame = *iter;
            break;

        case 2: //2 - rotate it ACW 90 deg
            transpose(*iter, transposedFrame);
            flip(transposedFrame, rotatedFrame, 0);
            break;

        case 3: //3 - rotate it 180deg
            flip(*iter, rotatedFrame, -1);
            break;

        case 4: //4 - rotate it CW 90 deg
            transpose(*iter, transposedFrame);
            flip(transposedFrame, rotatedFrame, 1);
            break;
        default:
            break;
        }

        //Check frame before pushing into vector
        if (i==0) imwrite("before_push_rotated1.jpg",rotatedFrame);
        if (i==1) imwrite("before_push_rotated2.jpg",rotatedFrame);
        if (i==2) imwrite("before_push_rotated3.jpg",rotatedFrame);

        frameList_rotated.push_back(rotatedFrame);


        //Check frame after pushing into vector.
        //Depending on the frameorientation, the frames are not the frames pushed in earlier!
        int n=0;
        for (vector<Mat>::iterator iter = frameList_rotated.begin(); iter != frameList_rotated.end(); iter++)
        {
            Mat frame = *iter;
            if (n==0) imwrite("after_push_rotated1.jpg",frame);
            if (n==1) imwrite("after_push_rotated2.jpg",frame);
            if (n==2) imwrite("after_push_rotated3.jpg",frame);
            n++;
        }

        i++;
        } //for

        return frameList_rotated;

}

void main()
{
    vector<Mat> frameList_rotated = checkOrientationAndRotate();
}
  • 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-06T21:54:20+00:00Added an answer on June 6, 2026 at 9:54 pm

    [I didn’t use OpenCV anytime recently, so I could be wrong, please let me know if I am :)]

    Mat represents (sort of) image header, not the image data. OpenCV maintains, internally, a reference counting mechanism to avoid large amounts of image-pixel-data being copied across different areas. Meaning to say that when you say:

    Mat a = b; // Only headers are copied, both a and b refer to the same image.
    

    In the above case, if you modify b, the change will be reflected in a as well. What you need to use in that case is:

    Mat a = b.clone();
    

    About your case, I really think the following line should fix the problem (and if not, there’s probably some other problem with the control flow, hehe):

    Try replacing:

    Mat transposedFrame;
    Mat rotatedFrame;
    

    with:

     //create a new image, not just the headers..
    Mat transposedFrame(Size(image_width, image_height), image.type());
    Mat rotatedFrame(Size(image_width, image_height), image.type());
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pushing elements into an array during a while statement. Each element is a
I am pushing XML data into an Excel Table via C#, but when I
After pushing to a git repo, I got this error: [trusktr@starlancer bml]$ git push
When pushing to Github, I want to .gitignore my database.yaml file so that I
So after pushing my app to heroku, I tried to migrate database to heroku.
This is probably pushing the boundaries of Linq-to-Sql a bit but given how versatile
I am pushing a bunch of views to my navigation controller but on some
When pushing objects from ColdFusion to Flex via BlazeDS, and mapping the classes using
This might be pushing things a little too far, but mostly out of curiosity..
This might be pushing the limits here. I iframe some external websites into one

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.