OpenCV library loaded in hadoop but not working
Asked Answered
J

1

6

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.

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.

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

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

This error is at line:

CascadeClassifier cad = new CascadeClassifier();

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;
}
Jovanjove answered 28/3, 2016 at 20:13 Comment(3)
Do not load libraries in a method, but rather in a static initializer. UnsatisfiedLinkErrors are also thrown if a library is attempted to be loaded more than once.Cavazos
Why not use HIPI?Florida
There are some specific methods, which are there only in OpenCv. Using HIPI is different thing. Thanks for your reply..Jovanjove
C
1

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.

Colville answered 11/4, 2016 at 22:49 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.