Found 2617 Articles for Java

How to draw a circle in OpenCV using Java?

Maruthi Krishna
Updated on 09-Apr-2020 08:32:06

254 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc.To draw a circle you need to invoke the circle() method of this class. This method accepts the following parameters −A Mat object representing the image on which the circle is to be drawn.A Point object representing the center of the circle.An integer variable representing the radius of the circle.A Scalar object representing the color of the circle(BGR).An integer representing the thickness of the circle(default 1).Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingCircle {    public static void main(String args[]) ... Read More

How to draw a rectangle in OpenCV using Java?

Maruthi Krishna
Updated on 09-Apr-2020 08:29:39

957 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw a rectangle you need to invoke the rectangle() method of this class. This method accepts the following parameters −A Mat object representing the image on which the rectangle is to be drawn.Two Point objects representing the vertices of the rectangle that is to be drawn.A Scalar object representing the color of the rectangle(BGR).An integer representing the thickness of the rectangle(default:1).Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingRectangle {    public static void main(String args[]) {     ... Read More

How to draw an ellipse in OpenCV using Java?

Maruthi Krishna
Updated on 09-Apr-2020 08:27:05

260 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw an ellipse you need to invoke the ellipse() method of this class. This method accepts the following parameters −A Mat object representing the image on which the ellipse is to be drawn.A RotatedRect object (The ellipse is drawn inscribed in this rectangle.)A Scalar object representing the color of the Rectangle(BGR).An integer representing the thickness of the Rectangle(default:1).Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.RotatedRect; import org.opencv.core.Scalar; import org.opencv.core.Size; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingEllipse {    public static void main(String args[]) {   ... Read More

How to draw a line in OpenCV using Java?

Maruthi Krishna
Updated on 09-Apr-2020 08:24:57

608 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw a line you need to invoke the line() method of this class. This method accepts the following parameters −A Mat object representing the image on which the line is to be drawn.Two Point objects representing the points between which the line is to be drawn.A Scalar object representing the color of the line. (BGR)An integer representing the thickness of the line(default:1).Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class DrawingLine {    Mat matrix = null;    public static ... Read More

How to convert colored image to HLS using Java OpenCV library?

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

162 Views

You can convert HLS image to RGB (colored) image by passing Imgproc.COLOR_RGB2HLS as the 3rd parameter to the cvtColor() method.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class HSL2RGB {    public static void main(String args[]) throws Exception {       System.loadLibrary( Core.NATIVE_LIBRARY_NAME );       Mat src = Imgcodecs.imread("D:\images\car3.jpg");       Mat dst = new Mat();       Imgproc.cvtColor(src, dst, Imgproc.COLOR_RGB2HLS);       Imgcodecs imageCodecs = new Imgcodecs();       imageCodecs.imwrite("D:\images\hslImage.jpg", dst);       System.out.println("Image Saved");    } }InputOutput

How to convert HLS to colored image using Java OpenCV library?

Maruthi Krishna
Updated on 09-Apr-2020 08:20:02

166 Views

The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −src − A Matrix object representing source.dst − A Matrix object representing the destination.code − An integer value representing the color of the destination image.You can convert a colored image to an HLS image by passing Imgproc.COLOR_RGB2HLS as a parameter to the above method.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class RGB2HSL {    public static void main(String args[]) throws Exception {       //Loading the OpenCV core library       System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); ... Read More

How to convert HSV to BGR image using Java OpenCV library?

Maruthi Krishna
Updated on 09-Apr-2020 08:17:14

347 Views

The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −src − A Matrix object representing source.dst − A Matrix object representing the destination.code − An integer value representing the color of the destination image.To convert an HSV image to BGR you need to pass Imgproc.COLOR_HSV2BGR as the 3rd parameter to the cvtColor() method.Examplepublic class HSV2RGB {    public static void main(String args[]) throws Exception {       System.loadLibrary( Core.NATIVE_LIBRARY_NAME );       Mat src = Imgcodecs.imread("D:\images\hsvimage2.jpg");       Mat dst = new Mat();     ... Read More

How to convert HSV to colored image using Java OpenCV library?

Maruthi Krishna
Updated on 09-Apr-2020 08:14:57

253 Views

The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −src − A Matrix object representing source.dst − A Matrix object representing the destination.code − An integer value representing the color of the destination image.To convert an HSV image to RGB you need to pass Imgproc.COLOR_HSV2RGB as the third parameter to this method.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class HSV2RGB {    public static void main(String args[]) throws Exception {       //Loading the OpenCV core library       System.loadLibrary( Core.NATIVE_LIBRARY_NAME );     ... Read More

How to convert RGB image to HSV using Java OpenCV library?

Maruthi Krishna
Updated on 09-Apr-2020 08:12:00

714 Views

The cvtColor() method of the Imgproc class changes/converts the color of the image from one to another. This method accepts three parameters −src − A Matrix object representing source.dst − A Matrix object representing the destination.code − An integer value representing the color of the destination image.To convert an RGB image to HSV you need to pass Imgproc.COLOR_RGB2HSV as the third parameter to this method.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class RGB2HSV {    public static void main(String args[]) throws Exception {       //Loading the OpenCV core library       System.loadLibrary( Core.NATIVE_LIBRARY_NAME );   ... Read More

OpenCV JavaFX application to alter the sharpness of an image

Maruthi Krishna
Updated on 09-Apr-2020 08:09:44

177 Views

Sharpening an image is the opposite of blur. To alter the sharpness of an image using the OpenCV library, you need to smooth/blur it using the Gaussian filter and subtract the smoothed version from the original image.ExampleFollowing is a JavaFX program with two sliders representing the alpha and beta values.import java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import javafx.application.Application; import javafx.beans.value.ChangeListener; import javafx.beans.value.ObservableValue; import javafx.embed.swing.SwingFXUtils; import javafx.geometry.Insets; import javafx.scene.Scene; import javafx.scene.control.Label; import javafx.scene.control.Slider; import javafx.scene.image.ImageView; import javafx.scene.image.WritableImage; import javafx.scene.layout.VBox; import javafx.stage.Stage; import javax.imageio.ImageIO; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfByte; import org.opencv.core.Size; import org.opencv.imgcodecs.Imgcodecs; import org.opencv.imgproc.Imgproc; public class SharpnessJavaFX extends Application ... Read More

Advertisements