Perform Bitwise XOR Operation on Two Images Using Java OpenCV

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

523 Views

You can compute bitwise exclusive or between two images using the bitwise_xor() method of the org.opencv.core.Core class.This method accepts three Mat objects representing the source, destination, and result matrices, calculates the bitwise exclusive or of each element in the source matrices and stores the result in the destination matrix.ExampleIn the following Java example, we are converting an image into binary and gray scale and calculating the bitwise exclusive or of the results.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 BitwiseXORExample {    public static void main(String args[]) throws Exception {       //Loading the OpenCV core ... Read More

Implement Bilateral Blur in OpenCV Using Java

Maruthi Krishna
Updated on 09-Apr-2020 08:42:11

396 Views

You can blur an image by filtering it using a low-pass filter, this removes high frequency content (noise, edges) from an image. Bilateral Filtering is one of the blurring techniques provided by OpenCV, it −removes noise efficientlykeeps the edges sharpComparatively slowYou can apply the bilateral filter on an image using the bilateralFilter() method, this method acceptsTwo Mat objects representing the source and destination images.An integer representing the diameter of the pixel neighborhood.Two integer variables of the type integer representing the filter sigma in the color space and coordinate space.An Integer object representing the type of the border used.Exampleimport java.awt.Image; import ... Read More

Implement Gaussian Blur in OpenCV using Java

Maruthi Krishna
Updated on 09-Apr-2020 08:38:49

1K+ Views

You can blur an image by filtering it using a low-pass filter, this removes high frequency content (noise, edges) from an image.Gaussian Blurring is one of the blurring techniques provided by OpenCV, it is highly efficient in removing the noise of an image. This replaces the central element with the average of all the pixels in the kernel area.You can filter/blur an image by this technique using the GaussianBlur() method, this method accepts −Two Mat objects representing the source and destination images.A Size object representing the size of the kernel.A variable of the type double representing the Gaussian kernel standard ... Read More

Implement Blur Averaging in OpenCV Using Java

Maruthi Krishna
Updated on 09-Apr-2020 08:35:45

318 Views

You can blur an image by filtering it using a low-pass filter, this removes high frequency content (noise, edges) from an image.Averaging is one of the blurring techniques provided by OpenCV, this replaces the central element with the average of all the pixels in the kernel areaYou can filter/blur an image by this technique using the blur() or, boxFilter() methods, the blur() method accepts −Two Mat objects representing the source and destination images.A Size object representing the size of the kernel.An integer variable representing the anchor point.An integer variable of representing the type of the border to be used to ... Read More

Draw a Circle in OpenCV Using Java

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

393 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

Draw a Rectangle in OpenCV using Java

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

1K+ 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

Draw an Ellipse in OpenCV Using Java

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

390 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

Draw a Line in OpenCV using Java

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

881 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

Convert Colored Image to HLS Using Java OpenCV Library

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

244 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

Convert HLS to Colored Image Using Java OpenCV Library

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

276 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

Advertisements