I am currently working on a Play 2.1 project in which requests for a web service will process the loading of user images, their re-sorting and re-cropping, as well as filtering of known bad photos (for example, we do not want users to upload company logos). We are trying to use OpenCV to handle background work, but I can't get IntelliJ to add an OpenCV banner in a way that works with a java project.
I was able to create OpenCV from source without problems. This left me with the following folder: / home / charles / opencv / letting go
Inside this folder, I have three files of interest:
- bin / opencv -246.jar
- Library / cv 2.so
- Library / libopencv _java246.so
If I try to add the jar file to IntelliJ as a new Java library, it seems to find all the classes / methods, and I can write the code using autocomplete. I can also click on the appropriate classes or methods, and this leads me to the correct files.
However, when I try to start the Play project, I get this error:
[info] Loading project definition from /home/charles/Github/ImageProject [info] Set current project to ImageProject (in build file:/home/charles/Github/ImageProject/)
I also tried adding a copy of the jar file directly to the project (to put opencv-246.jar in ImageProject / lib), and then instead adding the java library from this place. But that just leaves me with another error:
java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path
I suspect that part of the problem may be related to the native libraries that the Java OpenCV shell uses (file 2 or 3 above). In Eclipse, when you add a jar file, you can explicitly specify the location of your own library, which makes OpenCV great. I read suggestions about using this to fix the problem:
-Djava.library.path=/home/charles/opencv/release/lib
But this does not work (although maybe I am installing it in the wrong place? I tried to install it as a JVM parameter in the startup configuration for the project and in the IDE settings, but none seem to be used or respected).
Note. To clarify again, this is a Play2 project, not an Android project. It seems that there is some special help from Android, which in this case is not relevant.
It seems like it should be fairly straightforward, but I have been trying to find the answer at this point for several days and still have nothing. Any ideas?
Additional Information: I also tried following the “Launches SBT Samples” OpenCV documentation here: http://docs.opencv.org/doc/tutorials/introduction/desktop_java/java_dev_intro.html
And I also get a similar error:
charles@charles-VirtualBox :~/JavaSample$ sbt run [info] Loading project definition from /home/charles/JavaSample/project [info] Set current project to JavaSample (in build file:/home/charles/JavaSample/) [info] Compiling 1 Java source to /home/charles/JavaSample/target/scala-2.10/classes... [info] Running HelloOpenCV Hello, OpenCV [error] (run-main) java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path java.lang.UnsatisfiedLinkError: no opencv_java246 in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1856) at java.lang.Runtime.loadLibrary0(Runtime.java:845) at java.lang.System.loadLibrary(System.java:1084) at HelloOpenCV.main(HelloOpenCV.java:47) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:601) [trace] Stack trace suppressed: run last compile:run for the full output. java.lang.RuntimeException: Nonzero exit code: 1 at scala.sys.package$.error(package.scala:27) [trace] Stack trace suppressed: run last compile:run for the full output. [error] (compile:run) Nonzero exit code: 1 [error] Total time: 2 s, completed Jul 17, 2013 5:11:39 PM