Last Updated : 11 Aug, 2025
Corner detection is a fundamental technique in computer vision, powering applications like image stitching, panorama creation, object recognition and motion tracking. Corner as a point in an image where the pixel intensity changes sharply in two or more directions. These are:
OpenCV’s cv2.goodFeaturesToTrack() implements Shi-Tomasi algorithm, which selects the N strongest corners in a grayscale image.
Syntaxcv2.goodFeaturesToTrack(image, maxCorners, qualityLevel, minDistance, corners=None, mask=None, blockSize=3, useHarrisDetector=False, k=0.04)
Parameters:
Start by importing required libraries NumPy for efficient array handling, OpenCV (cv2) for image processing operations and Matplotlib for visualizing results such as detected corners or processed images.
Python
import numpy as np
import cv2
from matplotlib import pyplot as plt
Step 2: Load and Preprocess the Image
Use cv2.imread('corner1.png') to read the image file. Image can be downloaded from here.
Python
img = cv2.imread('corner1.png')
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
Here, we are converting the image to grayscale corner detection works on intensity changes, so color isn’t needed.
Step 3: Detect Corners Python
corners = cv2.goodFeaturesToTrack(
gray,
maxCorners=27,
qualityLevel=0.01,
minDistance=10,
blockSize=3,
useHarrisDetector=False,
k=0.04
)
We detect up to 27 corners with:
We convert corner coordinates to integers with np.intp(), flatten them using ravel() and draw small filled green circles at each corner using cv2.circle(). Finally, we convert BGR to RGB for Matplotlib, set the title, hide axes and display the image.
Python
corners = np.intp(corners) # Convert to integer coords
for corner in corners:
x, y = corner.ravel()
cv2.circle(img, (x, y), radius=3, color=(0, 255, 0), thickness=-1)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))
plt.title('Corners Detected')
plt.axis('off')
plt.show()
Output:
Corner Detection OutputRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4