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!

Start Spring using IntelliJIDEAUltimate version...

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...

Java...

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...

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...

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

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 to set the SpringBoot project default run configuration list in Idea using IntelliJ...


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

Atom editor mac version download
The most popular open source editor

SublimeText3 Linux new version
SublimeText3 Linux latest version

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.