C ++ OpenCV mat.at在使用数据时提供访问冲突 [英] C++ OpenCV mat.at gives access violation when using data

查看:1425
本文介绍了C ++ OpenCV mat.at在使用数据时提供访问冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个Visual Studio 2010 C ++ dll中使用openCV 2.1做矩阵运算。 dll从一个VB.NET程序接收数组,并将它们加载到矩阵中进行一些操作。但是我不能在任何cv :: mat对象上使用.at成员,而不会引发访问冲突异常。我认为这是因为我在传递数组,但我甚至不能运行这个:

I'm using openCV 2.1 in a visual studio 2010 C++ dll to do matrix operations. The dll recieves arrays from a VB.NET program and loads them into matrices for some manipulation. However I cannot use the .at member on any cv::mat object without throwing an access violation exception. I thought it was because I was passing in the arrays but I cannot even run this:

Mat Rhat(2,1,CV_32FC1);
Rhat.at<double>(0,0) = 10;
Rhat.release();

如果我删除 .at 它运行良好。我使用CvMat类型完成了整个事情,但它不喜欢cvCreateMat,并开始使用cv命名空间。所有我的非opencv函数在dll工作正常,所以问题是在我的cv设置或某事。
任何人都可以帮助吗?

If I remove the .at line then it runs fine. I had the whole thing done with C using CvMat types but it didn't like cvCreateMat and started working with the cv namespace instead. All my non opencv functions in the dll work fine so the problem is in my cv setup or something.
Can anyone help?

推荐答案

问题是,你创建了一个float(32FC1)的矩阵,你正在尝试使用double访问它导致一个out的绑定访问。

The problem is that your created a matrix of float (32FC1) and you are trying to access it using double which causes an out of bound access.

使用float无处不在:

You can either use float everywhere:

Mat Rhat(2,1,CV_32FC1);
Rhat.at<float>(0,0) = 10;
Rhat.release();

或双重:

Mat Rhat(2,1,CV_64FC1);
Rhat.at<double>(0,0) = 10;
Rhat.release();

这篇关于C ++ OpenCV mat.at在使用数据时提供访问冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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