crash when trying to use opencv CalcOpticalFlowLK

Hi all,
I’m trying to use the opencv function CalcOpticalFlowLK but am getting a crash and can’t find why.

I started with the zip supplied here http://forum.openframeworks.cc/t/movement-vector-from-video/555/6
which takes input from the camera, converts to greyscale, differences with prev frame etc.
I modified the VectorField class to have 2x linear arrays, u & v to store the horizontal and vertical values (instead of a 2 dimensional array of ofxVec2f) - tested it and worked fine - so no problems there.

Then in the update function I replaced the convertMotionHistoryToField function with the opticalflow function of opencv, making my update function:

  
camera.grabFrame();  
prev = grey;  
color.setFromPixels(camera.getPixels(), camera.width, camera.height);  
color.blur(15);  
color.mirror(false, true);  
grey = color;  
  
cvCalcOpticalFlowLK(grey.getCvImage()->imageData, prev.getCvImage()->imageData, cvSize, motionField.u, motionField.v);  

From what i can figure by looking around this should be correct, but I get a crash straight away with no useful info in the crash log… does anyone have any ideas what it could be?

(I’m on mac)

I found somewhere, that actually the void* in the function definition are not actually raw pixel and velocity data, but are IplImage* - and for the velocities they are single channel float. So I changed the code to:
setup:

  
  
IplImage* u;  
IplImage* v;  
  
CvSize cameraSize;  
cameraSize.width = camera.width;  
cameraSize.height = camera.height;  
u = cvCreateImage(cameraSize, IPL_DEPTH_32F, 1);   
v = cvCreateImage(cameraSize, IPL_DEPTH_32F, 1);   

update:

  
camera.grabFrame();  
prev = grey;  
color.setFromPixels(camera.getPixels(), camera.width, camera.height);  
grey = color;  
grey.blur(15);  
grey.mirror(false, true);  
cvCalcOpticalFlowLK(grey.getCvImage(), prev.getCvImage(), win_size, u, v);  

but still no luck! :S
Has anyone have any experience with this function? or similar?

I found this thread http://forum.openframeworks.cc/t/opencv-optical-flow/367/6 and the class there works fine… I don’t know why mine wasn’t working… but these classes saved the day! thanks takashi!