在JavaCV中找不到“ cvLoad”所在的软件包?

时间:2019-03-26 10:55:48

标签: javacv javacpp

我尝试了一个用于面部检测的示例代码,但是即使导入了cvLoad也没有找到方法org.bytedeco.javacpp.opencv_objdetect.*

import org.bytedeco.javacpp.FlyCapture2.Image;
import org.bytedeco.javacpp.opencv_core.CvMemStorage;
import org.bytedeco.javacpp.opencv_core.CvSeq;
import static org.bytedeco.javacpp.opencv_core.cvClearMemStorage;
import org.bytedeco.javacpp.opencv_objdetect.CvHaarClassifierCascade;
import static org.bytedeco.javacpp.opencv_objdetect.*;


/**
 *
 * @author LEVALLOIS
 */
public class FaceDetect {

    // Create memory for calculations
    CvMemStorage storage = null;

    // Create a new Haar classifier
    CvHaarClassifierCascade classifier = null;

    // List of classifiers
    String[] classifierName = {
        "./classifiers/haarcascade_frontalface_alt.xml",
        "./classifiers/haarcascade_frontalface_alt2.xml",
        "./classifiers/haarcascade_profileface.xml"};

    public FaceDetect() {
        // Allocate the memory storage
        storage = CvMemStorage.create();

        // Load the HaarClassifierCascade
        classifier = new CvHaarClassifierCascade(cvLoad(classifierName[0]));

        // Make sure the cascade is loaded
        if (classifier.isNull()) {
            System.err.println("Error loading classifier file");
        }
    }

    public boolean find(Image value) {
        // Clear the memory storage which was used before
        cvClearMemStorage(storage);

        if (!classifier.isNull()) {
            // Detect the objects and store them in the sequence
            CvSeq faces = cvHaarDetectObjects(value, classifier,
                    storage, 1.1, 3, CV_HAAR_DO_CANNY_PRUNING);

            // Get the number of faces found.
            int total = faces.total();
            if (total > 0) {
                return true;
            }
        }
        return false;
    }
}

Maven依赖项:

<dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>javacpp</artifactId>
    <version>1.4.4</version>
</dependency>
<dependency>
    <groupId>org.bytedeco</groupId>
    <artifactId>javacv-platform</artifactId>
    <version>1.4.4</version>
</dependency>

Error: FaceDetect.java:[39,50] cannot find symbol
  symbol:   method cvLoad(java.lang.String)

帮助?

1 个答案:

答案 0 :(得分:0)

有时可以手动编写导入语句,而不是依赖于快捷键Ctrl + shft + o

因此请手动添加以下导入语句

 import static org.bytedeco.javacpp.opencv_imgcodecs.cvLoadImage;