Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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;
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
249 views
Welcome To Ask or Share your Answers For Others

1 Answer

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...