Java opencv霍夫变换找出图中圆

本文介绍了一种使用Java结合OpenCV库进行图像处理的方法,具体为通过霍夫变换来检测图像中的圆环。文章提供了完整的代码示例,包括如何加载OpenCV的dll文件、设置maven依赖以及进行圆环检测的具体步骤。
摘要由CSDN通过智能技术生成
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;


//霍夫变换找图中的圆环
public class imageCriDis {
    public static void main(String[] args)
    {
        String relativelyPath = System.getProperty("user.dir");
        System.load(relativelyPath + "\\opencv_java340-x64.dll");
        //System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat src = Imgcodecs.imread("E:\\a.png");

        Mat dst = src.clone();
        Imgproc.cvtColor(src, dst, Imgproc.COLOR_BGR2GRAY);

        Mat circles = new Mat();
        Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 10, 440, 50, 0, 345);
        // Imgproc.HoughCircles(dst, circles, Imgproc.HOUGH_GRADIENT, 1, 100,440, 50, 0, 1000000);
        for (int i = 0; i < circles.cols(); i++)
        {
            double[] vCircle = circles.get(0, i);

            Point center = new Point(vCircle[0], vCircle[1]);
            int radius = (int) Math.round(vCircle[2]);

            // circle center
            Imgproc.circle(src, center, 3, new Scalar(0, 255, 0), -1, 8, 0);
            // circle outline
            Imgproc.circle(src, center, radius, new Scalar(0, 0, 255), 3, 8, 0);
        }

        Imgcodecs.imwrite("E:\\b.jpg", src);
    }
}

 

Java处理opencv 需要调用dll 

下载连接://download.csdn.net/download/weixin_40652498/11997095

maven依赖:

<dependencies>
        <!-- https://mvnrepository.com/artifact/org.bytedeco/javacv-platform -->
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv-platform</artifactId>
            <version>1.4.1</version>
        </dependency>
        <!-- https://mvnrepository.com/artifact/org.bytedeco.javacpp-presets/opencv-platform -->
        <dependency>
            <groupId>org.bytedeco.javacpp-presets</groupId>
            <artifactId>opencv-platform</artifactId>
            <version>3.4.1-1.4.1</version>
        </dependency>


        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.bytedeco</groupId>
            <artifactId>javacv</artifactId>
            <version>1.4.1</version>
        </dependency>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>compile</scope>
        </dependency>

    </dependencies>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值