【问题标题】:NATIVE_LIBRARY_NAME cannot be resolved or is not a fieldNATIVE_LIBRARY_NAME 无法解析或不是字段
【发布时间】:2018-07-29 19:52:50
【问题描述】:

我正在通过 eclipse 4.5.0 在 java 中使用 open Graphics Library 创建一个人脸检测程序,并将一个 jar 文件添加到 open CV 2.4.1 的 java 项目中,并且我已经尝试了 web 上指定的所有方法用于通过 Eclipse IDE 中可用的构建路径选项设置 NATIVE_LIBRARY_NAME 的位置,但仍然找不到解决方案...请帮我解决此错误

我的人脸检测 Java 文件

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.MatOfRect;
import org.opencv.core.Point;
import org.opencv.core.Rect;
import org.opencv.core.Scalar;
import org.opencv.highgui.Highgui;
import org.opencv.objdetect.CascadeClassifier;

public class FaceDetection 
{
    public static void main(String[] args)
    {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        System.out.println("\nRunning FaceDetector");

        CascadeClassifier faceDetector = new CascadeClassifier(FaceDetection.class.getResource("haarcascade_frontalface_alt.xml").getPath());
        Mat image = Highgui
                .imread(FaceDetection.class.getResource("shekhar.JPG").getPath());

        MatOfRect faceDetections = new MatOfRect();
        faceDetector.detectMultiScale(image, faceDetections);

        System.out.println(String.format("Detected %s faces", faceDetections.toArray().length));

        for (Rect rect : faceDetections.toArray()) 
        {
            Core.rectangle(image, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height),
                    new Scalar(0, 255, 0));
        }

        String filename = "ouput.png";
        System.out.println(String.format("Writing %s", filename));
        Highgui.imwrite(filename, image);
    }
}

我已点击此链接 https://blog.openshift.com/day-12-opencv-face-detection-for-java-developers/

【问题讨论】:

标签: java eclipse opencv opengl


【解决方案1】:

由于您提供了 OpenCV 的 jar 文件,但未配置 Native 库位置。

您需要先在您的机器上安装 OpenCV,并使用安装 OpenCV 后创建的文件夹(或使用您下载的 jar 文件)在构建路径中提供 jar 文件的路径,并且本地库位置的位置应该是“opencv-2.4.7/build/lib 文件夹”。

OpenCV 下载链接 - https://opencv.org/releases.html

请参考此链接配置eclipse - http://docs.opencv.org/2.4/doc/tutorials/introduction/java_eclipse/java_eclipse.html

【讨论】:

  • 你试过答案了吗?
猜你喜欢
  • 2014-10-12
  • 2022-01-09
  • 2014-03-27
  • 2014-01-05
  • 2016-05-20
  • 2016-02-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多