OpenCV.箱式滤波

箱式滤波
箱式滤波实现的效果与均值模糊类似,作用是将每个像素替换成其相邻矩形内像素的平均值,是低通滤波器 。在中该类的实现依赖于() 函数 。下面是该函数的声明:
(src, dst, , ksize, , , );

OpenCV.箱式滤波

文章插图
【OpenCV.箱式滤波】各参数解释
Java代码( 层)
public class Controller{@FXML private Text fxText;@FXML private ImageView imageView;@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() {@Overridepublic void run() {try {WritableImage writableImage = boxFilter(filePath);Platform.runLater(new Runnable() {@Overridepublic void run() {imageView.setImage(writableImage);}});} catch (IOException e) {e.printStackTrace();}}}).start();}private WritableImage boxFilter(String filePath) throws IOException {System.loadLibrary(Core.NATIVE_LIBRARY_NAME);Mat src = http://www.kingceram.com/post/Imgcodecs.imread(filePath);Mat dst = new Mat();Imgproc.boxFilter(src, dst, 50, new Size(15,15), new Point(-1,-1), true, Core.BORDER_DEFAULT);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;}}
运行图: