How to match keypoints of two images using OpenCV Java library?
org.opencv.features2d.Feature2D (Abstract) class’s detect() method detects key points of a given image. For this method, you need to pass a Mat object representing the source image and an empty MatOfKeyPoint object to hold the read keypoints.
org.opencv.features2d.Feature2D The strong>drawMatches() method of class finds matches between key points of two given images and draws them. This method accepts the following parameters -
src1 - an object source image representing the first Mat class.
keypoints1 - Object of class MatOfKeyPoint, representing the key point of the first source image.
src2 - An object of class Mat representing the second source image.
keypoints2 - Object of class MatOfKeyPoint, representing the key points of the second source image.
matches1to2 strong> - a match from the first image to the second image, meaning keypoints1[i] is in keypoints2[matches[i] ] There are corresponding points in .
dst - An object of Mat class representing the target image.
So, matching the key points of two images -
Read the two sources using the imread() method image.
Get the key points of the image and use the detect() method to draw two images.
Use the drawMatches() method to find and draw matches.
Example
import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfDMatch; import org.opencv.core.MatOfKeyPoint; import org.opencv.features2d.FastFeatureDetector; import org.opencv.features2d.Features2d; import org.opencv.highgui.HighGui; import org.opencv.imgcodecs.Imgcodecs; public class MatchingKeypoints { public static void main(String args[]) throws Exception { //Loading the OpenCV core library System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); //Reading the source images String file1 ="D:\Images\feature1.jpg"; Mat src1 = Imgcodecs.imread(file1); String file2 ="D:\Images\feature2.jpg"; Mat src2 = Imgcodecs.imread(file2); //Creating an empty matrix to store the destination image Mat dst = new Mat(); FastFeatureDetector detector = FastFeatureDetector.create(); //Detecting the key points in both images MatOfKeyPoint keyPoints1 = new MatOfKeyPoint(); detector.detect(src1, keyPoints1); MatOfKeyPoint keyPoints2 = new MatOfKeyPoint(); detector.detect(src2, keyPoints2); MatOfDMatch matof1to2 = new MatOfDMatch(); Features2d.drawMatches(src1, keyPoints1, src2, keyPoints2, matof1to2, dst); HighGui.imshow("Feature Matching", dst); HighGui.waitKey(); } }
Input image
Image1 -
Image2 -
Output
The above is the detailed content of How to match keypoints of two images using OpenCV Java library?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Start Spring using IntelliJIDEAUltimate version...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...
