opencv error“错误:org.opencv.objdetect.cascadeclassifier.cascadeclassifier\u 1(ljava/lang/string;)“j”

xpcnnkqh  于 2021-06-01  发布在  Hadoop
关注(0)|答案(1)|浏览(572)

我用的是 opencv-249.jar 但是当我运行我的程序 hadoop 它显示了一个错误。我还使用 System.loadlibrary(Core.NATIVE_LIBRARY_NAME) 但还是会出错

Error: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava/lang/String;)J

Map器类如下

public static class DumpHibMapper
    extends Mapper<ImageHeader, FloatImage, IntWritable, Text> {

    private static Configuration conf;

    public DumpHibMapper() {}

    public void setup(Mapper<ImageHeader, FloatImage, IntWritable, Text>.Context paramMapper)
      throws IOException {
       conf = paramMapper.getConfiguration();
       System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    }

    public void map(ImageHeader paramImageHeader, FloatImage paramFloatImage, Mapper<ImageHeader, FloatImage, IntWritable, Text>.Context paramMapper)
      throws IOException, InterruptedException {
      if (paramFloatImage != null) {
        String str1 = conf.get("local.file.path");
        CascadeClassifier localCascadeClassifier = new CascadeClassifier(str1 + "haarcascade_frontalface_default.xml");
        String str2 = UUID.randomUUID().toString();
        File localFile = new File(str1.toString() + "imwf/" + str2 + ".jpg");
        FileOutputStream localFileOutputStream = new FileOutputStream(localFile);
        JPEGImageUtil.getInstance().encodeImage(paramFloatImage, paramImageHeader, localFileOutputStream);
        Mat localMat = Highgui.imread(localFile.getAbsolutePath());
        MatOfRect localMatOfRect = new MatOfRect();
        localCascadeClassifier.detectMultiScale(localMat, localMatOfRect);
        int i = localMatOfRect.toArray().length;
        if (i == 0) {
          localFile.renameTo(new File(str1.toString() + "imwof/" + localFile.getName()));
        }
        int j = paramFloatImage.getWidth();
        int k = paramFloatImage.getHeight();
        String str3 = ByteUtils.asHex(ByteUtils.FloatArraytoByteArray(paramFloatImage.getData()));
        String str4;
        if (i > 0) {
          str4 = j + "x" + k + "\t(" + str3 + ")\t\t" + str2 + ".jpg";
          paramMapper.write(new IntWritable(1), new Text(str4));
        } else {
          str4 = j + "x" + k + "\t(" + str3 + ")\t\t" + "No face detected found " + str2 + ".jpg";
          paramMapper.write(new IntWritable(1), new Text(str4));
        }
      }
    }
  }
iqih9akk

iqih9akk1#

添加 System.loadLibrary(Core.NATIVE_LIBRARY_NAME); 主要方法

相关问题