使用cvGet2D OpenCV函数 [英] Using cvGet2D OpenCV function

查看:345
本文介绍了使用cvGet2D OpenCV函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用OpenCV中的函数cvGet2D从图像中获取信息.

I'm trying to get information from an image using the function cvGet2D in OpenCV.

我创建了一个包含10个IplImage指针的数组:

I created an array of 10 IplImage pointers:

IplImage *imageArray[10];  

并且我要从网络摄像头中保存10张图像:

and I'm saving 10 images from my webcam:

imageArray[numPicture] = cvQueryFrame(capture);  

当我调用函数时:

info = cvGet2D(imageArray[0], 250, 100);  

其中info:

CvScalar info;  

我得到了错误:

OpenCV错误:cvPtr2D,文件/build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp,第1824行中的参数错误(无法识别或不受支持的数组类型)
抛出'cv :: Exception'实例后调用终止终止
what():/build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp:1824:错误:(-5)函数cvPtr2D中无法识别或不支持的数组类型

OpenCV Error: Bad argument (unrecognized or unsupported array type) in cvPtr2D, file /build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp, line 1824
terminate called after throwing an instance of 'cv::Exception'
what(): /build/buildd/opencv-2.1.0/src/cxcore/cxarray.cpp:1824: error: (-5) unrecognized or unsupported array type in function cvPtr2D

如果我使用函数cvLoadImage初始化IplImage指针,然后将其传递给cvGet2D函数,则代码将正常工作:

If I use the function cvLoadImage to initialize an IplImage pointer and then I pass it to the cvGet2D function, the code works properly:

IplImage* imagen = cvLoadImage("test0.jpg");
info = cvGet2D(imagen, 250, 100);  

但是,我想使用已经存储在数组中的信息.

however, I want to use the information already stored in my array.

您知道我该如何解决吗?

Do you know how can I solve it?

推荐答案

是的,消息正确.

如果要存储像素值,则需要执行以下操作.

If you want to store a pixel value you need to do something like this.

int value = 0;
value = ((uchar *)(img->imageData + i*img->widthStep))[j*img->nChannels +0];
cout << "pixel value for Blue Channel and (i,j) coordinates: " << value << endl;

总而言之,要绘制或存储数据,必须创建一个整数值(像素值在0到255之间变化).但是,如果您只想测试像素值(如if闭包之类的东西),则可以直接访问像素值,而无需使用整数值.

Summarizing, to plot or store data you must create an integer value (pixel value varies between 0 and 255). But if you only want to test pixel value (like in an if closure or something similar) you can access directly to pixel value without using an integer value.

我认为刚开始时有点奇怪,但是当您使用它2到3次时,您将毫无困难地工作.

I think thats a little bit weird when you start but when you work with it 2 o 3 times you will work without difficulties.

这篇关于使用cvGet2D OpenCV函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆