Programming Articles - Page 2019 of 3366

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

Maruthi Krishna
Updated on 10-Apr-2020 08:47:14

683 Views

You can compute bitwise conjunction between two images using the bitwise_and() method of the org.opencv.core.Core class.This method accepts three Mat objects representing the source, destination and result matrices, calculates the bitwise conjunction of each every 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 conjunction 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 BitwiseAndExample {    public static void main(String args[]) throws Exception {       //Loading the OpenCV core library   ... Read More

How JShell tool works internally in Java 9?

raja
Updated on 10-Apr-2020 08:52:04

373 Views

JShell tool has introduced in Java 9 that provides a fast and friendly environment that enables us to quickly explore, discover, and experiment with Java language features and extensive libraries.When the code entered into the JShell console, it is processed by JLine. It is a Java library that allows us to capture on a console. Once the code has been entered, it is parsed by JShell parser in order to determine its type (method, variable, etc.).JShell Parser is wrapped in a class with the following rules:All imports are placed at the top of this class.Variables, methods and class declarations become static members ... Read More

How to change the color spaces of an image using Java OpenCV library?

Maruthi Krishna
Updated on 10-Apr-2020 08:42:41

796 Views

Using color space protocol you can represent the colors in an image. There are several color spaces available in OpenCV some of them are −BGR − RGB is the most widely used color space in this, each pixel is actually formed by three different colors (intensity) values: red, blue and green, it is the default color space in OpenCV but it is stored as BGR.HSV − In HSV color space the different colors are formed by changing the hue, saturation, and brightness.CMK − This is a subtractive color space, in this the different colors are formed by subtracting the Cyan, ... Read More

How to drop a MongoDB Collection using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:39:17

2K+ Views

You can drop an existing collection from MongoDB using the drop() method.Syntaxdb.coll.drop()Where, db is the database.coll is the collection (name) in which you want to insert the documentExampleAssume 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 } > db.createCollection("sample") { "ok" : 1 } > show collections sample students teachersThe following query deletes the collection named sample.> db.sample.drop() true > show collections example students teachersUsing Java programIn Java, you can drop a collection using the in ... Read More

How to delete a MongoDB document using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:24:56

3K+ Views

You can delete a document from an existing collection in MongoDB using the remove() method.Syntaxdb.coll.remove(DELLETION_CRITTERIA)Where, db is the database.coll is the collection (name) in which you want to insert the documentExampleAssume we have a collection named students in the MongoDB database with the following documents −{name:"Ram", age:26, city:"Mumbai"} {name:"Roja", age:28, city:"Hyderabad"} {name:"Ramani", age:35, city:"Delhi"}The following query deletes the document with name value as Ram.> db.test.remove({'name': 'Ram'}) WriteResult({ "nRemoved" : 1 }) > db.test.find() { "_id" : ObjectId("5e8700"), "name" : "Roja", "age" : 28, "city" : "Hyderabad" } { "_id" : ObjectId("5e4161"), "name" : "Ramani", "age" : 35, "city" : "Delhi" ... Read More

How to retrieve all the documents from a MongoDB collection using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:20:50

20K+ Views

You can retrieve documents from an existing collection in MongoDB using the find() method.Syntaxdb.coll.find()Where, db is the database.coll is the collection (name) in which you want to insert the documentExampleAssume we have a collection named students in the MongoDB database with the following documents −{name:"Ram", age:26, city:"Mumbai"} {name:"Roja", age:28, city:"Hyderabad"} {name:"Ramani", age:35, city:"Delhi"}The following query retrieves all the documents from the collected sample.> use myDatabase() switched to db myDatabase() > db.createCollection(sample) { "ok" : 1 } > > db.sample.find() { "_id" : ObjectId("5e870492af638d501865015f"), "name" : "Ram", "age" : 26, "city" : "Mumbai" } { "_id" : ObjectId("5e870492af638d5018650160"), "name" : "Roja", ... Read More

How to insert multiple document into a MongoDB collection using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:18:40

2K+ Views

You can insert multiple documents into an existing collection in MongoDB using the insertMany() method.Syntaxdb.coll.insert(docArray)Where, db is the database.coll is the collection (name) in which you want to insert the documentdocArray is the array of documents you want to insert.Example> use myDatabase() switched to db myDatabase() > db.createCollection(sample) { "ok" : 1 } > db.test.insert([{name:"Ram", age:26, city:"Mumbai"}, {name:"Roja", age:28, city:"Hyderabad"}, {name:"Ramani", age:35, city:"Delhi"}]) BulkWriteResult({    "writeErrors" : [ ],    "writeConcernErrors" : [ ],    "nInserted" : 3,    "nUpserted" : 0,    "nMatched" : 0,    "nModified" : 0,    "nRemoved" : 0,    "upserted" : [ ] })Using ... Read More

How to insert a document into a MongoDB collection using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:15:34

6K+ Views

You can insert a document into an existing collection in MongoDB using the insert() method.Syntaxdb.coll.insert(doc)Where, db is the database.coll is the collection (name) in which you want to insert the documentdoc is the document you want to insert.Example> use myDatabase() switched to db myDatabase() > db.createCollection(sample) { "ok" : 1 } > db.sample.insert({name:"Ram", age:26, city:"Hyderabad"}) WriteResult({ "nInserted" : 1 })Using Java programIn Java, you can insert a document into a collection using the insertOne() method of the com.mongodb.client.MongoCollection interface. This method accepts a document (object) representing the document you want to insert as a parameter.Therefore to create a collection in MongoDB ... Read More

How to create a MongoDB collection using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:12:03

3K+ Views

You can create a collection in MongoDB using the db.createCollection() method.Syntaxdb.createCollection(name, options)Wheredb is the database.name is the name of the collection you want to create.Option is the set of optional parameters such as capped, auto indexed, size and, max.Example> use myDatabase switched to db myDatabase > db.createCollection("myCollection") { "ok" : 1 }Using Java programIn Java, you can create a collection using the createCollection() method of the com.mongodb.client.MongoDatabase interface. This method accepts a string value representing the name of the collection.Therefore to create a collection in MongoDB using Java program −Make sure you have installed MongoDB in your systemAdd the following dependency ... Read More

How to draw a filled ellipse in OpenCV using Java?

Maruthi Krishna
Updated on 10-Apr-2020 08:01:15

261 Views

The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc this class provides various methods to process an input image. It provides a set of methods to draw geometrical shapes on images.This class provides a method named ellipse() using this you can draw an ellipse on an image, one of the variants of this method allows you to specify the line type as one of the parameters including −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 ... Read More

Advertisements