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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:49:43+00:00 2026-05-31T11:49:43+00:00

I am implementing an image processing algorithm in C++ using openCV, in which the

  • 0

I am implementing an image processing algorithm in C++ using openCV, in which the 1st step requires that the image be converted to a matrix. I know that when an image is loaded into openCV, it is already stored as a matrix. The image that I am using is of size 80 x 60, so I am assuming that the matrix it is stored in is of size 80 x 60. However, I would like to first be able to see this matrix and then be able to reshape it into a matrix with the same no. of pixels but as one long column instead. i.e. the 80 x 60 matrix would now become a 4800 x 1 matrix. I have tried researching textbooks and online but to no avail. This is my code so far. In any case, it is not working because I cannot cannot convert from ‘IplImage *’ to ‘CvMat * but how else I am supposed to assign my pixel values to the matrix after creating it? Please, I would greatly appreciate if someone could help me with this code.

#include "cv.h"
#include "highgui.h"
#include "iostream"

using namespace std;
int main( int argc, char* argv ) {
IplImage* img0 = NULL;
CvMat* img0_mat = NULL ;
img0 = cvLoadImage("C:\\new\\walk mii.jpg");
if (!img0){
    return -1;}
img0_mat = cvCreateMat(80, 60, 1);
img0_mat = img0;
cout <<" matrix " << img0 << endl;

cvWaitKey(0);
return 0;
}
  • 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-31T11:49:44+00:00Added an answer on May 31, 2026 at 11:49 am

    You could call Mat::reshape(int cn, int rows=0):

    The method makes a new matrix header for *this elements. The new matrix may have different size and/or different number of channels. Any combination is possible, as long as:

    1) No extra elements is included into the new matrix and no elements are excluded. Consequently,
    the product

    2) rows*cols*channels() must stay the same after the transformation.

    No data is copied, i.e. this is O(1) operation. Consequently, if you change the number of rows, or the operation changes elements’ row indices in some other way, the matrix must be continuous. See Mat::isContinuous() .

    …it looks like you’re using an older version of the library though so you want cvReshape. Something like this should work:

    #include "cv.h" 
    #include "highgui.h" 
    #include "iostream" 
    using namespace std; 
    
    int main( int argc, char* argv ) 
    { 
        IplImage* img0 = NULL; 
        CvMat* img0_mat = NULL ; 
        img0 = cvLoadImage("C:\\new\\walk mii.jpg"); 
        img0_mat = cvCreateMat(80, 60, 1); 
    
        CvMat row_header, *row;
        row = cvReshape( img0_mat, &row_header, 0, 1 );
    
        cout << " matrix " << row->tostring() << endl; 
    
        cvWaitKey(0); 
        return 0;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I am taking a digital image processing class that requires implementing some image
I'm implementing the component labelling algorithm as in this paper using python and opencv.
I am using openCV to implementing camera motion compensation for an application. I know
I'm currently implementing some image processing code for Android. I'm aware of the memory
I'm implementing an upload form so that my users can upload a background image
I was implementing a simple laplacian filter for an image processing project i was
I'm implementing a basic speedometer using an image and rotating it. However, when I
I am implementing an image filtering operation in C using multiple threads and making
For a photography webpage I am implementing an image viewer that allows for selecting
I'm implementing a web application that is written in C++ using CGI. Is it

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.