Maruthi Krishna has Published 951 Articles

How to create a watermark on an image using Java OpenCV library?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Apr-2020 07:19:52

347 Views

Following Java example draws a watermark (“Hello”) on the given image and saves it back.Exampleimport java.awt.Color; import java.awt.Font; import java.awt.Graphics; import java.awt.image.BufferedImage; import java.io.File; import java.io.IOException; import javax.imageio.ImageIO; public class WaterMarkExample {    public static void main(String[] args) throws IOException {       //Reading the contents of an image ... Read More

How to create a mirror image using Java OpenCV library?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Apr-2020 07:17:16

539 Views

To create a mirror imageRead the required image using ImageIO.read() method.Get the height and width of the image.Create an empty buffered image to store the resultUsing nested for loops traverse through each pixel in the image.Iterate the width of the image from right to left.Get the pixel value using the ... Read More

Converting image to Grayscale without using any methods Java OpenCV.

Maruthi Krishna

Maruthi Krishna

Updated on 09-Apr-2020 07:14:40

367 Views

To convert the colored image to grayscale.Get the red green blue values of each pixelGet the average of these 3 colors.Replace the RGB values with the average.Create a new pixel value from the modified colors.Set the new value to the pixel.Exampleimport java.io.File; import java.io.IOException; import java.awt.Color; import java.awt.image.BufferedImage; import javax.imageio.ImageIO; ... Read More

How to convert a colored image to Sepia image using Java OpenCV library?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Apr-2020 07:11:01

611 Views

Algorithm to convert a colored image to sepia −Get the red green blue values of each pixelGet the average of these 3 colors.Define the depth and intensity values (ideally 20, and 30).Modify the values as −red = red + (depth*2).Green = green +depth.blue = blue-intensity.Make sure that the modified values ... Read More

How to convert a negative image to positive image using Java OpenCV library?

Maruthi Krishna

Maruthi Krishna

Updated on 09-Apr-2020 07:07:30

415 Views

To convert a negative image to positive −Read the required image using ImageIO.read() method.Get the height and width of the image.Using nested for loops traverse through each pixel in the image.Get the pixel value using the getRGB() method.To retrieve each value from a pixel you need to right shift to ... Read More

How to Set/modify the pixels(RGB values) of an image using Java OpenCV Library?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Apr-2020 14:14:13

3K+ Views

A pixel is the smallest element of a digital image, each pixel contains the values of alpha, red, green, blue values. The pixel value(s) is stored in a 32-bit memory space holding ARGB values (8 bits each) in the same order. Therefore, to modify the color of an image −You ... Read More

How to perform Bitwise OR operation on two images using Java OpenCV?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Apr-2020 14:12:14

254 Views

You can compute bitwise or between two images using the bitwise_or() method of the org.opencv.core.Core class.This method accepts three Mat objects representing the source, destination and result matrices, calculates the bitwise disjunction of each element in the source matrices and stores the result in the destination matrix.ExampleIn the following Java example, ... Read More

How to list all the Collections in a MongoDB database using Java?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Apr-2020 14:11:06

2K+ Views

You can print a list of all the existing collections in a database using show collections.ExampleAssume we have created 3 collections in a MongoDB database as shown below −> use sampleDatabase switched to db sampleDatabase > db.createCollection("students") { "ok" : 1 } > db.createCollection("teachers") { "ok" : 1 } > ... Read More

Reference to a constructor using method references in Java8

Maruthi Krishna

Maruthi Krishna

Updated on 08-Apr-2020 14:09:28

604 Views

Lambda expressions In Java allows you to pass functionality as an argument to a method. You can also call an existing method using lambda expressions.list.forEach(n -> System.out.println(n));Method references are simple, easy-to-read lambda expressions to call/refer and the existing method by name in a lambda expression. In addition to the instance ... Read More

How to convert a colored image to blue/green/red image using Java OpenCV library?

Maruthi Krishna

Maruthi Krishna

Updated on 08-Apr-2020 14:06:04

314 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 a colored ... Read More

Advertisements