I N F O A R Y A N

Augmented Reality From Scratch OpenCV-Python | Computer Vision Project | Resume Builder | Feature Detection

Step into a world where reality becomes a canvas, waiting to be infused with digital wonders and imaginative spectacles. This is the realm of Augmented Reality (AR), a mesmerizing tapestry woven with threads of possibility, distinct from the dreamscape of Virtual Reality (VR). In this voyage, we delve into the captivating symphony of AR development, orchestrated by the dynamic duo of Python and the Open Source Computer Vision Library (OpenCV).

Flow of the Article:

  1. Understanding the concept of Augmented Reality 
  2. Formulating the algorithm for feature detection
  3. Formulating algorithm for tracking the objects.

 

Understanding the Feature Detection using Images in OpenCV

  1. Load Image:

    • Read an image file named ‘meluha.jpg’ using OpenCV.
    • Resize the image to dimensions 400×550 pixels using bilinear interpolation.
  2. Convert to Grayscale:

    • Convert the color image to grayscale using the cvtColor function from OpenCV.
  3. Feature Detection Initialization:

    • Create an ORB (Oriented FAST and Rotated BRIEF) object using the cv2.ORB_create function, allowing a maximum of 1000 keypoints.
  4. Detect Keypoints and Descriptors:

    • Use the ORB object to detect keypoints and compute descriptors on the grayscale image.
    • The keypoints are the distinctive points in the image, and descriptors are numerical representations of the local image patches around the keypoints.
  5. Draw Keypoints on Original Image:

    • Use the detected keypoints to draw green circles on the original color image, indicating the location of the keypoints.
    • The resulting image with keypoints is stored in the variable final_keypoints.
  6. Display Result:

    • Display the image with drawn keypoints using the cv2.imshow function.
    • Wait for a key event with cv2.waitKey().
  7. Close Window:

    • Close the image window when any key is pressed.

To see this enchanting concept in action, watch our YouTube video for demonstration of the project and code explanation in detail. 

This video explains about feature detection

 

Understanding the Feature Matching

  1. Initialize ORB Feature Detector:

    • Set a threshold of minimum matches (MIN_MATCHES) to 20.
    • Create an ORB (Oriented FAST and Rotated BRIEF) feature detector with a maximum of 5000 keypoints.
  2. Prepare FLANN-Based Matcher:

    • Define parameters for the FLANN (Fast Library for Approximate Nearest Neighbors) matcher, such as the algorithm and number of trees.
    • Create a FLANN-based matcher using the defined parameters.
  3. Load Input Image and Keypoints:

    • Read an image file named ‘meluha.jpg’.
    • Resize the image to dimensions 400×550 pixels using bilinear interpolation.
    • Convert the color image to grayscale.
    • Use the ORB detector to find keypoints and descriptors in the grayscale image.
  4. Compute Matches:

    • Define a function (compute_matches) to compute matches between input and output descriptors using the FLANN matcher.
    • Apply a distance ratio test to filter out good matches.
  5. Main Logic:

    • Start capturing video from the default camera (camera index 0).
    • In a loop, read frames from the camera.
    • Check for a minimum number of input keypoints; if not met, continue to the next iteration.
    • Resize the frame for faster computation.
    • Convert the frame to grayscale.
    • Use the ORB detector to find keypoints and descriptors in the current frame.
    • Call the compute_matches function to find matches between input and output descriptors.
    • If matches exist, draw them on the frame; otherwise, display the original frame.
    • Display the resulting frame in a window named ‘Final Output’.
    • Exit the loop if the ‘Esc’ key (27) is pressed.

 

The Code for the project is located here.

Last part is the image augmentation which is a simple module and can be understood in the video above. 

To see these enchanting concepts in action, watch our YouTube video series for demonstration of the project and code explanation in detail.

Augmented Reality using OpenCV, OpenCV using Augmented Reality, AR projects, Augmented Reality from Scratch, Using Augmented reality to augmented images, Infoaryan.com, aryan verma blog, aryan verma, OpenCV python, Python projects, computer vision projects