C++ OpenCV mat.at 使用数据时出现访问冲突
我在 Visual Studio 2010 C++ dll 中使用 openCV 2.1 进行矩阵运算。该 dll 从 VB.NET 程序接收数组并将它们加载到矩阵中以进行某些操作。但是,我无法在任何 cv::mat 对象上使用 .at 成员而不引发访问冲突异常。我认为这是因为我传递了数组,但我什至无法运行它:
Mat Rhat(2,1,CV_32FC1);
Rhat.at<double>(0,0) = 10;
Rhat.release();
如果我删除 .at
行,那么它运行正常。我使用 CvMat 类型用 C 完成了整个工作,但它不喜欢 cvCreateMat,而是开始使用 cv 命名空间。我在 dll 中的所有非 opencv 函数都工作正常,所以问题出在我的 cv 设置或其他东西上。
任何人都可以帮忙吗?
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();
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是您创建了一个浮点矩阵(32FC1),并且您尝试使用双精度访问它,这会导致越界访问。
您可以在任何地方使用 float:
或 double:
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.
You can either use float everywhere:
or double: