我怎么使用cvReshape? [英] How am I supposed to use cvReshape?

查看:303
本文介绍了我怎么使用cvReshape?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用cvReshape有2个版本的同一矩阵数据。例如这里,gray_img是一个100×100矩阵,gray_line是10000x1矩阵,指向相同的数据,但使用不同的报头。
这是我做的OpenCV中的文件如下:

I am trying to use cvReshape to have 2 versions of the same matrix data. For instance here, gray_img is a 100x100 matrix and gray_line is a 10000x1 matrix, pointing to the same data but with a different header. This is what I am doing in OpenCV following the documentation:

CvMat *  gray_img;
CvMat  gray_line_header;
CvMat * gray_line;
gray_img = cvCreateImage(100, 100, IPL_DEPTH_32F, 1);
gray_line = cvReshape(gray_img, &gray_line_header, 0, 10000);

这可以作为intented,但我觉得这是难以阅读和不优雅的。如果我理解正确,gray_line将指向gray_line_header所以我觉得我在这里有一个额外的变量。
是否有可能做我想做的不宣矩阵头或(而不是3)只有2矩阵声明?

This works as intented but I feel that this is difficult to read and not elegant at all. If I understand correctly, gray_line will point to gray_line_header so I feel like I have an extra variable here. Is it possible to do what I want without declaring a matrix header or with only 2 (instead of 3) matrices declarations?

感谢

推荐答案

您承诺的OpenCV的老C接口?随着C ++接口,你可以这样做:

Are you committed to OpenCV's old C interface? With the C++ interface, you could do this:

cv::Mat grayImg(100, 100, CV_32FC1);
cv::Mat grayLine(grayImg);
grayLine.reshape(1,10000); //1 column, 10000 rows

现在你有两个实例指向相同的数据。

Now you have two instances that point to the same data.

这篇关于我怎么使用cvReshape?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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