描述符提取器导致错误

时间:2015-03-29 13:33:14

标签: java opencv javacv

我写了下面的代码来做匹配Mat对象列表的功能,问题是在运行时我收到下面发布的错误,据我所知,我检查了扩展和使用过的图像的大小 它们是.jpg和538 * 522,除了一张图像是538 * 520

是不同大小的图像可能会导致这样的错误? 请帮我解决这个问题。

代码

  public static void main(String[] args) {
    loadOpenCVLib();
                                    /*Step_1: Feature Detection*/
    initFeatureDetector();
                                    /*Step_2: Descriptor Extractor*/
    initDescriptorExtractor();
}

private static void initDescriptorExtractor() {
    // TODO Auto-generated method stub
    descriptorsList = new ArrayList<Mat>();

    descriptorsList.add(new Mat());
    descriptorsList.add(new Mat());
    descriptorsList.add(new Mat());

    DescriptorExtractor descripExtractor = 
    DescriptorExtractor.create(DescriptorExtractor.SIFT);
    descripExtractor.compute(matList, keyPointsList, descriptorsList);
    //descripExtractor.write(fileName) test this method
    //descripExtractor.read(fileName)
}

private static void initFeatureDetector() {
    // TODO Auto-generated method stub
    matList = new ArrayList<Mat>();
    keyPointsList = new ArrayList<MatOfKeyPoint>();

    matList.add(path2Mat(path_jf00));
    matList.add(path2Mat(path_jf01));
    matList.add(path2Mat(path_jf02));

    keyPointsList.add(newMatKeyPoints());
    keyPointsList.add(newMatKeyPoints());
    keyPointsList.add(newMatKeyPoints());

    FeatureDetector featsDetect =    
    FeatureDetector.create(FeatureDetector.SURF);
    featsDetect.detect(matList, keyPointsList);
}

private static void loadOpenCVLib() {
    // TODO Auto-generated method stub
    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}

private static Mat path2Mat(String path2File) {
    // TODO Auto-generated method stub
    return Highgui.imread(path2File);
}

private static MatOfKeyPoint newMatKeyPoints() {
    return new MatOfKeyPoint();
}

}

错误

OpenCV Error: Assertion failed (imageCollection.size() ==  
pointCollection.size()) in cv::DescriptorExtractor::compute, file 
 ..\..\..\..\opencv\modules\features2d\src\descriptors.cpp, line 74

Exception in thread "main" CvException [org.opencv.core.CvException: 
cv::Exception: ..\..\..\..\opencv\modules\features2d
\src\descriptors.cpp:74: error: (-215) imageCollection.size() == 
pointCollection.size() in function cv::DescriptorExtractor::compute
]
 at org.opencv.features2d.DescriptorExtractor.compute_1(Native Method)
at 
 org.opencv.features2d.DescriptorExtractor.compute(DescriptorExtractor.java:140)
at test.FeatsMatch.initDescriptorExtractor(FeatsMatch.java:40)
at test.FeatsMatch.main(FeatsMatch.java:28)

0 个答案:

没有答案