Found 2616 Articles for Java

When to use the ServiceLoader class in a module in Java 9?

raja
Updated on 09-Apr-2020 12:22:21

203 Views

Java has a ServiceLoader class from java.util package that can help to locate service providers at the runtime by searching in the classpath. For service providers defined in modules, we can look at the sample application to declare modules with service and how it works.For instance, we have a "test.app" module that we need to use Logger that can be retrieved from System.getLogger() factory method with the help of LoggerFinder service.module com.tutorialspoint.test.app {    requires java.logging;    exports com.tutorialspoint.platformlogging.app;    uses java.lang.System.LoggerFinder; }Below is the test.app.MainApp class:package com.tutorialspoint.platformlogging.app; public class MainApp {    private static Logger LOGGER = System.getLogger();    public static void ... Read More

How to declare OpenCV Mat object using Java?

Maruthi Krishna
Updated on 09-Apr-2020 09:24:23

550 Views

In OpenCV Mat class represents a matrix object which is used to store images. You can also declare a Mat object manually −Load the OpenCV native library − While writing Java code using OpenCV library, the first step you need to do is to load the native library of OpenCV using the loadLibrary().Instantiate the Mat class − Instantiate the Mat class using any of the functions mentioned in this chapter earlier.Fill the matrix using the methods − You can retrieve particular rows/columns of a matrix by passing index values to the methods row()/col().you can set values to these using any of ... Read More

Explain the Mat class in Java OpenCV library

Maruthi Krishna
Updated on 09-Apr-2020 09:22:09

2K+ Views

In OpenCV, images are stored in Using Mat object. It is nothing but an n-dimensional array and is used to store image data of grayscale or color images, voxel volumes, vector fields, point clouds, tensors, histograms, etc.If you try to read an image using the OpenCV library it will be read to a Mat object.Mat matrix = Imgcodecs.imread(filePath);You can instantiate this class manually using one of the following constructors −Mat() − A no-arg constructor, used to create an empty matrix and pass this to other OpenCV methods.Mat(int rows, int cols, int type) − This constructor accepts three parameters of integer ... Read More

How to create custom color maps in Java using OpenCV?

Maruthi Krishna
Updated on 09-Apr-2020 09:20:38

312 Views

The applyColorMap() method of the Imgproc class applies specified color map to the given image. This method accepts three parameters −Two Mat objects representing the source and destination images.An integer variable representing the type of the color map to be applied.You can pass any of the following as color map value to this method.COLORMAP_AUTUMN, COLORMAP_BONE, COLORMAP_COOL, COLORMAP_HOT, COLORMAP_HSV, COLORMAP_JET, COLORMAP_OCEAN , COLORMAP_PARULA, COLORMAP_PINK, COLORMAP_RAINBOW, COLORMAP_SPRING, COLORMAP_SUMMER, COLORMAP_WINTER.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class CustomColorMaps {    public static void main(String args[]) {       // Loading the OpenCV core library       System.loadLibrary(Core.NATIVE_LIBRARY_NAME);     ... Read More

How to alter the brightness of a grey scale image?

Maruthi Krishna
Updated on 09-Apr-2020 09:18:12

178 Views

The equalizeHist() method of the Imgproc class accepts a greyscale image and equalizes its histogram, which will, in turn, normalizes the brightness and increases the contrast of the given image. This method accepts two parameters −A Mat object representing the source image (greyscale).A Mat object to save the result.ExampleFollowing Java program reads a colored image as greyscale, saves it, normalizes the brightness and increases the contrast of the given image and saves it.import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class HstExample {    public static void main(String args[]) {       //Loading the OpenCV core ... Read More

How to create a JavaFX slider?

Maruthi Krishna
Updated on 16-Apr-2020 08:30:35

332 Views

JavaFX provides a class known as Slider, this represents a slider component that displays a continuous range of values. This contains a track on which the numerical values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum and initial values of the slider. To create a slider you need to instantiate the Slider class, set the required properties and, add it to the scene.Exampleimport javafx.application.Application; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Slider; import javafx.scene.layout.VBox; import javafx.stage.Stage;         public class SliderExample extends Application {    public void start(Stage stage) ... Read More

How to create JavaFX slider with two thumbs?

Maruthi Krishna
Updated on 16-Apr-2020 06:44:39

813 Views

In general, a slider is a component that displays a continuous range of values. This contains a track on which the numerical values are displayed. Along the track, there is a thumb pointing to the numbers. You can provide the maximum, minimum and initial values of the slider.The slider JavaFX provides contains only one thumb if you want to create a slider with two thumbs you need to rely on an external library named org.controlsfx.control.Following is the maven dependency for this library −    org.controlsfx    controlsfx    11.0.1 The RangeSlider class of this package is the JavaFXSlider but with ... Read More

How to add noise to an image using Java OpenCV library?

Maruthi Krishna
Updated on 09-Apr-2020 09:07:46

529 Views

To add noise to a given image using OpenCV −Read the contents of the given image to a Mat object.Create two more empty matrices to store the noise and the resultant matrices.Create two MatOfDouble matrices to store mean and standard deviation.Get the mean and standard deviation values using the meanStdDev() method.Create a matrix with random elements (to store the noise) using the randn() method.To this method pass the above-created source, mean and standard deviation objects.Finally, add the noise matrix and source matrix and save as destination.Exampleimport java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import javafx.application.Application; import javafx.embed.swing.SwingFXUtils; import javafx.scene.Group; import javafx.scene.Scene; import ... Read More

OpenCV Java example to scale an image.

Maruthi Krishna
Updated on 09-Apr-2020 09:04:53

507 Views

The resize() method of the Imgproc class resizes the specified image. This method accepts −Two Mat objects representing the source and destination images.A Size object representing the size of the output image.A double variable representing the scale factor along the horizontal axis.A double variable representing the scale factor along the vertical axis.An integer variable representing the interpolation method to be used in the operation.Exampleimport java.awt.Image; import java.awt.image.BufferedImage; import java.io.IOException; import javafx.application.Application; import javafx.embed.swing.SwingFXUtils; import javafx.scene.Group; import javafx.scene.Scene; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; import javafx.stage.Stage; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Size; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class ScalingAnImage extends Application { ... Read More

How to display different list commands in JShell in Java 9?

raja
Updated on 09-Apr-2020 09:28:48

290 Views

JShell has introduced in Java 9 and is a command-line tool that allows us to enter simple statements, expressions, methods, and classes without a main () method.When we can enter code in JShell, the code has assigned a unique ID. This ID starts at 1 and has incremented for each command entered in JShell. The same can be true for libraries loaded at startup. For each of these imports, a unique ID has been assigned. It starts with $1 and is incremented for each code loaded ($2, $3 and etc). There is an internal command to list all code loaded, and ... Read More

Advertisements