带有opencv和hadoop的UnsatisfiedLinkError

时间:2018-09-26 15:58:44

标签: opencv hadoop

我正在Cloudera VM中的Eclipse中运行此代码。这是CannyEdgeDetector.java文件的代码。

package experiments;

import java.io.IOException;

import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;
import org.opencv.core.Mat;
import org.opencv.core.Size;
import org.opencv.imgproc.Imgproc;

import core.CombineMatImageInputFormat;
import core.MaprConfigurationParser;
import core.MatImageWritable;
import core.MatImageOutputFormat;
import core.OpenCVMapper;

public class CannyEdgeDetector {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        String input = args[0];
        String output = args[1];

        long startTime = System.currentTimeMillis();

        Job job = new MaprConfigurationParser().getOpenCVJobTemplate();
        job.setJarByClass(CannyEdgeDetector.class);
        job.setMapperClass(CannyMapper.class); 
        job.setInputFormatClass(CombineMatImageInputFormat.class;
        //job.setInputFormatClass(MatImageInputFormat.class);


        job.setOutputFormatClass(MatImageOutputFormat.class);
        Path outputPath = new Path(output);
        FileInputFormat.setInputPaths(job, input);
        FileOutputFormat.setOutputPath(job, outputPath);
        job.setOutputKeyClass(NullWritable.class);
        job.setOutputValueClass(MatImageWritable.class);
        job.waitForCompletion(true);

        long estimatedTime = System.currentTimeMillis() - startTime;

        System.out.println("Job has taken " + estimatedTime + " ms");
    }

    public static class CannyMapper extends OpenCVMapper<NullWritable, MatImageWritable, NullWritable, MatImageWritable> {
        @Override
        protected void map(NullWritable key, MatImageWritable value, Context context) throws IOException, InterruptedException {
            Mat image = value.getImage();
            Mat rimage = new Mat();

            Imgproc.blur(image, image, new Size(5,5));
            Imgproc.Canny(image, rimage, 1, 50);

            context.write(NullWritable.get(), new MatImageWritable(rimage, value.getFileName(), value.getFormat()));
        }
    }
}

这是OpenCVMapper.java文件的代码。

package core;

import org.apache.hadoop.filecache.DistributedCache;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.mapreduce.Mapper;

import java.io.IOException;

public class OpenCVMapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> extends Mapper<KEYIN, VALUEIN, KEYOUT, VALUEOUT> {
    @Override
    protected void setup(Context context) throws IOException, InterruptedException {
        Path[] myCacheFiles = DistributedCache.getLocalCacheFiles(context.getConfiguration());
        System.load(myCacheFiles[0].toUri().getPath());
    }
}

这是运行CannyEdgeDetector.java文件的输出。

18/08/24 09:22:45 WARN util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
18/08/24 09:22:46 INFO Configuration.deprecation: session.id is deprecated. Instead, use dfs.metrics.session-id
18/08/24 09:22:46 INFO jvm.JvmMetrics: Initializing JVM Metrics with processName=JobTracker, sessionId=
18/08/24 09:22:46 WARN mapred.JobClient: Use GenericOptionsParser for parsing the arguments. Applications should implement Tool for the same.
18/08/24 09:22:46 WARN mapred.JobClient: No job jar file set. User classes may not be found. See JobConf(Class) or JobConf#setJar(String).
18/08/24 09:22:46 INFO input.FileInputFormat: Total input paths to process : 1
18/08/24 09:22:47 INFO filecache.TrackerDistributedCacheManager: Creating fileopencv_java300.dll in /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042-work-6493143726339482696 with rwxr-xr-x
18/08/24 09:22:47 INFO filecache.TrackerDistributedCacheManager: Cached opencv_java300.dll as /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll
18/08/24 09:22:47 INFO filecache.TrackerDistributedCacheManager: Cached opencv_java300.dll as /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll
18/08/24 09:22:47 INFO mapred.JobClient: Running job: job_local490648103_0001
18/08/24 09:22:47 INFO mapred.LocalJobRunner: OutputCommitter set in config null
18/08/24 09:22:47 INFO mapred.LocalJobRunner: OutputCommitter is org.apache.hadoop.mapreduce.lib.output.FileOutputCommitter
18/08/24 09:22:47 INFO mapred.LocalJobRunner: Waiting for map tasks
18/08/24 09:22:47 INFO mapred.LocalJobRunner: Starting task: attempt_local490648103_0001_m_000000_0
18/08/24 09:22:47 WARN mapreduce.Counters: Group org.apache.hadoop.mapred.Task$Counter is deprecated. Use org.apache.hadoop.mapreduce.TaskCounter instead
18/08/24 09:22:47 INFO util.ProcessTree: setsid exited with exit code 0
18/08/24 09:22:47 INFO mapred.Task:  Using ResourceCalculatorPlugin : org.apache.hadoop.util.LinuxResourceCalculatorPlugin@2b1eb67d
18/08/24 09:22:47 INFO mapred.MapTask: Processing split: Paths:/home/cloudera/final_project/heart.jpg:0+4019
Java HotSpot(TM) 64-Bit Server VM warning: You have loaded library /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll which might have disabled stack guard. The VM will try to fix the stack guard now. It's highly recommended that you fix the library with 'execstack -c <libfile>', or link it with '-z noexecstack'.
18/08/24 09:22:47 INFO mapred.LocalJobRunner: Map task executor complete.
18/08/24 09:22:47 WARN mapred.LocalJobRunner: job_local490648103_0001
java.lang.Exception: java.lang.UnsatisfiedLinkError: /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll: /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll: invalid ELF header (Possible cause: endianness mismatch)
    at org.apache.hadoop.mapred.LocalJobRunner$Job.run(LocalJobRunner.java:406)
Caused by: java.lang.UnsatisfiedLinkError: /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll: /tmp/hadoop-cloudera/mapred/local/archive/-6191380913454212509_224460933_1774799042/fileopencv_java300.dll: invalid ELF header (Possible cause: endianness mismatch)
    at java.lang.ClassLoader$NativeLibrary.load(Native Method)
    at java.lang.ClassLoader.loadLibrary1(ClassLoader.java:1965)
    at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1890)
    at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1851)
    at java.lang.Runtime.load0(Runtime.java:795)
    at java.lang.System.load(System.java:1062)
    at core.OpenCVMapper.setup(OpenCVMapper.java:13)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:138)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:672)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:330)
    at org.apache.hadoop.mapred.LocalJobRunner$Job$MapTaskRunnable.run(LocalJobRunner.java:268)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    at java.util.concurrent.FutureTask.run(FutureTask.java:262)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:745)
18/08/24 09:22:48 INFO mapred.JobClient:  map 0% reduce 0%
18/08/24 09:22:48 INFO mapred.JobClient: Job complete: job_local490648103_0001
18/08/24 09:22:48 INFO mapred.JobClient: Counters: 0
Job has taken 3757 ms

有人可以帮我吗?我已经为此苦苦挣扎了一段时间。谢谢。

0 个答案:

没有答案