|
-
April 30th, 2010, 01:20 PM
#1
"Access violation" when assigning matrix values
Hello,
I am writing a program to estimate the fundamental matrix between two images, using OpenCV. This is a computer vision technique, but the error I am getting is something to do with memory in the program itself. I have copied the code exactly from this reliable source: http://books.google.co.uk/books?id=s...xample&f=false
Here is the code below:
Code:
int main()
{
int point_count = 100;
CvMat* points1;
CvMat* points2;
CvMat* status;
CvMat* fundamental_matrix;
points1 = cvCreateMat(1,point_count,CV_32FC2);
points2 = cvCreateMat(1,point_count,CV_32FC2);
status = cvCreateMat(1,point_count,CV_8UC1);
/* Fill the points here … */
for(int i = 0; i < point_count; i++ )
{
points1->data.db[i*2] = 2;
points1->data.db[i*2+1] = 4;
points2->data.db[i*2] = 5;
points2->data.db[i*2+1] = 3;
}
fundamental_matrix = cvCreateMat(3,3,CV_32FC1);
int fm_count = cvFindFundamentalMat(
points1,points2,fundamental_matrix,
CV_FM_RANSAC,1.0,0.99,status );
return 0;
}
However, when this is run, I get the following error:
"Unhandled exception at 0x0040122b in TestProgram.exe: 0xC0000005: Access violation writing location 0x0037d000."
This occurs when i = 54, at the line "points2->data.db[i*2] = 5;"
It seems to be suggesting that I don't have enough memory to make this assignment, but I have reserved enough. My "points2" matrix contains 100 elements, each of type CV_32FC2 (which represent two floating points), and thus the matrix should be able to hold 200 floating points.
Furthermore, this code is copied exactly from the source, which is a reliable text book. So, the code should run, and I am very confused as to why I am getting this error.
Thanks for any help
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|