在OpenCV中将Mats保存为int数组 [英] Saving Mats into int arrays in opencv
本文介绍了在OpenCV中将Mats保存为int数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我把我的img分成3个单独的Mats,像这样:
I split my img into 3 separate Mats like this:
std::vector<Mat> planes(3);
cv::split(img, planes);
cv::Mat R = planes[2];
cv::Mat G = planes[1];
cv::Mat B = planes[0];
现在我想将这些R,G和Bs值存储在三个不同的数组中。这样的:
例如对于R。
Now I want to store these R, G and Bs values in three different arrays. Somthing like this: for example for R.
std::vector<Mat> planes(3);
cv::split(img, planes);
cv::Mat R = planes[2];
int r[20];
for (i=0 ; i<20 ; i++)
{
r[i]= R[i];
}
我知道这会给错误。
I know this will give error. So how do I correctly implement this feature ?
推荐答案
这里是如何做到这一点R ; G)
Here is how you can do this for R (with obvious extension to B & G)
std::vector<Mat> planes(3);
cv::split(img, planes);
cv::Mat R;
// change the type from uchar to int
planes[2].convertTo(R, CV_32SC1);
// get a pointer to the first row
int* r = R.ptr<int>(0);
// iterate of all data (R has to be continuous
// with no row padding to do it like this)
for (i = 0 ; i < R.rows * R.cols; ++i)
{ // you have to write the following :-)
your_code(r[i]);
}
这篇关于在OpenCV中将Mats保存为int数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文