在 hadoop 中加载的 OpenCV 库但不起作用 [英] OpenCV library loaded in hadoop but not working

查看:23
本文介绍了在 hadoop 中加载的 OpenCV 库但不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将 OpenCV 与 Hadoop 结合使用.下面是我的代码.我只是在测试 OpenCV 库是否与 Hadoop 一起工作正常,即当我在函数中运行 OpenCV 代码时Hadoop的public int run(String[] args).

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 public int run(String[] args) of Hadoop.

我在网上搜索,找到了一些如何在 Hadoop 中添加 OpenCV 原生库(libopencv_java310.so)的方法.我尝试了一些方法,但没有奏效.例如本教程.

I searched on the internet, and found some ways of how to add OpenCV native library (libopencv_java310.so) in Hadoop. I tried some ways, but it didn't work. For example this tutorial.

它说将 JAVA.LIBRARY.PATH 添加到 hadoop-config.sh 文件.但它没有用.我收到这个错误

It says add JAVA.LIBRARY.PATH to hadoop-config.sh file. But it didn't work. I got this error

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path
at line
System.loadLibrary(Core.NATIVE.LIBRARY.NAME);

最后,我将 OpenCV 本机库 (libopencv_java310.so) 添加到此路径(从 Internet 获得解决方案)

Finally, I added the OpenCV native library (libopencv_java310.so) to this path (got solution from internet)

$HADOOP_HOME/lib/native

它似乎奏效了.我没有收到上述错误.但我在下一行收到此错误:

And it seems to have worked. I didn't get the above error. But I got this error at next line:

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava/lang/String;)

此错误在行:

CascadeClassifier cad = new CascadeClassifier();

据我所知,如果未加载 OpenCV 本机库,我们会收到此错误.但是现在库加载好了,不知道是什么原因导致这个错误.

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.

 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;
}

推荐答案

我遇到了同样的问题.我使用了以下解决方法.

I was facing the same problem. I used the following workaround.

您可以从使用 JavaCV 工具开始,因为它与 hadoop 完美配合.然后使用 OpenCv,通过将所有 opencv 库和 jar 包装在可执行 jar 中来制作一个可执行 jar.现在本机库由操作系统加载.所以在可执行jar文件中,编写提取OpenCv原生库到temp文件中的代码,然后加载库,最后删除temp文件.

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆