Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to customize the Image filter operator in Java OpenCV

2025-02-14 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

Today, I would like to share with you how to customize the image filter operator in Java OpenCV, the content is detailed, the logic is clear, I believe most people still know too much about this knowledge, so share this article for your reference, I hope you can get something after reading this article, let's take a look at it.

Sample code 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 Test File * @ Package com.xu.test * @ author: hyacinth * @ date: 12:13:13 * @ version: Vmur1.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 Custom filter (noise reduction) (Robert operator) * * @ return: void * @ date: 12:16:55 * / public static void kernel1 () {Mat src = Imgcodecs.imread ("D:\\ OneDrive\\ Desktop\\ 1.jpg"); HighGui.imshow ("original Robert operator", src.clone ()) Mat dst_x = new Mat (); Mat dst_y = new Mat (); / / Robert operator-X axis 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 operator-Y axis 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 operator Y", dst_y); HighGui.imshow ("Robert operator X", dst_x); Mat dst = new Mat () Core.addWeighted (dst_x, 0.5, dst_y, 0.5,0, dst); HighGui.imshow ("Robert operator Fusion", dst); HighGui.waitKey (10) } / * OpenCV-4.0.0 Custom filter (noise reduction) (Sable operator) * * @ return: void * @ date: 12:16:55 * / public static void kernel2 () {Mat src = Imgcodecs.imread ("D:\\ OneDrive\\ Desktop\\ 1.jpg"); HighGui.imshow ("original Sable operator", src.clone ()) Mat dst_x = new Mat (); Mat dst_y = new Mat (); / / Soble operator-X axis 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 operator-Y axis 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 operator X", dst_x) HighGui.imshow ("Sable operator Y", dst_y); Mat dst = new Mat (); Core.addWeighted (dst_x, 0.5, dst_y, 0.5,0, dst); HighGui.imshow ("Sable operator Fusion", dst); HighGui.waitKey (1) } / * OpenCV-4.0.0 Custom filter (noise reduction) (Laplace operator) * * @ return: void * @ date: 12:16:55 * / public static void kernel3 () {Mat src = Imgcodecs.imread ("D:\\ OneDrive\\ Desktop\\ 1.jpg"); HighGui.imshow ("original Laplace operator", src.clone ()) Mat dst = new Mat (); / / Laplace operator Mat kernel = new Mat (3,3,1); kernel.put (0,0,0); kernel.put (0,1,0); 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 operator", dst); HighGui.waitKey (0) }} effect picture

These are all the contents of the article "how to customize the Image filter operator in Java OpenCV". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report