OpenCVやりたいー。
Javaだから、JavaCV使って見ようと思って、pom.xmlに追加するじゃないですか。
https://github.com/bytedeco/javacv
<dependency> <groupId>org.bytedeco</groupId> <artifactId>javacv</artifactId> <version>0.10</version> </dependency>
公式サイトの通り。
で、公式サイトの通りテストプログラムを書いてみる。
import org.junit.Test;
import static org.bytedeco.javacpp.opencv_core.*;
import static org.bytedeco.javacpp.opencv_imgproc.*;
import static org.bytedeco.javacpp.opencv_highgui.*;
public class HogeTest {
@Test
public void test1() {
IplImage image = cvLoadImage("/Users/hoge.jpg");
if (image != null) {
cvSmooth(image, image);
cvSaveImage("/Users/hoge2.jpg", image);
cvReleaseImage(image);
}
}
}
でもこんなエラーになるわけです。
java.lang.UnsatisfiedLinkError: no jniopencv_core in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:845) at java.lang.System.loadLibrary(System.java:1084) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535) at org.bytedeco.javacpp.Loader.load(Loader.java:410) at org.bytedeco.javacpp.Loader.load(Loader.java:353) at org.bytedeco.javacpp.opencv_core.(opencv_core.java:10) at java.lang.Class.forName0(Native Method) at java.lang.Class.forName(Class.java:264) at org.bytedeco.javacpp.Loader.load(Loader.java:385) at org.bytedeco.javacpp.Loader.load(Loader.java:353) at org.bytedeco.javacpp.opencv_highgui. (opencv_highgui.java:13) at jp.co.cyberagent.dokusho.service.HogeTest.test1(HogeTest.java:17) 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) at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47) at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12) at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44) at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17) at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70) at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50) at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238) at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63) at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236) at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53) at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229) at org.junit.runners.ParentRunner.run(ParentRunner.java:309) at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50) at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390) at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197) Caused by: java.lang.UnsatisfiedLinkError: no opencv_core in java.library.path at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1860) at java.lang.Runtime.loadLibrary0(Runtime.java:845) at java.lang.System.loadLibrary(System.java:1084) at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:535) at org.bytedeco.javacpp.Loader.load(Loader.java:401) ... 31 more
悲しい。 結論から言うと、コイツ、いろんなjarが足りないらしい。ひどい! で、それらの足りないものを補ってくれるものが公開されてます。
ずばりここに書いてあった。
Making Computer Vision actually work
http://marellbox.marell.se/?p=687
で、書いてある回避用リポジトリをpom.xmlに追加すると動いたー。
<dependency>
<groupid>org.bytedeco</groupid>
<artifactid>javacv</artifactid>
<version>0.10</version>
</dependency>
<dependency>
<groupid>se.marell</groupid>
<artifactid>opencv-macosx-x86_64</artifactid>
<version>2.4.10-0.10</version>
<scope>runtime</scope>
</dependency>
...
<repository>
<id>marell</id>
<url>http://marell.se/nexus/content/repositories/releases/</url>
</repository>
( ´ー`)フゥー...