在openv中将Mats保存为int数组
Saving Mats into int arrays in opencv
我把我的图片分成3个独立的垫子,像这样:
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和b的值存储在三个不同的数组中。像这样:例如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];
}
我知道这将给出错误。那么我如何正确地实现这个功能呢?
你就快到了:
std::vector<Mat> planes(3);
cv::split(img, planes);
cv::Mat R = planes[2];
int r[20];
unsigned char *Rbuff = R.data;
for (i=0 ; i<20 ; i++)
{
r[i]= (int)Rbuff[i];
}
这是你如何在R中做到这一点(明显扩展到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]);
}
相关文章:
- 按字符值访问int数组
- 将 int 数组转换为 std::vector<int*>
- C++,在int数组中输入字符串或字符会输出0,而不是ascii或error
- 整数区间(或 int 数组)中每个数字的出现次数
- Int 数组到C++容器
- C++ 未初始化的本地(非全局)int 数组中的元素类型到底是什么?
- 如何检测将文本文件读入 int 数组的新行
- C++快速将 int 数组内容转储到文本文件中
- <string> 如何在使用 SWIG 时将 int 数组和 List 作为参数传递给 C# C++
- 如何制作不允许重复值的 C++ int 数组循环?
- 如何将逗号分隔的文件读取为 2D int 数组?
- int 数组,但索引是字符?
- 使用可变参数函数将整数和/或整数数组放入单个 int 数组中
- 将 int 数组转换为带有小数C++的双精度数组
- 将双精度值分配给 int 数组时的类型转换
- 已编辑 我如何将其拆分为 char 和 int 数组
- 从 C++ 中的 int ** 数组访问元素
- C++程序无法分配 int 数组?
- 我正在编写一个代码来将 int 数组存储在文件中,然后用 c++ 检索它,但是检索第一项是假值,我该如何解决这个问题?
- 如何通过头文件中的函数初始化 const int 数组?