Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV library loaded in hadoop but not working

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;
}
like image 828
Gurinderbeer Singh Avatar asked Mar 28 '16 20:03

Gurinderbeer Singh


1 Answers

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.

like image 51
jsingh13 Avatar answered Oct 25 '22 23:10

jsingh13