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