Draw a Filled Circle in OpenCV Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:48:35

741 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. This class provides a method named circle(), using this you can draw a circle on an image. This method provides 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).If you pass Imgproc.FILLEDas line type, this method generates/draws a filled circle.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Scalar; import ... Read More

Convert OpenCV Mat Object to JavaFX WritableImage

Maruthi Krishna
Updated on 10-Apr-2020 07:46:37

519 Views

If you try to read an image using the OpenCV imread() method it returns a Mat object. If you want to display the contents of the resultant Mat object using a JavaFX window You need to convert the Mat object to an object of the class javafx.scene.image.WritableImage. To do so, you need to follow the steps given below −Encode the Mat to MatOfByte − First of all, you need to convert the matrix to the matrix of a byte. You can do it using the method imencode() of the class Imgcodecs.This method accepts a String parameter(specifying the image format), a ... Read More

Create a Database in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:32:09

2K+ Views

There is no separate method to create a MongoDB database in Java, you can create a database by invoking the getDatabase() method of the com.mongodb.MongoClient class.Exampleimport com.mongodb.MongoClient; public class CreatingDatabase {    public static void main( String args[] ) {       //Creating a MongoDB client       @SuppressWarnings("resource")       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Accessing the database       mongo.getDatabase("myDatabase1");       mongo.getDatabase("myDatabase2");       mongo.getDatabase("myDatabase3");       System.out.println("Databases created successfully");    } }OutputDatabases created successfully

Create an Index in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:30:52

2K+ Views

In MongoDB to create an index, you need to use createIndex() method.Syntaxdb.COLLECTION_NAME.createIndex({KEY:1})Where the key is the name of the file on which you want to create index and 1 is for ascending order. To create an index in descending order you need to use -1.In Java, you can create an Index using the createIndex() method, to this method you need to pass the type of the index (ascending or descending) and the field name on which you want to create the index, as −createIndex(Indexes.descinding("name"));Exampleimport com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Indexes; import org.bson.Document; import com.mongodb.MongoClient; public class CreatingIndex {    public static void ... Read More

Drop an Index in MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:24:24

656 Views

In MongoDB to drop an index, you need to use dropIndex() method.Syntaxdb.COLLECTION_NAME.dropIndex({KEY:1})In Java, you can drop an Index using the dropIndex() method, to this method you need to pass the type of the index (ascending or descending) and the field name on which you have created it.dropIndex(Indexes.ascending("name"));Exampleimport com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Indexes; import org.bson.Document; import com.mongodb.MongoClient; public class DroppingIndex {    public static void main( String args[] ) {       //Creating a MongoDB client       MongoClient mongo = new MongoClient( "localhost" , 27017 );       //Accessing the database       MongoDatabase database = ... Read More

Java MongoDB Projections Explained

Maruthi Krishna
Updated on 10-Apr-2020 07:16:54

1K+ Views

While retrieving data from MongoDb collections you can select only necessary data using projections. In Java, you can project necessary data while reading the documents from a collection using the projection() method. Invoke this method on the result of find(), bypassing the names of the required filed names as −projection(Projections.include("name", "age"));ExampleFollowing Java examples read the documents from a collection, using projection we are displaying the values of name and age fields only.import com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import com.mongodb.client.model.Projections; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class ProjectionExample {    public static void main( String args[] ... Read More

Skip Documents While Retrieving Data from MongoDB Using Java

Maruthi Krishna
Updated on 10-Apr-2020 07:14:51

334 Views

While retrieving records from a MongoDB collection, you can skip records in the result using the skip() method.Syntaxdb.COLLECTION_NAME.find().limit(NUMBER).skip(NUMBER)The Java MongoDB library provides a method with the same name, to skip records, invoke this method (on the result of the find() method) bypassing an integer value representing the number of records to skip.Exampleimport com.mongodb.client.FindIterable; import com.mongodb.client.MongoCollection; import com.mongodb.client.MongoDatabase; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import org.bson.Document; import com.mongodb.MongoClient; public class SkipRecords {    public static void main( String args[] ) {       //Creating a MongoDB client       MongoClient mongo = new MongoClient( "localhost" , 27017 );   ... Read More

Display OpenCV Mat Object Using Swings

Maruthi Krishna
Updated on 10-Apr-2020 07:12:22

663 Views

The class ImageIcon is an implementation of the Icon interface that paints Icons from Images. You can display images on a Swing window using this class, the constructor of this class accepts a BufferedImage object as a parameter.Therefore to display an OpenCV image that is stored in a Mat object using Swing window, you need to convert it into a BufferedImage object and pass it as a parameter to the ImageIcon method.Exampleimport java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.InputStream; import javax.imageio.ImageIO; import javax.swing.ImageIcon; import javax.swing.JFrame; import javax.swing.JLabel; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfByte; import org.opencv.imgcodecs.Imgcodecs; public class DisplayingImagesUsingSwings {    public static ... Read More

Display OpenCV Mat Object Using JavaFX

Maruthi Krishna
Updated on 10-Apr-2020 07:10:36

506 Views

The JavaFX library provides a class with name ImageView using this you can display an image. This class accepts an object of the WritableImage class.To display an image Stored in OpenCV Mat object you need to convert it into a WritableImage object and pass it the ImageView class.Exampleimport java.awt.image.BufferedImage; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; 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 javax.imageio.ImageIO; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfByte; import org.opencv.imgcodecs.Imgcodecs; public class DisplayingImagesJavaFX extends Application {    @Override    public void start(Stage stage) throws IOException {       WritableImage writableImage = ... Read More

Importance of JMOD Format in Java 9

raja
Updated on 09-Apr-2020 18:15:29

1K+ Views

Java 9 has introduced a new format called "jmod" to encapsulate modules. The jmod files can be designed to handle more content types than jar files. It can also package local codes, configuration files, local commands, and other types of data. The "jmod" format hasn't support at runtime and can be based on zip format currently. The jmod format can be used at both compile and link time and can be found in JDK_HOME\jmods directory, where JDK_HOME is a directory. The files in jmod format have a ".jmod" extension.Java 9 comes with a new tool called jmod, and it is located in the ... Read More

Advertisements