OpenCV特征检测始终不返回任何内容

时间:2013-12-04 05:48:30

标签: java opencv feature-detection

背景

我正在创建一个OpenCV Java命令行应用程序,用于从某些粒子条纹图像中删除一些信息。特别是,我想知道最小可能的边界框的尺寸,它将适合每个粒子条纹。首先我必须找到粒子,所以我使用Simple Blob特征检测。

代码:

package com.bostonwalker;

import org.opencv.core.Mat;
import org.opencv.core.MatOfKeyPoint;
import org.opencv.features2d.FeatureDetector;
import org.opencv.features2d.KeyPoint;
import org.opencv.highgui.Highgui;
import org.opencv.imgproc.Imgproc;

import java.util.List;

public class Main {

    public static void main(String[] args)
    {
        System.loadLibrary("opencv_java247");

        String sourcePath = "C:\\path_to_image\\05.png";

        Mat srcImgMat = Highgui.imread(sourcePath);

        if (srcImgMat == null)
        {
            System.out.println("Failed to load image at " + sourcePath);
            return;
        }

        System.out.println("Loaded image at " + sourcePath);

        MatOfKeyPoint matOfKeyPoints = new MatOfKeyPoint();

        FeatureDetector blobDetector = FeatureDetector.create(FeatureDetector.SIMPLEBLOB);
        blobDetector.detect(srcImgMat, matOfKeyPoints);

        System.out.println("Detected " + matOfKeyPoints.size()+ " blobs in the image");

        List<KeyPoint> keyPoints = matOfKeyPoints.toList();

    }
}

错误:

不幸的是,返回的matOfKeyPoints始终为空(大小始终等于1x0)。我已经搜索过网络,但桌面Java的opencv并不是一个非常受欢迎的库,我的问题似乎并不常见。我尝试使用其他功能检测器算法,看看我是否可以返回任何关键点(答案是否定的)。

我的直觉告诉我,Simple Blob算法不支持图像的颜色通道方案。我已经从Photoshop导出.png文件为8位/通道灰度和8位/通道RGB颜色。很难知道Highgui.imread()调用中实际发生了什么,以及Mat数据实际上是什么样的。

问题:

  1. 是什么导致调用检测以返回空的matOfKeyPoints?

  2. 有没有更简单的方法来完成我想要的图像处理?

  3. 更多信息:

    OpenCV版本2.4.7

    下面的图片 enter image description here

    解决:

    发现问题。即,源路径中的小错字。当使用不正确的源路径时,看起来Highgui.imread()会返回一个空的Mat,而不是像我想象的那样返回null。

0 个答案:

没有答案
相关问题