开发者

C++ OpenCV mat.at gives access violation when using data

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开发者_JAVA技巧 in my cv setup or something.

Can anyone help?


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:

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

or double:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜