kallyani1989 / javacv

Automatically exported from code.google.com/p/javacv
GNU General Public License v2.0
0 stars 0 forks source link

Unable to use JavaCV in Matlab R2011b #130

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. install Matlab 2011b
2. install javacv from precompiled bin in */usr/share/java/*
3. run the matlab javacv example see code below:

javaaddpath('/usr/share/java/javacv.jar')
import com.googlecode.javacv.cpp.opencv_core.*
import com.googlecode.javacv.cpp.opencv_imgproc.*
import com.googlecode.javacv.cpp.opencv_highgui.*

image = cvLoadImage('/path/to/my/image.jpg')

What is the expected output? What do you see instead?
I get:
Undefined function 'cvLoadImage' for input arguments of type 'char'.
instead of the image loading.

What version of the product are you using? On what operating system?
I work on Ubuntu 11.10 with matlab R2011b and OpenCV 2.3.1a 

Please provide any additional information below.
I checked that opencv libraries are accessible using opencv examples and a 
program of mine. All is working well from the C/C++ side of the library. import 
function in Matlab is not displaying any information so i don't know if there 
is a problem while loading the class file associated with cvLoadImage.

Best regards,

Original issue reported on code.google.com by obrou...@gmail.com on 9 Nov 2011 at 4:30

GoogleCodeExporter commented 8 years ago
This will happen if you forgot to copy one of the JAR files, as explained in 
the README.txt file, required by your platform (javacpp.jar, 
javacv-linux-x86_64.jar, javacv-linux-x86.jar, javacv-macosx-x86_64.jar, 
javacv-windows-x86_64.jar, and javacv-windows-x86.jar). Please copy all of the 
JAR files, and let me know that it works, thank you.

Original comment by samuel.a...@gmail.com on 10 Nov 2011 at 4:16

GoogleCodeExporter commented 8 years ago
I'm sorry to inform you that it has been done in step 2 using cp *.jar 
/use/share/java/ as told in the readme. Is there any thing else that souls be 
done?
Best regards.

Original comment by obrou...@gmail.com on 10 Nov 2011 at 6:57

GoogleCodeExporter commented 8 years ago
Right, ok, MATLAB comes with its own bunch of system libraries in the `bin` 
directory, which can (almost always actually) conflict with the Linux system 
libraries you compiled OpenCV and what not against. Usually we get some sort of 
error when using things like javaaddpath() and import, but if that is not the 
case, you will need to figure out which libraries are in conflict, and pick the 
most recent one you have (either your Linux system ones, or MATLAB's ones) and 
make sure both MATLAB and OpenCV load the same version... good luck. :)

If you figure it out, please let us know which libraries caused you problems. 
Others might find the information helpful! thank you.

Original comment by samuel.a...@gmail.com on 10 Nov 2011 at 7:19

GoogleCodeExporter commented 8 years ago
Or maybe using the `mex` script file as compiler instead of GCC when 
configuring OpenCV with cmake could make it work ... 
http://www.vtk.org/Wiki/CMake:MatlabMex

Also, the more stuff you disable in OpenCV, the less it will depend on other 
libraries, so you could try to build a very slim version of OpenCV with 
everything disabled, and see what that gives...

Original comment by samuel.a...@gmail.com on 10 Nov 2011 at 7:30

GoogleCodeExporter commented 8 years ago
One more thing, to see the error, it may help to load the modules manually. We 
would get e.g.:

>> javaaddpath('/tmp/crap/javacv-bin/javacv.jar')
>> classLoader = com.googlecode.javacpp.Loader().getClass().getClassLoader();
>> class = classLoader.loadClass('com.googlecode.javacv.cpp.opencv_core');
>> com.googlecode.javacpp.Loader.load(class)
??? Java exception occurred:
java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path
    at java.lang.ClassLoader.loadLibrary(Unknown Source)
    at java.lang.Runtime.loadLibrary0(Unknown Source)
    at java.lang.System.loadLibrary(Unknown Source)
    at com.googlecode.javacpp.Loader.load(Loader.java:343)
    at com.googlecode.javacpp.Loader.load(Loader.java:271)
    at com.googlecode.javacv.cpp.opencv_core.<clinit>(opencv_core.java:126)
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Unknown Source)
    at com.googlecode.javacpp.Loader.load(Loader.java:291)

if the `libjniopencv_core.so` file is missing, but MATLAB would display errors 
concerning other missing files or functions that way too... Let me know what 
you get, for the other modules like `opencv_imgproc` and `opencv_highgui` as 
well, thanks.

Original comment by samuel.a...@gmail.com on 11 Nov 2011 at 4:08

GoogleCodeExporter commented 8 years ago
I tried what you proposed and I get an error that you may help me to understand.
Here is the code I used:
javaaddpath('/usr/share/java/javacv.jar')

classLoader = com.googlecode.javacpp.Loader().getClass().getClassLoader(); 
class = classLoader.loadClass('com.googlecode.javacv.cpp.opencv_core');
com.googlecode.javacpp.Loader.load(class) 

And here is the error Matlab returns me:
Static method or constructor invocations cannot be indexed.
Do not follow the call to the static method or constructor with
any additional indexing or dot references.

Error in test (line 3)
classLoader = com.googlecode.javacpp.Loader().getClass().getClassLoader();

Do you have any clue? The "Static method..." is strange for me what may be the 
cause of this warning?

Original comment by obrou...@gmail.com on 14 Nov 2011 at 2:12

GoogleCodeExporter commented 8 years ago
I solved my problem by installing the repository version of opencv and then 
rebuilding all the new opencv (2.3.1) over it.

As i needed libavcodec libavformat etc. I rebuild all ffmpeg (with x264, 
libtheora, ...) enabling both shared and static libraries maybe this helped but 
I won't be able to tell.

The problem is solved for me but maybe we can keep a trace in any case someone 
also get a similar problem.

regards,
Olivier.

Original comment by obrou...@gmail.com on 14 Nov 2011 at 6:24

GoogleCodeExporter commented 8 years ago
Do you mean that the official OpenCV 2.3.1 sources do not work, but the sources 
from the trunk here https://code.ros.org/svn/opencv/trunk/ do work?

Original comment by samuel.a...@gmail.com on 15 Nov 2011 at 10:36

GoogleCodeExporter commented 8 years ago
Well, I guess this issue has been resolved, but the problem with MATLAB is that 
it comes with its own duplicate set of libraries, so we may have to recompile 
OpenCV and JavaCV using those libraries, if we cannot make MATLAB use the 
system libraries... I added a comment about that on the Wiki page:
http://code.google.com/p/javacv/wiki/UsingJavaCVInMATLAB

Thanks for reporting this issue!

Original comment by samuel.a...@gmail.com on 12 May 2012 at 12:32