
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
How to Detect the key points of an image using OpenCV Java library?
The detect() method of the org.opencv.features2d.Feature2D (abstract) class detects the key points of the given image. To this method, you need to pass a Mat the object representing the source image and an empty MatOfKeyPoint object to hold the read key points.
You can draw the draw key points on the image using the drawKeypoints() method of the org.opencv.features2d.Features2d class.
Note
Since Feature2D is an abstract class you need to instantiate one of its subclasses to invoke the detect() method. Here we have used the FastFeatureDetector class.
Features2D and Features2d are two different classes of the package features2d don’t get confused...
Example
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfKeyPoint; import org.opencv.core.Scalar; import org.opencv.features2d.FastFeatureDetector; import org.opencv.features2d.Features2d; import org.opencv.highgui.HighGui;z import org.opencv.imgcodecs.Imgcodecs; public class DetectingKeyPoints{ public static void main(String args[]) throws Exception { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the contents of the image String file ="D:\Images\javafx_graphical.jpg"; Mat src = Imgcodecs.imread(file); //Reading the key points of the image Mat dst = new Mat(); MatOfKeyPoint matOfKeyPoints = new MatOfKeyPoint(); FastFeatureDetector featureDetector = FastFeatureDetector.create(); featureDetector.detect(src, matOfKeyPoints); //Drawing the detected key points Features2d.drawKeypoints(src, matOfKeyPoints, dst, new Scalar(0, 0, 255)); HighGui.imshow("Feature Detection", dst); HighGui.waitKey(); } }
Input Image
Output
- Related Articles
- How to detect faces in an image using Java OpenCV library?
- How to match the key points of two images using OpenCV Java library?
- How to write an image using Java OpenCV library?
- How to flip an image using Java OpenCV library?
- How to alter the contrast of an image using Java OpenCV library?
- How to alter the brightness of an image using Java OpenCV library?
- How to alter the sharpness of an image using Java OpenCV library?
- How to add noise to an image using Java OpenCV library?
- How to add text to an image using Java OpenCV library?
- How to add borders to an image using Java OpenCV library?
- How to change the color spaces of an image using Java OpenCV library?
- How to draw markers on an image using Java OpenCV library?
- How to get pixels (RGB values) of an image using Java OpenCV library?
- How to find Image Contours using Java OpenCV library?
- How to draw Image Contours using Java OpenCV library?

Advertisements