【问题标题】:OpenCV Java Harris Corner DetectionOpenCV Java Harris 角点检测
【发布时间】:2019-07-18 15:10:53
【问题描述】:

我正在开发一个 Android 应用程序,我想使用 Harris 角点检测。我想绘制检测到的角,但似乎找不到 Java 代码的文档。

到目前为止我的代码:

Mat inputImage = inputFrame.rgba();
Imgproc.cornerHarris(inputImage, inputImage, 7, 5, 0.05, Imgproc.BORDER_DEFAULT);

如何检测和显示角点?

【问题讨论】:

    标签: java android opencv


    【解决方案1】:

    对于 Java,您可以尝试这段代码。

    private void Harris(Mat Scene, Mat Object, int thresh) {
    
        // This function implements the Harris Corner detection. The corners at intensity > thresh
        // are drawn.
        Mat Harris_scene = new Mat();
        Mat Harris_object = new Mat();
    
        Mat harris_scene_norm = new Mat(), harris_object_norm = new Mat(), harris_scene_scaled = new Mat(), harris_object_scaled = new Mat();
        int blockSize = 9;
        int apertureSize = 5;
        double k = 0.1;
        Imgproc.cornerHarris(Scene, Harris_scene,blockSize, apertureSize,k);
        Imgproc.cornerHarris(Object, Harris_object, blockSize,apertureSize,k);
    
        Core.normalize(Harris_scene, harris_scene_norm, 0, 255, Core.NORM_MINMAX, CvType.CV_32FC1, new Mat());
        Core.normalize(Harris_object, harris_object_norm, 0, 255, Core.NORM_MINMAX, CvType.CV_32FC1, new Mat());
    
        Core.convertScaleAbs(harris_scene_norm, harris_scene_scaled);
        Core.convertScaleAbs(harris_object_norm, harris_object_scaled);
    
        for( int j = 0; j < harris_scene_norm.rows() ; j++){
            for( int i = 0; i < harris_scene_norm.cols(); i++){
                if ((int) harris_scene_norm.get(j,i)[0] > thresh){
                    Imgproc.circle(harris_scene_scaled, new Point(i,j), 5 , new Scalar(0), 2 ,8 , 0);
                }
            }
        }
    
        for( int j = 0; j < harris_object_norm.rows() ; j++){
            for( int i = 0; i < harris_object_norm.cols(); i++){
                if ((int) harris_object_norm.get(j,i)[0] > thresh){
                    Imgproc.circle(harris_object_scaled, new Point(i,j), 5 , new Scalar(0), 2 ,8 , 0);
                }
            }
        }
     }
    

    我刚刚写了以下代码here

    【讨论】:

    • 如果对您有帮助,请采纳!这对其他人也有帮助!
    • 我试过上面的代码将 Harris(mat, mat, 1) 作为参数传递给方法。当我检查图像时,它没有显示任何显示角落的圆圈
    • @SivaKReddyCShiva 你为什么通过 1?
    【解决方案2】:

    我知道这并不理想,但它也不是那么糟糕 - 你可以查看 c++ 文档和示例,Java 的翻译通常是直截了当的: 一个例子:Harris corner detector。 (你没有提到你的版本,这是从 v2.4 开始的)。

    【讨论】:

      【解决方案3】:
      猜你喜欢
      • 1970-01-01
      • 2011-04-21
      • 1970-01-01
      • 2013-08-17
      • 2018-10-22
      • 2012-10-24
      • 1970-01-01
      • 2023-03-18
      • 1970-01-01
      相关资源
      最近更新 更多