AI & MLBeginnerPRJ-090

AI Air Drawing Using Python

Draw on screen by moving your index finger in front of a webcam.

Built and tested by Shahan Fathima K · Industrial Robotics Institute

Laptop / PC with webcam

Python 3.11.9, OpenCV, MediaPipe, NumPy, PyCharm IDE

LevelBeginner
Build time1–2 hours
BoardLaptop / PC with webcam
Parts2 components

What is the AI Air Drawing Using Python?

AI Air Drawing is a computer vision application that lets users draw in the air using hand gestures instead of a mouse or touchscreen. AI-based hand tracking detects the finger position from a webcam and converts its movement into a digital drawing on screen. It is built in Python with OpenCV, MediaPipe and NumPy.

How it works

  1. The webcam captures live video, which is mirrored for natural interaction.
  2. MediaPipe detects the hand and its 21 landmarks.
  3. Landmark 8 (index fingertip) is tracked and converted to pixel coordinates.
  4. A green line is drawn on a black canvas from the previous to the current fingertip position.
  5. The canvas is merged with the live video; tracking resets when the hand leaves the frame.
  6. Press Q to quit.

Parts list

ComponentQty
Laptop / Computer1
Webcam1

Software

  • Python 3.11.9
  • OpenCV
  • MediaPipe
  • NumPy
  • PyCharm IDE

How to build the AI Air Drawing Using Python

  1. Install Python 3.11.9 and enable ‘Add Python to PATH’.
  2. Install PyCharm Community Edition and create a new project.
  3. Install the libraries: pip install opencv-python mediapipe numpy.
  4. Copy the Python code into a new file in the project.
  5. Run the script with a webcam connected.
  6. Move your index finger in front of the camera to draw; press Q to exit.

AI Air Drawing Using Python code

Complete, tested Python code for this project. Copy it into Python 3.11.9 and upload it and run it.

import cv2
import mediapipe as mp
import numpy as np

cap = cv2.VideoCapture(0)
mpHands = mp.solutions.hands
hands = mpHands.Hands(max_num_hands=1)
mpDraw = mp.solutions.drawing_utils

canvas = None
prev_x, prev_y = 0, 0

while True:
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)

    if canvas is None:
        canvas = np.zeros_like(frame)

    rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
    result = hands.process(rgb)

    if result.multi_hand_landmarks:
        for handLms in result.multi_hand_landmarks:
            mpDraw.draw_landmarks(frame, handLms, mpHands.HAND_CONNECTIONS)

            landmarks = [(int(lm.x*640), int(lm.y*480)) for lm in handLms.landmark]

            x, y = landmarks[8]

            if prev_x == 0 and prev_y == 0:
                prev_x, prev_y = x, y

            cv2.line(canvas, (prev_x, prev_y), (x, y), (0,255,0), 5)

            prev_x, prev_y = x, y

    else:
        prev_x, prev_y = 0, 0

    frame = cv2.add(frame, canvas)

    cv2.imshow("Air Drawing", frame)

    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Real-world uses

  • Touch-free interactive drawing
  • Virtual whiteboard for teaching
  • Gesture-control demos
  • Learning computer vision

Frequently asked questions

What is a AI Air Drawing Using Python?

AI Air Drawing is a computer vision application that lets users draw in the air using hand gestures instead of a mouse or touchscreen. AI-based hand tracking detects the finger position from a webcam and converts its movement into a digital drawing on screen.

What components are needed for the AI Air Drawing Using Python?

You need: Laptop / Computer (1), Webcam (1). Software: Python 3.11.9, OpenCV, MediaPipe, NumPy, PyCharm IDE.

Is the AI Air Drawing Using Python project good for beginners?

Yes. It is rated beginner and takes about 1–2 hours to build, using the Laptop / PC with webcam. The guide on this page explains every connection and step.

Where can I get the code for the AI Air Drawing Using Python?

The complete, tested Python code is free on this page. Copy it into Python 3.11.9 and upload it and run it.

Do I need any hardware for the AI Air Drawing Using Python?

No kit is needed. This project runs on a laptop or PC with webcam. For help with the setup, message IRI on WhatsApp at +91 86060 82634.

Industrial Robotics Institute
Logo