最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

OpenCV實(shí)現(xiàn)普通閾值

 更新時(shí)間:2021年11月17日 11:10:12   作者:kicinio  
這篇文章主要為大家詳細(xì)介紹了OpenCV實(shí)現(xiàn)普通閾值,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

普通閾值

閾值本質(zhì)上就是對(duì)圖像進(jìn)行分割的一個(gè)過(guò)程。利用閾值二值化可對(duì)灰度或彩色圖像進(jìn)行像素?cái)?shù)據(jù)分類。普通閾值即閾值二值化就是針對(duì)給定的圖像,以T作為閾值進(jìn)行分割的過(guò)程。在OpenCV中該類的實(shí)現(xiàn)依賴于threshold() 函數(shù)。下面是該函數(shù)的聲明:

threshold(src, dst, thresh, maxval, type);

各參數(shù)解釋

·src
表示此操作的源(輸入圖像)的Mat對(duì)象。

·mat
表示目標(biāo)(輸出)圖像的類Mat的對(duì)象。

·thresh
表示閾值T。

·maxval
表示最大灰度值,一般為255。

·type
表示要使用的閾值類型的整數(shù)類型變量,閾值二值化為Imgproc.THRESH_BINARY。

其數(shù)學(xué)描述解釋如下:

對(duì)于給定的src(x,y),若其像素值大于閾值T(thresh),則其返回像素最大值,否則為0。

那么dst其像素描述如下:

Java代碼(JavaFX Controller層)

public class Controller{

    @FXML private Text fxText;
    @FXML private ImageView imageView;
    @FXML private Label resultLabel;

    @FXML public void handleButtonEvent(ActionEvent actionEvent) throws IOException {

        Node source = (Node) actionEvent.getSource();
        Window theStage = source.getScene().getWindow();
        FileChooser fileChooser = new FileChooser();
        FileChooser.ExtensionFilter extFilter = new FileChooser.ExtensionFilter("PNG files (*.png)", "*.png");
        fileChooser.getExtensionFilters().add(extFilter);
        fileChooser.getExtensionFilters().add(new FileChooser.ExtensionFilter("JPG Files(*.jpg)", "*.jpg"));
        File file = fileChooser.showOpenDialog(theStage);

        runInSubThread(file.getPath());

    }

    private void runInSubThread(String filePath){
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    WritableImage writableImage = thresholdOfBinary(filePath);

                    Platform.runLater(new Runnable() {
                        @Override
                        public void run() {
                            imageView.setImage(writableImage);
                        }
                    });

                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }).start();
    }
    
    private WritableImage thresholdOfBinary(String filePath) throws IOException {
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

        Mat src = Imgcodecs.imread(filePath);
        Mat dst = new Mat();

        Imgproc.threshold(src, dst, 150, 255, Imgproc.THRESH_BINARY);

        MatOfByte matOfByte = new MatOfByte();
        Imgcodecs.imencode(".jpg", dst, matOfByte);

        byte[] bytes = matOfByte.toArray();
        InputStream in = new ByteArrayInputStream(bytes);
        BufferedImage bufImage = ImageIO.read(in);

        WritableImage writableImage = SwingFXUtils.toFXImage(bufImage, null);

        return writableImage;
    }

}

運(yùn)行圖

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

您可能感興趣的文章:

相關(guān)文章

最新評(píng)論

香河县| 南通市| 嘉兴市| 海丰县| 正镶白旗| 清苑县| 汉阴县| 浙江省| 高台县| 安福县| 东兰县| 广宗县| 柳江县| 中卫市| 安达市| 陇川县| 油尖旺区| 资溪县| 光泽县| 威远县| 越西县| 安塞县| 闵行区| 开化县| 柳江县| 佳木斯市| 衡阳县| 武义县| 法库县| 清徐县| 睢宁县| 庆城县| 莱西市| 上高县| 环江| 江都市| 宁安市| 鄂托克前旗| 平泉县| 乌恰县| 沙洋县|