How to get pixel matrix and change matrix in openCV

I implement an image processing algorithm in C ++ using openCV, in which the first step is to convert the image to a matrix. I know that when an image is uploaded to openCV, it is already saved as a matrix. The image that I use is 80 x 60 in size, so I assume that the matrix in which it is stored is 80 x 60 in size. However, I would like to see this matrix first, and then be able to resize it to a matrix with that same number. pixels, but instead uses one long column. those. the 80 x 60 matrix will now become the 4800 x 1 matrix. I tried to research textbooks online, but to no avail. This is my code so far. In any case, it does not work, because I cannot convert from "IplImage" to "CvMat",but how else should I assign pixel values ​​in the matrix after creating it? Please, I would really appreciate if someone would 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;
}
+5
1

Mat::reshape(int cn, int rows=0):

* . / . , :

1) , . ,

2) * cols * channels() .

, .. O (1). , - , . . Mat:: isContinuous().

... , , cvReshape. - :

#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;
}
+1

All Articles