Articles on Trending Technologies

Technical articles with clear explanations and examples

How can I remove all empty values when I explode a string using PHP?

AmitDiwan
AmitDiwan
Updated on 09-Apr-2020 1K+ Views

The array_filter() or PREG_SPLIT_NO_EMPTY option on preg_split() can be used to remove empty values from a string when it is exploded −Example Live Demo

Read More

PHP: fopen to create folders

AmitDiwan
AmitDiwan
Updated on 09-Apr-2020 2K+ Views

The fopen can’t be used to create directories. This is because fopen function doesn't create or open folders, it only works with files.Before using the fopen function, one should check with is_dir first if it exists, if not create it using the mkdir function −$filename = '/path/to /file.txt'; $dirname = dirname($filename); if (!is_dir($dirname)) {    mkdir($dirname, 0755, true); }The above code creates a path to the file named ‘filename’. The directory of the ‘filename’ is obtained using the ‘dirname’ function. Next, this directory is checked for the existence using the ‘is_dir’ function. If the directory already exists, no operation takes ...

Read More

How to import csv file in PHP?

AmitDiwan
AmitDiwan
Updated on 09-Apr-2020 1K+ Views

The below code can be used to import CSV file in PHP −The file will display the contents of the csv file are displayed on the screen.In the above code, beginning from row 1 (since row 0 would usually contain headers/column names), the csv file is opened in read mode and the fgetcsv function is called to read in 1000 rows of data present in the csv file.The number of columns in every row is displayed along with the contents of it.

Read More

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

raja
raja
Updated on 09-Apr-2020 413 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

Explain the Mat class in Java OpenCV library

Maruthi Krishna
Maruthi Krishna
Updated on 09-Apr-2020 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
Maruthi Krishna
Updated on 09-Apr-2020 471 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
Maruthi Krishna
Updated on 09-Apr-2020 325 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 add noise to an image using Java OpenCV library?

Maruthi Krishna
Maruthi Krishna
Updated on 09-Apr-2020 761 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

How to draw an ellipse in OpenCV using Java?

Maruthi Krishna
Maruthi Krishna
Updated on 09-Apr-2020 403 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 convert colored image to HLS using Java OpenCV library?

Maruthi Krishna
Maruthi Krishna
Updated on 09-Apr-2020 260 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

Read More
Showing 48101–48110 of 61,248 articles
Advertisements