在hadoop中加载OpenCV库但不工作 [英] OpenCV library loaded in hadoop but not working
问题描述
我正在尝试在Hadoop中使用OpenCV。以下是我的代码。我只是测试OpenCV库是否可以正常运行Hadoop,即当我在Hadoop的函数
public int run(String [] args)
中运行OpenCV代码时。
我在互联网上搜索,找到了一些如何添加OpenCV本地库的方法( libopencv_java310.so
)在Hadoop中。我尝试了一些方法,但没有奏效。例如本教程。
它说添加 JAVA.LIBRARY.PATH
到 hadoop-config.sh
文件。
但它不起作用。我得到这个错误
线程main中的异常java.lang.UnsatisfiedLinkError:java.library.path中的no opencv_java310
在行
System.loadLibrary(Core.NATIVE.LIBRARY.NAME);
最后,我添加了OpenCV本地库( 它似乎起作用了。我没有得到上述错误。 这个错误是在线: 据我所知,如果OpenCV本机库没有加载,我们会得到这个错误。但现在图书馆已经加载,我不知道这个错误的原因是什么。 我面临同样的问题。我使用了以下解决方法。 您可以使用JavaCV工具开始,因为它可以与hadoop完美协作。 I am trying to use OpenCV with Hadoop. Below is my code. I am just testing if OpenCV libraries works fine with Hadoop, i.e when I am running OpenCV code in function
I searched on the internet, and found some ways of how to add OpenCV native library ( It says add Finally, I added the OpenCV native library ( And it seems to have worked. I didn't get the above error.
But I got this error at next line: This error is at line: As far as I know, we get this error if OpenCV native library is not loaded. But now the library is loaded, I don't know what is the reason for this error.
I was facing the same problem. I used the following workaround. You can start by using JavaCV tool as it works perfectly with hadoop.
Then with OpenCv,make an executable jar by wrapping all opencv libraries and jars within executable jar. Now native library is loaded by operating system. So within executable jar file, write the code which extracts the OpenCv native library to temper pry file, then it loads the library, and finally delete the temp file. 这篇关于在hadoop中加载OpenCV库但不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! libopencv_java310.so $
$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $' code>
但是我在下一行发现了这个错误:
线程main中的异常java.lang.UnsatisfiedLinkError:org .opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava / lang / String;)
CascadeClassifier cad = new CascadeClassifier();
public int run(String [] args)throws Exception {
Configuration conf =新的配置();
Job job = Job.getInstance(conf);
job.setJarByClass(readVideoFile.class);
job.setJobName(smallfilestoseqfile);
job.setInputFormatClass(readVideoInputFormat.class);
job.setNumReduceTasks(1);
FileInputFormat.setInputPaths(job,new Path(args [0]));
FileOutputFormat.setOutputPath(job,new Path(args [1]));
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapperClass(readVideoMapper.class);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier cad = new CascadeClassifier();
返回job.waitForCompletion(true)? 0:1;
}
然后在OpenCv中,通过在可执行jar中包装所有opencv库和jar来制作一个可执行的jar文件。现在,本机库被操作系统加载。因此,在可执行jar文件中,编写提取OpenCv本机库的代码来调试pry文件,然后加载库,最后删除临时文件。public int run(String[] args)
of Hadoop.libopencv_java310.so
) in Hadoop. I tried some ways, but it didn't work. For example this tutorial.JAVA.LIBRARY.PATH
to hadoop-config.sh
file.
But it didn't work. I got this errorException in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
at line
System.loadLibrary(Core.NATIVE.LIBRARY.NAME);
libopencv_java310.so
) to this path (got solution from internet)$HADOOP_HOME/lib/native
Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava/lang/String;)
CascadeClassifier cad = new CascadeClassifier();
public int run(String[] args) throws Exception {
Configuration conf = new Configuration();
Job job = Job.getInstance(conf);
job.setJarByClass(readVideoFile.class);
job.setJobName("smallfilestoseqfile");
job.setInputFormatClass(readVideoInputFormat.class);
job.setNumReduceTasks(1);
FileInputFormat.setInputPaths(job, new Path(args[0]));
FileOutputFormat.setOutputPath(job, new Path(args[1]));
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(Text.class);
job.setMapperClass(readVideoMapper.class);
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
CascadeClassifier cad = new CascadeClassifier();
return job.waitForCompletion(true) ? 0 : 1;
}