欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Java?OpenCV圖像處理之自定義圖像濾波算子

 更新時(shí)間:2022年02月19日 09:13:08   作者:深色風(fēng)信子  
這篇文章主要為大家介紹了如何利用Java?OpenCV實(shí)現(xiàn)自定義圖像濾波(降噪)?算子,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編學(xué)習(xí)一下

示例代碼

package com.xu.image;

import java.io.File;

import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;

/**
 * @Title: Image.java
 * @Description: OpenCV 測試文件
 * @Package com.xu.test
 * @author: hyacinth
 * @date: 2019年5月7日12:13:13
 * @version: V-1.0.0
 * @Copyright: 2019 hyacinth
 */
public class Image {

    static {
        String os = System.getProperty("os.name");
        String type = System.getProperty("sun.arch.data.model");
        if (os.toUpperCase().contains("WINDOWS")) {
            File lib;
            if (type.endsWith("64")) {
                lib = new File("D:\\Learn\\OpenCV\\OpenCV-4.5.5\\build\\java\\x64\\" + System.mapLibraryName("opencv_java455"));
            } else {
                lib = new File("D:\\Learn\\OpenCV\\OpenCV-4.5.5\\build\\java\\x86\\" + System.mapLibraryName("opencv_java455"));
            }
            System.load(lib.getAbsolutePath());
        }
    }

    public static void main(String[] args) {
        kernel3();
    }

    /**
     * OpenCV-4.0.0 自定義濾波(降噪)(Robert算子)
     *
     * @return: void
     * @date: 2019年5月7日12:16:55
     */
    public static void kernel1() {
        Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\1.jpg");
        HighGui.imshow("Robert算子 原圖", src.clone());
        Mat dst_x = new Mat();
        Mat dst_y = new Mat();

        //Robert算子-X軸
        Mat kernel_x = new Mat(2, 2, 1);
        kernel_x.put(0, 0, 1);
        kernel_x.put(0, 1, 0);
        kernel_x.put(1, 0, 0);
        kernel_x.put(1, 1, -1);
        Imgproc.filter2D(src, dst_x, -1, kernel_x, new Point(-1, -1), 0.0);

        //Robert算子-Y軸
        Mat kernel_y = new Mat(2, 2, 1);
        kernel_y.put(0, 0, 0);
        kernel_y.put(0, 1, 1);
        kernel_y.put(1, 0, -1);
        kernel_y.put(1, 1, 0);
        Imgproc.filter2D(src, dst_y, -1, kernel_y, new Point(-1, -1), 0.0);

        HighGui.imshow("Robert算子 Y", dst_y);
        HighGui.imshow("Robert算子 X", dst_x);
        Mat dst = new Mat();
        Core.addWeighted(dst_x, 0.5, dst_y, 0.5, 0, dst);
        HighGui.imshow("Robert算子 融合", dst);
        HighGui.waitKey(10);
    }

    /**
     * OpenCV-4.0.0 自定義濾波(降噪)(Sable算子)
     *
     * @return: void
     * @date: 2019年5月7日12:16:55
     */
    public static void kernel2() {
        Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\1.jpg");
        HighGui.imshow("Sable算子 原圖", src.clone());
        Mat dst_x = new Mat();
        Mat dst_y = new Mat();

        //Soble算子-X軸
        Mat kernel_x = new Mat(3, 3, 1);
        kernel_x.put(0, 0, -1);
        kernel_x.put(0, 1, 0);
        kernel_x.put(0, 2, 1);
        kernel_x.put(1, 0, -2);
        kernel_x.put(1, 1, 0);
        kernel_x.put(1, 2, 2);
        kernel_x.put(2, 0, -1);
        kernel_x.put(2, 1, 0);
        kernel_x.put(2, 2, 1);
        Imgproc.filter2D(src, dst_x, -1, kernel_x, new Point(-1, -1), 0.0);

        //Soble算子-Y軸
        Mat kernel_y = new Mat(3, 3, 1);
        kernel_y.put(0, 0, -1);
        kernel_y.put(0, 1, 2);
        kernel_y.put(0, 2, -1);
        kernel_y.put(1, 0, 0);
        kernel_y.put(1, 1, 0);
        kernel_y.put(1, 2, 0);
        kernel_y.put(2, 0, 1);
        kernel_y.put(2, 1, 2);
        kernel_y.put(2, 2, 1);
        Imgproc.filter2D(src, dst_y, -1, kernel_y, new Point(-1, -1), 0.0);

        HighGui.imshow("Sable算子 X", dst_x);
        HighGui.imshow("Sable算子 Y", dst_y);
        Mat dst = new Mat();
        Core.addWeighted(dst_x, 0.5, dst_y, 0.5, 0, dst);
        HighGui.imshow("Sable算子 融合", dst);
        HighGui.waitKey(1);
    }

    /**
     * OpenCV-4.0.0 自定義濾波(降噪)(Laplace算子)
     *
     * @return: void
     * @date: 2019年5月7日12:16:55
     */
    public static void kernel3() {
        Mat src = Imgcodecs.imread("D:\\OneDrive\\桌面\\1.jpg");
        HighGui.imshow("Laplace 算子 原圖", src.clone());
        Mat dst = new Mat();

        //拉普拉斯算子
        Mat kernel = new Mat(3, 3, 1);
        kernel.put(0, 0, 0);
        kernel.put(0, 1, -1);
        kernel.put(0, 2, 0);
        kernel.put(1, 0, -1);
        kernel.put(1, 1, 4);
        kernel.put(1, 2, -1);
        kernel.put(2, 0, 0);
        kernel.put(2, 1, -1);
        kernel.put(2, 2, 0);
        Imgproc.filter2D(src, dst, -1, kernel, new Point(-1, -1), 0.0);

        HighGui.imshow("Laplace 算子", dst);
        HighGui.waitKey(0);
    }

}

效果圖

以上就是Java OpenCV圖像處理之自定義圖像濾波算子的詳細(xì)內(nèi)容,更多關(guān)于Java OpenCV圖像濾波算子的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • java實(shí)現(xiàn)dijkstra最短路徑尋路算法

    java實(shí)現(xiàn)dijkstra最短路徑尋路算法

    這篇文章主要為大家詳細(xì)介紹了java實(shí)現(xiàn)dijkstra最短路徑尋路算法,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2019-01-01
  • Spring 整合Shiro 并擴(kuò)展使用EL表達(dá)式的實(shí)例詳解

    Spring 整合Shiro 并擴(kuò)展使用EL表達(dá)式的實(shí)例詳解

    Shiro是一個(gè)輕量級(jí)的權(quán)限控制框架,應(yīng)用非常廣泛。本文的重點(diǎn)是介紹Spring整合Shiro,并通過擴(kuò)展使用Spring的EL表達(dá)式。需要的朋友可以參考下
    2018-03-03
  • c語言來實(shí)現(xiàn)貪心算法之裝箱問題

    c語言來實(shí)現(xiàn)貪心算法之裝箱問題

    這篇文章主要介紹了c語言來實(shí)現(xiàn)貪心算法之裝箱問題,需要的朋友可以參考下
    2015-03-03
  • Spring Bean實(shí)例化實(shí)現(xiàn)過程解析

    Spring Bean實(shí)例化實(shí)現(xiàn)過程解析

    這篇文章主要介紹了Spring Bean實(shí)例化實(shí)現(xiàn)過程解析,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2020-02-02
  • Java語言的11大特點(diǎn)(Java初學(xué)者必知)

    Java語言的11大特點(diǎn)(Java初學(xué)者必知)

    Java是一種簡單的,面向?qū)ο蟮?,分布式的,解釋型的,健壯安全的,結(jié)構(gòu)中立的,可移植的,性能優(yōu)異、多線程的靜態(tài)語言。這篇文章主要介紹了Java語言的11大特點(diǎn),需要的朋友可以參考下
    2020-07-07
  • Spring AOP使用接口方式實(shí)現(xiàn)

    Spring AOP使用接口方式實(shí)現(xiàn)

    本文主要介紹了Spring AOP使用接口方式實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • SpringBoot Maven打包插件spring-boot-maven-plugin無法解析原因

    SpringBoot Maven打包插件spring-boot-maven-plugin無法解析原因

    spring-boot-maven-plugin是spring boot提供的maven打包插件,本文主要介紹了SpringBoot Maven打包插件spring-boot-maven-plugin無法解析原因,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-03-03
  • java實(shí)現(xiàn)刪除某條信息并刷新當(dāng)前頁操作

    java實(shí)現(xiàn)刪除某條信息并刷新當(dāng)前頁操作

    這篇文章主要介紹了java實(shí)現(xiàn)刪除某條信息并刷新當(dāng)前頁操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過來看看吧
    2020-11-11
  • @RequestBody的使用詳解

    @RequestBody的使用詳解

    這篇文章主要介紹了@RequestBody的使用詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • SpringBoot部署到Linux讀取resources下的文件及遇到的坑

    SpringBoot部署到Linux讀取resources下的文件及遇到的坑

    本文主要給大家介紹SpringBoot部署到Linux讀取resources下的文件,在平時(shí)業(yè)務(wù)開發(fā)過程中,很多朋友在獲取到文件內(nèi)容亂碼或者文件讀取不到的問題,今天給大家分享小編遇到的坑及處理方案,感興趣的朋友跟隨小編一起看看吧
    2021-06-06

最新評(píng)論