OpenCV,拉普拉斯变异(Java) [英] OpenCV, Variation of the Laplacian (Java)

查看:754
本文介绍了OpenCV,拉普拉斯变异(Java)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图根据图像找到拉普拉斯算子的变体,目的是根据图像的模糊度得到一个数值。

I am attempting to locate the Variation for the Laplacian based on an image with the goal of getting a numerical value based on the blurriness of an image.

这是一个有用的帖子
http://www.pyimagesearch .com / 2015/09/07 / blur-detection-with-opencv /

cv2.Laplacian(image, cv2.CV_64F).var()

我一直试图实现同样的运气。我的起点是一个表示图像的字节[](img):

I've been trying to implement the same without luck. My starting point is a byte[] representing the image (img):

Mat mat = new Mat(img.getImageHeight(), img.getImageWidth(), CvType.CV_8UC3);
Imgproc.cvtColor(mat, mat, Imgproc.COLOR_BGR2GRAY);
mat.put(0, 0, putData.getFileContents());
Imgproc.Laplacian(mat,mat, CvType.CV_64F);

任何帮助都将不胜感激。

Any help would be appreciated.

基本上,我从图像开始,想要使用拉普拉斯算法得到一个代表图像模糊度的值。

Essentially, I'm starting with an image and want to get a value representing the blurriness of an image using Laplacian.

推荐答案

拉普拉斯变换可以用应用filter2D方法的内核代替。
我在这样的java程序中运行了同样的python示例:

The Laplacian transformation can be replaced by a kernel applied with the filter2D method. I have been running that same python example in a java program like this:

    Mat destination = new Mat();
    Mat matGray=new Mat();  
    Mat kernel = new Mat(3,3, CvType.CV_32F){
       {
          put(0,0,0);
          put(0,1,-1);
          put(0,2,0);

          put(1,0-1);
          put(1,1,4);
          put(1,2,-1);

          put(2,0,0);
          put(2,1,-1);
          put(2,2,0);
       }
    };        
    Imgproc.cvtColor(image, matGray, Imgproc.COLOR_BGR2GRAY);          
    Imgproc.filter2D(matGray, destination, -1, kernel); 
    MatOfDouble median = new MatOfDouble();
    MatOfDouble std= new MatOfDouble();        
    Core.meanStdDev(destination, median , std);

    Math.pow(std.get(0,0)[0],2);

希望这有助于您的编码。

Hope this helps your coding.

注意:我从Python和Java程序获得的值是不同的,我仍然没有找出原因。无论如何,java代码运行良好。

Note: The values I get from the Python and Java program are different and I still didn't figure out why. Anyway the java code runs well.

找出值不一样的原因。使用Imgproc.Laplacian方法而不是Imgproc.filter2D在python和java中生成完全相同的值。

Found out why the values were not the same. Using the Imgproc.Laplacian method instead of Imgproc.filter2D produces exactly the same values in python and java.

新代码变为:

Mat destination = new Mat();
Mat matGray=new Mat();  

Imgproc.cvtColor(image, matGray, Imgproc.COLOR_BGR2GRAY);          
Imgproc.Laplacian(matGray, destination, 3); 
MatOfDouble median = new MatOfDouble();
MatOfDouble std= new MatOfDouble();        
Core.meanStdDev(destination, median , std);

Math.pow(std.get(0,0)[0],2);

比python更简单,结果相同。

Much simpler and with same results as python.

这篇关于OpenCV,拉普拉斯变异(Java)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆