问题描述
我使用的是Ubuntu 12.04和opencv 2
I am using Ubuntu 12.04 and opencv 2
我写了以下代码:
IplImage* img =0;
img = cvLoadImage("nature.jpg");
if(img != 0)
{
Mat Img_mat(img);
std::vector<Mat> RGB;
split(Img_mat, RGB);
int data = (RGB[0]).at<int>(i,j)); /*Where i, j are inside the bounds of the matrix size .. i have checked this*/
}
问题是在数据变量中我得到负值和非常大的值。我想我在某个地方犯了一些错误。你能指出来吗?
我一直在阅读文档(我没有完成它..它是相当大。)但是从我已经阅读,这应该工作。但它不是。这是怎么回事?
The problem is I am getting negative values and very large values in teh data variable. I think I have made some mistake somewhere. Can you please point it out.I have been reading the documentation (I have not finished it fully .. it is quite large. ) But from what I have read, this should work. But it isnt. What is going wrong here ?
推荐答案
Img_mat
。每个通道由数据类型中的像素值 uchar
组成。
因此 split(Img_mat,BGR)
Img_mat
分为3个平面的蓝色,绿色和红色,它们被共同存储在向量 BGR
中。因此 BGR [0]
是 uchar
数据类型像素的第一个(蓝色)
Img_mat
is a 3 channeled image. Each channel consists of pixel values uchar
in data type.So with split(Img_mat, BGR)
the Img_mat
is split into 3 planes of blue, green and red which are collectively stored in a vector BGR
. So BGR[0]
is the first (blue) plane with uchar
data type pixels...hence it will be
int dataB = (int)BGR[0].at<uchar>(i,j);
int dataG = (int)BGR[1].at<uchar>(i,j);
等等...
strong> @bsdnoobz 我想你想写
@bsdnoobz I think you wanted to write
Vec3b data = Img_mat.at<Vec3b>(i,j);
data[0] = // blue pixel
data[1] = // green pixel
等等...
这篇关于在opencv中使用Mat :: at(i,j)获取2-D Mat对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!