Programming Articles

Page 162 of 2547

How to implement ORB feature detectors in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 4K+ Views

ORB (Oriented FAST and Rotated BRIEF) is a fusion of FAST keypoint detector and BRIEF descriptors with many modifications to enhance performance. ORB is rotation invariant and resistant to noise, making it ideal for real-time applications like object recognition and image matching. Steps to Implement ORB Feature Detector To implement ORB feature detector and descriptors, follow these steps: Import the 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 using cv2.cvtColor() method. Initiate ...

Read More

How to detect and draw FAST feature points in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 3K+ Views

FAST (Features from Accelerated Segment Test) is a high-speed corner detection algorithm designed for real-time applications. OpenCV provides a simple interface to detect corner features using the FAST algorithm through cv2.FastFeatureDetector_create(). How FAST Algorithm Works FAST detects corners by examining a circle of 16 pixels around each candidate point. If a continuous arc of pixels (usually 12 or more) are all brighter or darker than the center pixel by a threshold value, it's classified as a corner feature. Steps to Detect FAST Features To detect and draw feature points using the FAST detector, follow these steps ...

Read More

OpenCV Python – How to detect and draw keypoints in an image using SIFT?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 6K+ Views

SIFT (Scale-Invariant Feature Transform) is a scale invariant feature descriptor that detects keypoints in images and computes their descriptors. SIFT keypoints are robust to changes in scale, rotation, and illumination, making them ideal for object recognition and image matching tasks. How SIFT Works SIFT detects keypoints by finding locations in an image that are distinctive and stable across different scales. The algorithm creates a SIFT object with cv2.SIFT_create(), detects keypoints using sift.detect(), and draws them using cv2.drawKeypoints(). Steps to Detect and Draw Keypoints To detect and draw keypoints in an input image using SIFT algorithm, follow ...

Read More

How to perform matrix transformation in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 5K+ Views

The cv2.transform() function performs matrix transformation of each element in an input array. Since images in OpenCV are NumPy arrays, we can apply transformations directly to modify pixel values using a transformation matrix. Syntax cv2.transform(src, m, dst=None) Parameters src − Input array (image) m − Transformation matrix of size (output_channels, input_channels) dst − Output array (optional) Steps to Perform Matrix Transformation Follow these steps to apply matrix transformation to an image − Import the required libraries OpenCV and NumPy Read the input image using cv2.imread() Define a transformation ...

Read More

How to extract the foreground of an image using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 3K+ Views

OpenCV's GrabCut algorithm is a powerful method for foreground extraction from images. The cv2.grabCut() function uses iterative graph cuts to separate foreground objects from the background based on a user-defined rectangle. Algorithm Overview GrabCut works by modeling foreground and background pixels using Gaussian Mixture Models (GMM). You define a rectangle around the object of interest, and the algorithm iteratively refines the segmentation ? Step-by-Step Process Import required libraries OpenCV and NumPy Read the input image using cv2.imread() Initialize variables: mask, bgdModel, and fgdModel Define rectangle coordinates (x, y, width, height) that enclose the foreground object ...

Read More

How to find discrete cosine transform of an image using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 7K+ Views

The discrete cosine transform (DCT) is a mathematical technique used in image processing for frequency domain analysis and compression. OpenCV provides cv2.dct() to compute DCT of an image and cv2.idct() to apply inverse DCT. Syntax cv2.dct(src, flags) cv2.idct(src, flags) Parameters src − Input image as float32 array flags − Transformation flags (cv2.DCT_INVERSE or cv2.DCT_ROWS) Steps to Apply DCT To find discrete cosine transform of an input image, follow these steps − Import the required libraries OpenCV and NumPy Read the input image using cv2.imread() and convert to grayscale ...

Read More

How to compare histograms of two images using OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 6K+ Views

The histograms of two images can be compared using cv2.compareHist() function. This function accepts three input arguments: hist1, hist2, and compare_method. The hist1 and hist2 are histograms of the two input images, while compare_method is a metric to compute the matching between the histograms. It returns a numerical parameter that expresses how well two histograms match with each other. Comparison Methods OpenCV provides four different histogram comparison methods: Method Description Perfect Match No Match HISTCMP_CORREL Correlation 1 0 HISTCMP_CHISQR Chi-Square 0 ∞ HISTCMP_INTERSECT Intersection Higher values = better match ...

Read More

How to perform distance transformation on a given image in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 1K+ Views

Distance transformation is a morphological operation that calculates the distance from every pixel of the foreground to the nearest pixel of the background in a binary image. OpenCV provides the cv2.distanceTransform() method to perform this operation. Syntax cv2.distanceTransform(src, distanceType, maskSize) Parameters This method accepts the following parameters ? src − 8-bit, single-channel (binary) source image. distanceType − Type of distance calculation (cv2.DIST_L1, cv2.DIST_L2, cv2.DIST_C). maskSize − Size of the distance transform mask (3, 5, or cv2.DIST_MASK_PRECISE). Steps to Perform Distance Transform Import required libraries (OpenCV, NumPy, Matplotlib) Read ...

Read More

How to find the Fourier Transforms of Gaussian and Laplacian filters in OpenCV Python?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 1K+ Views

We apply Fourier Transform to analyze the frequency characteristics of various filters. We can apply Fourier transform on the Gaussian and Laplacian filters using np.fft.fft2(). We use np.fft.fftshift() to shift the zero-frequency component to the center of the spectrum. Steps To find Fourier transforms of the Gaussian or Laplacian filters, you could follow the steps given below − Import the required libraries. In all below Python examples the required Python libraries are OpenCV, NumPy and Matplotlib. Make sure you have already installed them. Define a Gaussian or a Laplacian Filter. Apply Fourier transform on the above ...

Read More

OpenCV Python – How to find the shortest distance between a point in the image and a contour?

Shahid Akhtar Khan
Shahid Akhtar Khan
Updated on 26-Mar-2026 5K+ Views

In OpenCV, we can compute the shortest distance between a point and a contour using cv2.pointPolygonTest(). This function takes contour coordinates and a point coordinate as arguments and returns the shortest Euclidean distance between them. Syntax distance = cv2.pointPolygonTest(contour, point, measureDist) Parameters contour − The input contour point − The point coordinates as a tuple (x, y) measureDist − If True, returns actual distance. If False, returns +1, 0, or -1 Return Value Positive − Point is inside the contour Negative − Point is outside the contour Zero − ...

Read More
Showing 1611–1620 of 25,469 articles
« Prev 1 160 161 162 163 164 2547 Next »
Advertisements