In this tutorial we will talk about Feature Matching with OpenCV. In my example I used the same book cover but in different lighting conditions, position and perspective.
For a normal comparison they could be different but two simple steps we can compare the main characteristics:
- Orb detector method
- Brute Force Matching
Orb detector method
Passing the image to the ORB Detector method we obtain an array with the definition of the image characteristics. Obviously it will not do the pixel by pixel analysis because obviously they will be different. Here is the code:
# ORB Detector orb = cv2.ORB_create() kp1, des1 = orb.detectAndCompute(img1, None) kp2, des2 = orb.detectAndCompute(img2, None)
Now let’s take the descriptor of both images, in my example defined with des1 and des2 . Obviously we need a comparison function for feature matching.
Brute Force Matching
For this purpose we use the BFMatcher opencv method. Here are some parameters to set:
- Norm_hamming is used when comparing Orb detector arrays
- crosscheck = true it allows us to have only the results with the best score in the comparison
This is the code:
# Brute Force Matching bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True) matches = bf.match(des1, des2) matches = sorted(matches, key = lambda x:x.distance)
Finally we draw the lines that represent the equalities:
matching_result = cv2.drawMatches(img1, kp1, img2, kp2, matches[:50], None, flags=2)
The image below is an example of the final result. I do not recommend using this method for real-time analysis, such as a video, because it requires a lot of computing energy


Hi there, I’m the founder of Pysource.
I’m a Computer Vision Consultant, developer and Course instructor.
I help Companies and Developers to build efficient computer vision software.
Amazing…. You explained it better than Sentdex….
NO ONE IS BETTER THAN SENTDEX
Sentdex is awesome 🙂
keep it up
Thanks Sir, You explained very well.. Sir also explain the differences among the three mentioned detectors algorithm and which one is suitable in which scenario.
Thank you Sergio for this explanation. Can you tell some thing about other matching strategies.
Sir I want to know that how would you calculate and store the results of both images.pls help
Thank you so much for your great video about detecting and matching key points between two images.
I have a request that is could you please provide a video like this one and explain how we can get disparity map? Because I obtain the disparity map wrongly from images.
Thanks a lot.