opencv Mat与数组之间值传递

1. Mat数据传递给数组
如果Mat数据是连续的,可以直接转换它的数据到一维数组

Mat mat;
//方法1,vector
std::vector array(mat.rows*mat.cols);
if (mat.isContinuous())
    array = mat.data;
//方法2,数组
unsigned char *array=new unsigned char[mat.rows*mat.cols];
if (mat.isContinuous())
    array = mat.data;

2. 将数组传递给Mat

unsigned char cbuf[height][width];
cv::Mat mat(height, width, CV_8UC1, (unsigned char*)cbuf);

参考链接
http://blog.csdn.net/gh_home/article/details/52101778
http://stackoverflow.com/questions/26681713/convert-mat-to-array-vector-in-opencv

你可能感兴趣的:(opencv,opencv)