5/2/25, 6:07 AM Untitled2.
ipynb - Colab
# Install necessary libraries if not installed
!pip install opencv-python numpy matplotlib
# Import libraries
import cv2
import numpy as np
import [Link] as plt
# Function to overlay text and shapes on an image
def add_ar_overlay(image):
overlay = [Link]()
# Add a rectangle (Example: Simulating an AR bounding box)
[Link](overlay, (50, 50), (300, 200), (0, 255, 0), 3)
# Add text on the image (Example: Label an object)
[Link](overlay, "AR Overlay Example", (60, 180), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
# Overlay an external image (Example: AR sticker)
sticker = [Link]("[Link]", cv2.IMREAD_UNCHANGED)
if sticker is not None:
sticker_resized = [Link](sticker, (100, 100))
overlay[50:150, 50:150] = sticker_resized # Place sticker at a specific position
return overlay
# Upload an image for processing
from [Link] import files
uploaded = [Link]()
# Read the uploaded image
image = [Link](list([Link]())[0])
image = [Link](image, cv2.COLOR_BGR2RGB) # Convert to RGB format for display
# Apply AR overlays
ar_image = add_ar_overlay(image)
# Display original and modified images
fig, ax = [Link](1, 2, figsize=(12, 6))
ax[0].imshow(image)
ax[0].set_title("Original Image")
ax[1].imshow(ar_image)
ax[1].set_title("AR Overlay Applied")
[Link]()
[Link] 1/2
5/2/25, 6:07 AM [Link] - Colab
Requirement already satisfied: opencv-python in /usr/local/lib/python3.11/dist-packages ([Link])
Requirement already satisfied: numpy in /usr/local/lib/python3.11/dist-packages (2.0.2)
Requirement already satisfied: matplotlib in /usr/local/lib/python3.11/dist-packages (3.10.0)
Requirement already satisfied: contourpy>=1.0.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.3.2)
Requirement already satisfied: cycler>=0.10 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (0.12.1)
Requirement already satisfied: fonttools>=4.22.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (4.57.0)
Requirement already satisfied: kiwisolver>=1.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (1.4.8)
Requirement already satisfied: packaging>=20.0 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (24.2)
Requirement already satisfied: pillow>=8 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (11.2.1)
Requirement already satisfied: pyparsing>=2.3.1 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (3.2.3)
Requirement already satisfied: python-dateutil>=2.7 in /usr/local/lib/python3.11/dist-packages (from matplotlib) (2.9.0.post0)
Requirement already satisfied: six>=1.5 in /usr/local/lib/python3.11/dist-packages (from python-dateutil>=2.7->matplotlib) (1.17.0)
Choose Files No file chosen Upload widget is only available when the cell has been executed in the current browser session. Please rerun this cell to
enable.
Saving [Link] to [Link]
[Link] 2/2