Java-OpenCV Sobel

    /**
     * Get the Sobel Mat of input image!
     * @param image The input image.
     * @return The Sobel Mat image of input image.
     */
    public Mat getSobelMat(Mat image) {
        if (image.empty()) {
            System.out.println("Please check the input image!");
            return image;
        }

        Mat gray = image.clone();
        if (3 == gray.channels()) {
            Imgproc.cvtColor(gray, gray, Imgproc.COLOR_BGR2GRAY);
        }

        Mat grad = new Mat();
        Mat grad_x = new Mat();
        Mat grad_y = new Mat();
        Mat abs_grad_x = new Mat();
        Mat abs_grad_y = new Mat();
        final int scharr_scale = 1;
        final int scharr_delta = 0;
        final int scharr_ddpeth = CvType.CV_16S;
        //Imgproc.Scharr(grayImg, grad_x, scharr_ddpeth, 1, 0, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
        //Imgproc.Scharr(grayImg, grad_y, scharr_ddpeth, 0, 1, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
        Imgproc.Sobel(gray, grad_x, scharr_ddpeth, 1, 0, 3, scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
        Imgproc.Sobel(gray, grad_y, scharr_ddpeth, 0, 1, 3,scharr_scale, scharr_delta, Core.BORDER_DEFAULT);
        Core.convertScaleAbs(grad_x, abs_grad_x);
        Core.convertScaleAbs(grad_y, abs_grad_y);
        Core.addWeighted(abs_grad_x, 0.5, abs_grad_y, 0.5, 0, grad);
        return grad;
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Digital2Slave

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值