Found 2616 Articles for Java

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

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

586 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

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

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

179 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

How to draw polylines in OpenCV using Java?

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

429 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 such as resize(), filter2D, etc.. In addition to these It also provides a set of method to draw geometrical shapes on images.Among them to draw a polylines you need to invoke the polylines() method of this class. This method accepts the following parameters −A Mat object representing the image on which the polygon is to be drawn.A-List object holding the objects of the type MatOfPoint.A parameter of the type boolean specifying whether the poly-lines are closed.A Scalar object ... Read More

How to draw a polygon in OpenCV using Java?

Maruthi Krishna
Updated on 10-Apr-2020 07:55:56

333 Views

A polygon with all the interior angles less than 180 is known as a convex polygon. The org.opencv.imgproc package of Java OpenCV library contains a class named Imgproc. To draw a polygon you need to invoke the fillConvexPoly() method of this class. This method accepts 3 parameters −A Mat object representing the image on which the polygon is to be drawn.A MatOfPoint object points between which the polygon is to be drawn.A Scalar object representing the color of the polygon.Exampleimport org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; 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 DrawingConvexPolygon {    public ... Read More

Advertisements