cummon questions for openCv in java-desktop

asked 2013-10-13 07:42:57 -0500

Ioanna gravatar image

Hello, I am a beginner in openCv in java-desktop.I used to use openCV for c++ and it was awesome.However, know I am lost.I have some questions because I stuck.

  1. How can i show/ display an image?
  2. How can i define an image with CvType.CV_8UC1 with out to know the size (Mat next =Mat.ones( ?, >, CvType.CV_8UC1 );) and then i load it from disk.

  3. I am using the following function Video.calcOpticalFlowFarneback(prev,next,flow,0.5,1, 1, 1, 7, 1.5,1); how can i use the flow matrix?

Thanks in advance, Ioanna

edit retag flag offensive close merge delete

Comments

for 2. there's an easy answer) :

Mat img = Highgui.imread("my.jpg")
berak gravatar imageberak ( 2013-10-13 08:02:29 -0500 )edit

thanks again for your help! However i am using this 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);

and i am getting this 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

Ioanna gravatar imageIoanna ( 2013-10-13 08:16:53 -0500 )edit

probably wise, to check, if the image was found/loaded: if ( prev.empty() ) { "bwaa!!" }

oh, and you have to load them as grayscale images (imread(path,0)) or convert them (Imgproc.cvtColor)

berak gravatar imageberak ( 2013-10-13 08:49:14 -0500 )edit

thanks!! it is empty! :)

Ioanna gravatar imageIoanna ( 2013-10-13 09:36:38 -0500 )edit

where i have to locate my image to find it? in the src directory?

Ioanna gravatar imageIoanna ( 2013-10-13 10:48:16 -0500 )edit

hmm, i'd say, using an absolute path was already a good idea. bit clueless here. check again, if it's really there. drop it onto a webbrowser or on paint, to see if it's maybe broken

berak gravatar imageberak ( 2013-10-13 10:53:58 -0500 )edit

Finally, the images are not empty but this error appeared: OpenCV Error: Assertion failed (prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1) in unknown function, file ......\src\opencv\modules\video\src\optflowgf.cpp, line 579 Exception in thread "main" CvException [org.opencv.core.CvException: ......\src\opencv\modules\video\src\optflowgf.cpp:579: error: (-215) prev0.size() == next0.size() && prev0.channels() == next0.channels() && prev0.channels() == 1 && pyr_scale < 1 ] at org.opencv.video.Video.calcOpticalFlowFarneback_0(Native Method) at org.opencv.video.Video.calcOpticalFlowFarneback(Video.java:293) at openCvHello.main(openCvHello.java:48) Video.calcOpticalFlowFarneback(prev,next,flow,0.5,1, 1, 1, 7,1.5 :(

Ioanna gravatar imageIoanna ( 2013-10-13 12:01:34 -0500 )edit

Can anyone help me!

Ioanna gravatar imageIoanna ( 2013-10-13 12:02:25 -0500 )edit