java - 如何在小图像上使用 Opencv FeatureDetecter

标签 java opencv knn

我在 Java 中使用 Opencv 3,我试图在其他图像上找到小图像(如 25x25 像素)。但是 FeatureDetector 在小图像上检测 (0,0) 大小的 Mat。

    Mat smallImage = ...

    FeatureDetector detector = FeatureDetector.create(FeatureDetector.ORB);
    DescriptorExtractor descriptor = DescriptorExtractor.create(DescriptorExtractor.ORB);
    DescriptorMatcher matcher = DescriptorMatcher.create(DescriptorMatcher.BRUTEFORCE_HAMMING);

    Mat descriptorsSmall = new Mat();
    MatOfKeyPoint keyPointsSmall = new MatOfKeyPoint();

    detector.detect(smallImage, keyPointsSmall);
    descriptor.compute(smallImage, keyPointsSmall, descriptorsSmall);

在这里,我将 keyPointsSmall 和 descriptorsSmall 大小设置为零,并且确定检测不起作用。

但如果我在 150x150 像素等较大的图像上尝试此操作,效果很好。 有什么建议么?谢谢。

我在这里添加示例。 我们有这个源图像: This is source image

假设我们有 P 字母的模板,所以我们需要在源图像上检测这个 P。 This is template

好吧,将图像缩放到更高分辨率对我来说不起作用。这将浪费时间和资源。 理想情况下,它应该是旋转尺度不变的。但是没有旋转和缩放的简单解决方案也可以。

除 OpenCv 之外的其他解决方案对我来说是 Not Acceptable 。 (例如使用 Tesseract)

最佳答案

用于文本识别的关键点检测不是最佳解决方案,因为您会得到许多看起来相似的特征,如果模板非常小,滑动窗口将无法产生足够的检测特征。

幸运的是,OpenCV 3 在 contrib 存储库中包含一个文本检测/识别模块:link,其中一个示例取自 here 和许多其他查找 here 的示例:

/*
 * cropped_word_recognition.cpp
 *
 * A demo program of text recognition in a given cropped word.
 * Shows the use of the OCRBeamSearchDecoder class API using the provided default classifier.
 *
 * Created on: Jul 9, 2015
 *     Author: Lluis Gomez i Bigorda <lgomez AT cvc.uab.es>
 */

#include "opencv2/text.hpp"
#include "opencv2/core/utility.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"

#include <iostream>

using namespace std;
using namespace cv;
using namespace cv::text;

int main(int argc, char* argv[])
{

    cout << endl << argv[0] << endl << endl;
    cout << "A demo program of Scene Text Character Recognition: " << endl;
    cout << "Shows the use of the OCRBeamSearchDecoder::ClassifierCallback class using the Single Layer CNN character classifier described in:" << endl;
    cout << "Coates, Adam, et al. \"Text detection and character recognition in scene images with unsupervised feature learning.\" ICDAR 2011." << endl << endl;

    Mat image;
    if(argc>1)
        image  = imread(argv[1]);
    else
    {
        cout << "    Usage: " << argv[0] << " <input_image>" << endl;
        cout << "           the input image must contain a single character (e.g. scenetext_char01.jpg)." << endl << endl;
        return(0);
    }

    string vocabulary = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"; // must have the same order as the clasifier output classes

    Ptr<OCRHMMDecoder::ClassifierCallback> ocr = loadOCRHMMClassifierCNN("OCRBeamSearch_CNN_model_data.xml.gz");

    double t_r = (double)getTickCount();
    vector<int> out_classes;
    vector<double> out_confidences;

    ocr->eval(image, out_classes, out_confidences);

    cout << "OCR output = \"" << vocabulary[out_classes[0]] << "\" with confidence "
         << out_confidences[0] << ". Evaluated in "
         << ((double)getTickCount() - t_r)*1000/getTickFrequency() << " ms." << endl << endl;

    return 0;
}

关于java - 如何在小图像上使用 Opencv FeatureDetecter,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37583375/

相关文章:

java - 在 Java 桌面聊天应用程序中混合使用 Swing 和 JavaFX

python - 使用 Knn 分类器时出现无效形状错误

r - knnImpute 使用带插入符号包的分类变量

java - 如何在没有循环的情况下从ArrayList中获取对象?

java - JPA 不删除数据库行

java - 理解Java中的类变量

opencv - 获取二值图像中对象的位置和大小

c++ - OpenCV 2.3 : Convert Mat to RGBA pixel array

opencv - opencv人脸识别,获得相似度的度量

matlab - 如何定义KNN的权重?