Ask Your Question
0

Crach on Video.calcOpticalFlowFarneback

asked 2013-10-13 08:06:13 -0600

Ioanna gravatar image

Hello, i am running the follwing code.

public static void main( String[] args ) { System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Mat mat = Mat.eye( 800, 600, CvType.CV_8UC1 ); Mat prev=Mat.ones( 800, 600, CvType.CV_8UC1 ); Mat next =Mat.ones( 800, 600, CvType.CV_8UC1 ); Mat flow=Mat.ones( 800, 600, CvType.CV_32FC2);

   //URL img_url = getClass().getResource("C:/Users/user/Desktop/Master Thesis/Sample images/Frame19.jpg"); 
   //String img_path = img_url.getPath();
   String prev_img_path ="C:/Users/user/Desktop/SampleImages/Frame19.jpg";
   String next_img_path ="C:/Users/user/Desktop/SampleImages/Frame40.jpg";

   prev = Highgui.imread(prev_img_path);
   next = Highgui.imread(next_img_path);

   Video.calcOpticalFlowFarneback(prev,next,flow,0.5,1, 1, 1, 7,1.5,0);
  System.out.println( "flow = " + flow.dump() );

}

and I am getting the following error OpenCV Error: Assertion failed (ssize.area() > 0) in unknown function, file ......\src\opencv\modules\imgproc\src\imgwarp.cpp, line 1723 Exception in thread "main" CvException [org.opencv.core.CvException: ......\src\opencv\modules\imgproc\src\imgwarp.cpp:1723: error: (-215) ssize.area() > 0 ] at org.opencv.video.Video.calcOpticalFlowFarneback_0(Native Method) at org.opencv.video.Video.calcOpticalFlowFarneback(Video.java:293) at openCvHello.main(openCvHello.java:29)

After debugging i found out the the issue is on this two rows prev = Highgui.imread(prev_img_path); next = Highgui.imread(next_img_path);

I do not know how to fix it I am so desperate. Also how can i show the image to know that i have the correct one?

Thanks in advance

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2015-04-26 01:11:26 -0600

I hope the following code you can help (java OpenCV 2.4.10 NetBeans IDE 7.3)

int Numkadr2 = -1;
Mat Kadr1N = new Mat();
Mat Kadr2N = new Mat();
public Mat detectMotion(Mat src) {
    if (Numkadr2 == -1) {
        Kadr1N = src.clone();
        Kadr2N = src.clone();
    }
    Numkadr2++;
    if (Numkadr2 == 1) {
        Kadr1N = src.clone();
    }
    if (Numkadr2 == 2) {
        Kadr2N = src.clone();
        Numkadr2 = 0;
    }
    Point pt1 = new Point();
    Point pt2 = new Point();
    Mat first_frame = new Mat();
    Mat second_frame = new Mat();
    Imgproc.cvtColor(Kadr1N, first_frame, Imgproc.COLOR_BGR2GRAY);
    Imgproc.cvtColor(Kadr2N, second_frame, Imgproc.COLOR_BGR2GRAY);
    Mat flow = new Mat(Kadr1N.size(), CvType.CV_32FC2);
    Video.calcOpticalFlowFarneback(first_frame, second_frame, flow, 0.5, 3, 15, 3, 5, 1.1, 0);
    Mat outMat = frame.clone();

    for (int i = 0; i < Kadr1N.size().height; i += 30) {
        for (int j = 0; j < Kadr1N.size().width; j += 30) {
            pt1.x = j;
            pt1.y = i;
            pt2.x = j + flow.get(i, j)[0];
            pt2.y = i + flow.get(i, j)[1];
            Scalar color = new Scalar(255, 255, 0, 255);
            Core.line(outMat,
                    pt1,
                    pt2,
                    color, 2, 8, 0);
        }
    }
    return outMat;
}

image description
Источник : http://me10.sblo.jp/archives/20140225...

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-10-13 08:06:13 -0600

Seen: 745 times

Last updated: Oct 13 '13