- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Implementing Shi-Tomasi Corner Detector in OpenCV Python
The Shi-Tomasi Corner Detector is an enhanced algorithm of the Harris Corner Detector. To implement the Shi-Tomasi corner detector, OpenCV provides us with the function, cv2.goodFeaturesToTrack(). It detects N strongest corners in the image.
Steps
To detect corners in an image using Shi-Tomasi corner detector, you could follow the steps given below −
Import required libraries OpenCV and NumPy. Make sure you have already installed them.
Read the input image using cv2.imread() method. Specify the full path of the image. Convert the input image to grayscale image using cv2.cvtColor() metod.
Apply cv2.goodFeaturesToTrack() function on the grayscale image. Pass suitable number of corners, quality level and Euclidean distance between two corners to the method as parameters. This function returns the corners as floating points in the image. Convert these floating point corners to the integers.
Draw corner points on the input image as filled circles with a small radius.
Display the image with detected corners.
Let's see the examples to detect corners in an image using Shi-Tomasi Corner Detector.
Input Image
We will use this image as an input file in the example below.
Example
In this example, we detect corners in an input image using the Shi-Tomasi corner detector.
# import required libraries import numpy as np import cv2 # read the input image img = cv2.imread('building.jpg') # convert the image to grayscale gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # apply Shi-Tomasi corner detector on gray image # to detect 50 best corners corners = cv2.goodFeaturesToTrack(gray,50,0.01,10) # convert floating points to integers corners = np.int0(corners) # loop over all points and draw corner points as circles for i in corners: x,y = i.ravel() cv2.circle(img,(x,y),3,(0,0,255),-1) # Display image with corner points drawn on it cv2.imshow("Corners", img) cv2.waitKey(0) cv2.destroyAllWindows()
Output
When you run the above Python program, it will produce the following output window −
The above output image shows the corners detected using the Shi-Tomasi corner detector. The corner points are shown in red color.
- Related Articles
- Detecting corners using Harris corner detector in Python OpenCV
- Implementing k-Nearest Neighbor in OpenCV Python?
- OpenCV Python – Implementing feature matching between two images using SIFT
- WebCam Motion Detector program in Python ?
- Implementing Photomosaics in Python
- Radiation Detector
- Cell Count After Removing Corner Diagonals in Python
- Implementing web scraping using lxml in Python?
- Implementing Web Scraping in Python with BeautifulSoup?
- Implementing Web Scraping in Python with Scrapy
- Implementing web scraping using lxml in Python Programming
- Python Implementing Web Scraping with Scrapy
- Python Implementing web scraping using lxml
- Line detection in python with OpenCV?
- Template matching using OpenCV in Python
