Ask Your Question
0

farneback optical flow in opencv for java

asked 2013-10-06 15:00:53 -0600

Ioanna gravatar image

Hello, As i find out there is implementation for the Farneback optical flow in openCV c, c++ and java. Is there any implementation in java?

Thanks in advance, Ioanna

edit retag flag offensive close merge delete

Comments

berak gravatar imageberak ( 2013-10-06 15:48:41 -0600 )edit

Thank you very much!

Ioanna gravatar imageIoanna ( 2013-10-10 14:49:01 -0600 )edit

Finally i installed openCV successfully. However it is so hard to define the variables and to use the function..Is there any manual which can help very beginners for java?

Ioanna gravatar imageIoanna ( 2013-10-12 09:29:53 -0600 )edit

hey, nice to hear, that you got it running now ;)

unfortunately, there are no real beginner-tutorials for java. there are some for android, but apart from the same language, pretty much different situation.

berak gravatar imageberak ( 2013-10-12 10:14:00 -0600 )edit

I used to use openCv in c++ and it was awesome. Know i can really to something! Let's say i am trying to to the following:

import org.opencv.core.Core;

import org.opencv.core.CvType; import org.opencv.core.Mat;

public class openCvHello { public static void main( String[] args ) { // System.loadLibrary( Core.NATIVE_LIBRARY_NAME );

   System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
    Mat mat = Mat.eye( 3, 3, CvType.CV_8UC1 );

   Mat prev=Mat.ones( 3, 3, CvType.CV_8UC1 );
   Mat next=Mat.ones( 3, 3, CvType.CV_8UC1 );
   Mat flow=Mat.ones( 3, 3, CvType.CV_8UC1 );
   calcOpticalFlowFarneback(prev,next,flow,0.5,1, 1, 1, 7,
           1.5,1);
  System.out.println( "mat = " + mat.dump() );

} }

However, i am getting this error:

Ioanna gravatar imageIoanna ( 2013-10-12 10:24:45 -0600 )edit

Exception in thread "main" java.lang.Error: Unresolved compilation problem: The method calcOpticalFlowFarneback(Mat, Mat, Mat, double, int, int, int, int, double, int) is undefined for the type openCvHello

at openCvHello.main(openCvHello.java:17). 
   Can you help me please!! 
   You will be my hero!
Ioanna gravatar imageIoanna ( 2013-10-12 10:26:07 -0600 )edit

hey ;)

  • it should be Video.calcOpticalFlowFarneback(...) // there's no 'free' functions in java, the replacement for this are static members of a (static, again) module class, Highgui.imread(...); Imgproc.cvtColor(...); and such, you'll get the picture..
  • from the doc page, again: flow - computed flow image that has the same size as prev and type CV_32FC2.

    so the type for your flow mat is wrong here, too. should be CvType.CV_32FC2 instead. that 'flow' matrix will hold the x and y movement for each pixel

also, chuckle a bit about things being peculiar in java here

berak gravatar imageberak ( 2013-10-12 10:53:58 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2013-10-12 14:58:58 -0600

Ioanna gravatar image

updated 2013-10-13 07:29:33 -0600

Thank you so much. Definitely you are my hero :). Can i ask a last questions? How can i show the image to be sure that the variables are not empty and how to show the flow image to make sense to me!? Thank you in advance :)

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-10-06 15:00:53 -0600

Seen: 1,595 times

Last updated: Oct 06 '13