goodFeaturesToTrack crashing or producing one dimensional vector

asked 2015-05-06 14:20:48 -0600

Amr gravatar image

I am trying to implement optical flow in Vs2008 using opencv2.4.11 I use the following code:

 Mat img = imread("t.JPeG", CV_LOAD_IMAGE_UNCHANGED);//read the image data  
vector<Point2f> corn;
 goodFeaturesToTrack(img,corn,100,0.01,0.01);

I get an error when I run the code and it crashes it says due to opencv_core2411d.dll

when I modify the code to:

 Mat corn instead of  vector<Point2f> corn;

the code runs however, it produces the corn vector 100 rows by 1 column i.e. there is no xy it is only x I assume is that normal? how to infer the coordinates of the features then?

edit retag flag offensive close merge delete

Comments

the x,y components are hidden in the 'pixels' in this case. try :

for ( int i=0; i<corn.rows; i++)
    cerr << corn.at<Vec2f>(i) << endl;

(but rather, really use a vector<point>. the outcome is a list of points, not an image)

berak gravatar imageberak ( 2015-05-06 14:24:57 -0600 )edit

@berak The problem is that the goodfeaturestotrack function fails as soon as I pass a vector to it but when I pass a MAT to it I see it is working. I did cout corn.cols " " corn.rows ; and I am getting 1 and 100 so the array is one dimensional but I thought it should be 2 dimensional

Amr gravatar imageAmr ( 2015-05-06 14:32:52 -0600 )edit

hmm. yes it's a one dimensional thing with 2 components.

i don't see, why it would crash with vector<point2f> though. any errors ? where's your code ?

berak gravatar imageberak ( 2015-05-06 14:36:14 -0600 )edit

"I am trying to implement optical flow" - trying to reinvent the wheel ?

berak gravatar imageberak ( 2015-05-06 14:38:34 -0600 )edit

@berak No but I need to extract features before using LK method for optical flow. The code that yields the error (when running) is vectors one:

Mat img = imread("t.JPeG", CV_LOAD_IMAGE_UNCHANGED);//read the image data  
    vector<Point2f> corn;
     goodFeaturesToTrack(img,corn,100,0.01,0.01);

The code produces an error as soon as it goes to the function the error is:Unhandled exception at 0x535451bf in P3DX.exe: 0xC0000005: Access violation writing location 0xcccccccc.

The call stack stops at: opencv_core2411d.dll with a yellow arrow

I am using VS2008 32 debug my laptop is 64 bit and the version of openCV is 2.4.11 I used the dll from opencv\build\x86\vc10\bin

Amr gravatar imageAmr ( 2015-05-06 14:49:40 -0600 )edit

oh, that's an easy catch (though painful):

you simply can't use the vc10 libs with vs2008. if you're bound to this (like me ;() you've got to build opencv libs from scratch (using cmake)

berak gravatar imageberak ( 2015-05-06 15:15:18 -0600 )edit

Oh I see unfortunately I am new to openCv and programming and I do not think I can do that, do you suggest downloading an earlier version of opencV? if so what version do you think will work? I do not have an idea what is cmake the only license I have is VS2008 do I need vc08 ?

Amr gravatar imageAmr ( 2015-05-07 04:40:45 -0600 )edit

i would not recommend getting an older opencv version.

either update your vs, or bite the apple and compile the libs with vs2008 (and cmake), it's really doable (though there is probably no more official support for vs2008 from the opencv side)

berak gravatar imageberak ( 2015-05-07 04:46:22 -0600 )edit

@berak

Thanks for help I followed a tutorial on using cmake and tried it myself using opencv2.4.9 but when I build the vs file created by cmake it produces errors. I tried another version 2.3.1 which had vc9 in it but then my exe crashes as soon I declare a Mat instant it says error msvcr90d.dll error in fopen.c the error is access violation what could be the cause?

Amr gravatar imageAmr ( 2015-05-10 12:31:29 -0600 )edit

please, do not even try to use opencv2.3.1 . it's best-before-date is long over. (and noone can help you/is interested with that)

again, either update visual studio, or build current codebase from src

berak gravatar imageberak ( 2015-05-10 12:36:47 -0600 )edit