使用openCV创建超级矩阵 [英] Creating a super matrix using openCV

查看:287
本文介绍了使用openCV创建超级矩阵的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须创建一个4800 x 5超级矩阵。该矩阵将由5个大小为80 x 60的图像组成,我已经使用cvReshape将其重新整形为4800 x 1的矩阵。因此,我现在想将这些图像放在另一个上,以获得尺寸为4800 x 5的超级矩阵。如何使用openCV进行此操作?我现在已经尝试了很长一段时间,这很快就要到了,但我并没有接近实现这个矩阵的创建。如果有人能帮助我,我真的很感激。到目前为止这是我的代码。但是,它不起作用,更不用说给出我想要的输出了。

I have to create a 4800 x 5 super matrix. This matrix will consist of 5 images of size 80 x 60 which I have already reshaped into matrices of 4800 x 1 using cvReshape. Therefore, I would now like to place these images next to the other to get a super matrix of dimensions 4800 x 5. How can I go about doing this using openCV? I have been trying all a long while now and this is due soon but I am no closer to achieving the creation of this matrix. I would really appreciate if someone could please help me. This is my code so far. However, it is not working, much less for giving the output I want.

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

using namespace std; 

void cvDoubleMatPrint (const CvMat* mat)
{
int i, j;
for (i = 0; i < mat->rows; i++)
{
    for (j = 0 ; j < mat->cols; j++)
    {
        printf ( "%f ", cvGet2D (mat, i , j));
    }
    printf ( "\n" );
}
}


int main( int argc, char* argv ) 
{ 
CvMat *img0, *img1,  *img0_mat, *img1_mat, *col0, *col1, *superMat, *col0_mat, *col1_mat, *superMat_mat = NULL;

img0 = cvLoadImageM("C:\\small\\walk mii.jpg", CV_LOAD_IMAGE_UNCHANGED);    
img1 = cvLoadImageM("C:\\small\\wave mii.jpg", CV_LOAD_IMAGE_UNCHANGED);    
img0_mat = img0;
img1_mat = img1;//what does this do!!!

CvMat col0_header, col1_header, superMat_header, img0_header, img1_header;

col0 = cvReshape(img0_mat, &img0_header, 0, 4800);
col1 = cvReshape(img1_mat, &img1_header, 0, 4800);
col0_mat = col0;
col1_mat = col1;

superMat = cvCreateMat(4800, 2, CV_8UC1);
superMat_mat = superMat;

for(int i = 0; i < 2; i++)
{
    cvGetCol(col0_mat, &col0_header, 1);
    cvGetCol(superMat_mat, &superMat_header, 1);
    cvCopy(col0_mat, superMat_mat);
}

cvDoubleMatPrint(superMat_mat);

cvWaitKey(0);
return 0;
}


推荐答案

只需复制每个图像矩阵行按行代码如下所示:

Just copy each image matrix row by row as illustrated in the code below:

cv::Mat superMat;
cv::Mat rowImg1, rowImg2, ..

superMat.create(5,rowImg.cols,rowImg1.type());

for (int i=0;i<5;i++){
  rowImg1.copyTo(superMat.row(i));  
}

这篇关于使用openCV创建超级矩阵的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆