本文介绍了将vec3b转换成mat的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 im
中有彩色图像,我想使用以下代码使用vec3b获取3通道图像的像素值
for(int i = 0; i {
for(int j = 0; j {
for(int k = 0; k {
zay [k] = im.at< Vec3b& ,j)[k]; //获取像素值并赋值给新的vec3b变量zay
}
}
}
之后,我想将以下mat 3x3过滤器乘以zay中的vec3b
Filter =(Mat_< double>(3,3)< 0,1,0,
0,0,0);
如何将vec3b转换为mat矩阵,而vec3b是一个数组3x1?
感谢
解决方案未尝试但应该工作:
cv :: Mat DoubleMatFromVec3b(cv :: Vec3b in)
{
cv :: Mat mat(3,1,CV_64FC1);
mat.at< double>(0,0)= in [0];
mat.at< double>(1,0)= in [1];
mat.at< double>(2,0)= in [2];
return mat;
};
I have color image in im
, i want to get the pixel value of 3 channels image using vec3b using the following code
for (int i = 0; i < im.rows; i++)
{
for (int j = 0; j < im.cols; j++)
{
for (int k = 0; k < nChannels; k++)
{
zay[k] = im.at<Vec3b>(i, j)[k]; //get the pixel value and assign to new vec3b variable zay
}
}
}
After that, i want to multiply the following mat 3x3 filter with that vec3b in zay
Filter= (Mat_<double>(3, 3) << 0, 0, 0,
0, 1, 0,
0, 0, 0);
How to convert vec3b into mat matrix so i can multiplied with mat Filter?? And vec3b is an array 3x1?Thanks
解决方案 Didnt try but should work:
cv::Mat DoubleMatFromVec3b(cv::Vec3b in)
{
cv::Mat mat(3,1, CV_64FC1);
mat.at <double>(0,0) = in [0];
mat.at <double>(1,0) = in [1];
mat.at <double>(2,0) = in [2];
return mat;
};
这篇关于将vec3b转换成mat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!