Found 33676 Articles for Programming

OpenCV Python – Matching the key points of two images using ORB and BFmatcher

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:44:54

4K+ Views

To match the keypoints of two images, we use ORB (Oriented FAST and Rotated BRIEF) to detect and compute the feature keypoints and descriptors and Brute Force matcher to match the descriptors in both images. Steps To match keypoints of two images using the ORB feature detector and Brute Force matcher, you could follow the steps given below − Import the required libraries OpenCV, Matplotlib and NumPy. Make sure you have already installed them. Read two input images using cv2.imread() method as grayscale images. Specify the full path of the image. Initiate ORB object orb with default ... Read More

How to blur faces in an image using OpenCV Python?

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:42:14

3K+ Views

To blur faces in an image first we detect the faces using a haar cascade classifier. OpenCV provides us with different types of trained haarcascades for object detection. We use haarcascade_frontalface_alt.xml as a haarcascade xml file. To blur the face area, we apply the cv2.GaussianBlur(). How to Download Haarcascade? You can find different haarcascades following the GitHub website address − https://github.com/opencv/opencv/tree/master/data/haarcascades To download a haarcascade for face detection, click the haarcascade_frontalface_alt.xml file. Open it in raw format, right click and save. Steps You could follow the steps given below to blur faces in an image − Import ... Read More

How to implement ORB feature detectors in OpenCV Python?

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:39:38

4K+ Views

ORB (Oriented FAST and Rotated BRIEF) is a fusion of FAST keypoint detector and BRIEF descriptors with many changes to enhance the performance. To implement ORB feature detector and descriptors, you could follow the steps given below 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 image using cv2.cvtColor() method. Initiate the ORB object with default values using orb=cv2.ORB_create(). Detect and compute the feature keypoints 'kp' and descriptor 'des' in the ... Read More

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

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:37:14

3K+ Views

FAST (Features from Accelerated Segment Test) is a high speed corner detection algorithm. We use the FAST algorithm to detect features in the image. We first create a FAST object with cv2.FastFeatureDetector_create(). Then detect the feature points using fast.detect() where fast is the created FAST object. To draw featurepoints, we use cv2.drawKeypoints(). Steps To detect and draw feature points in the input image using the FAST feature detector, you could follow the steps given below 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 ... Read More

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

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:34:36

6K+ Views

SIFT (Scale-Invariant Feature Transform ) is scale invariant feature descriptor. It detects keypoints in the image and computes its descriptors. We first create a SIFT object with cv2.SIFT_create(). Then detect the keypoints using sift.detect() where sift is the created SIFT object. To draw keypoints, we use cv2.drawKeypoints(). Steps To detect and draw keypoints in the input image using SIFT algorithm, you could follow the steps given below Import the required libraries OpenCVand 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 ... Read More

How to perform matrix transformation in OpenCV Python?

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:31:22

5K+ Views

The cv2.transform() function performs the matrix transformation of each element of the input array. We could apply this transformation directly on the image as the images are NumPy ndarrays in OpenCV. To use this function, we should first define a transformation matrix m. The number of channels in the output will be the same as the number of rows in the transformation matrix m. Steps To find matrix transform of an input image, you could follow the steps given below- Import the required libraries OpenCV and NumPy. Make sure you have already installed them. Read the input ... Read More

How to rotate an image in OpenCV Python?

Shahid Akhtar Khan
Updated on 28-Aug-2023 13:20:58

30K+ Views

OpenCV provides us the function cv.rotate() to rotate an image (NumPy array) in multiples of 90 degrees. This function rotates an image in three possible ways: 90, 180, and 270 degrees clockwise. We use the following syntax − Syntax cv2.rotate(img, rotateCode) rotateCode is a rotate flag specifying how to rotate the array. The three rotate flags are as below − cv2.ROTATE_90_CLOCKWISE cv2.ROTATE_180 cv2.ROTATE_90_COUNTERCLOCKWISE Steps To rotate an input image, you could follow the steps given below − Import the required libraries OpenCV and matplotlib. Make sure you have already installed them. Read the input image using ... Read More

How to blend images using image pyramids in OpenCV Python?

Shahid Akhtar Khan
Updated on 05-Dec-2022 10:25:55

1K+ Views

We can blend the images using the Gaussian and Laplacian image pyramids. The Gaussian pyramid is a type of image pyramid. To create a Gaussian pyramid, OpenCV provides us two functions cv2.pyrDown() and cv2.pyrUp(). We can form the Laplacian Pyramids from the Gaussian pyramids. In Laplacian pyramid images look like edge images only. A level in the Laplacian Pyramid is formed by the difference between that level in the Gaussian Pyramid and the expanded version of its upper level in the Gaussian Pyramid. Steps To blend images using image pyramids, we could follow the steps given below − ... Read More

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

Shahid Akhtar Khan
Updated on 02-Dec-2022 11:08:18

3K+ Views

We apply the cv2.grabCut() method to extract the foreground in an image. For detailed approach please follow the steps given below − 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 image path. Define the variables: mask, bgdModel and fgdModel. Define the coordinates of a rectangle "rect" which includes the foreground object in the format (x, y, w, h). The correct coordinates are very important to extract the meaningful foreground. Apply grabCut() algorithm to extract the foreground of the input image. Pass mask, ... Read More

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

Shahid Akhtar Khan
Updated on 02-Dec-2022 11:06:22

6K+ Views

We apply cv2.dct() to find the discrete cosine transform of an image. This function transforms the grayscale image of dtype float32. It accepts two types of flag cv2.DCT_INVERSE or cv2.DCT_ROWS. To convert the transformed image to the original image we use cv2.idct(). Steps To find discrete cosine transform of an input image, you could follow the steps given below − 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 image using cv2.cvtColor() metod. Convert ... Read More

Advertisements