AI & MLAdvancedPRJ-093

AI Smart Board (Gesture Whiteboard)

A virtual whiteboard: draw, pick colours and drag shapes with hand gestures.

Built and tested by Aboobacker sidheeq K P · Industrial Robotics Institute

Laptop / PC with webcam

Python 3.11, OpenCV (opencv-python), MediaPipe, NumPy, PyCharm (recommended)

LevelAdvanced
Build time2–3 hours
BoardLaptop / PC with webcam
Parts2 components

What is the AI Smart Board (Gesture Whiteboard)?

A gesture-controlled smart board that turns your webcam into an interactive whiteboard. Your index finger is the cursor. In Draw mode you draw freehand in red, green or blue; in Shapes mode you add circles, squares, rectangles and triangles, then pinch to move and resize them. An open hand clears the board.

How it works

  1. The webcam tracks your hand with MediaPipe; the index fingertip is the cursor.
  2. Touch the buttons on the top bar to switch between DRAW and SHAPES, pick a colour, or QUIT.
  3. In Draw mode, raising only your index finger draws lines.
  4. In Shapes mode, touch a shape icon to add it, then pinch thumb and index to drag and resize it.
  5. Opening all five fingers clears the board.

Parts list

ComponentQty
Laptop / Computer1
Webcam (built-in or external)1

Software

  • Python 3.11
  • OpenCV (opencv-python)
  • MediaPipe
  • NumPy
  • PyCharm (recommended)

How to build the AI Smart Board (Gesture Whiteboard)

  1. Install Python 3.11 and tick "Add Python to PATH".
  2. Open a terminal and run: pip install opencv-python mediapipe numpy
  3. Paste the code into a new Python file and run it; the board opens full screen.
  4. Point with your index finger and touch DRAW or SHAPES on the top bar.
  5. Draw, add shapes, pinch to move and resize, open your hand to clear.
  6. Touch QUIT or press q to close.

AI Smart Board (Gesture Whiteboard) code

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

import cv2
import mediapipe as mp
import numpy as np
import math

cap = cv2.VideoCapture(0)

mpHands = mp.solutions.hands
hands = mpHands.Hands(max_num_hands=1,
                      min_detection_confidence=0.8,
                      min_tracking_confidence=0.8)
mpDraw = mp.solutions.drawing_utils

board = np.ones((720, 1280, 3), dtype=np.uint8) * 255
canvas = np.zeros((720, 1280, 3), dtype=np.uint8)

prev_x, prev_y = 0, 0
smooth_x, smooth_y = 0, 0
smoothening = 6
draw_color = (0, 255, 0)
brush_thickness = 7
mode = "draw"


class DraggableShape:
    def __init__(self, shape_type, x, y, color):
        self.type, self.x, self.y = shape_type, x, y
        self.size, self.color = 100, color

    def draw(self, img):
        h = self.size // 2
        if self.type == 'circle':
            cv2.circle(img, (self.x, self.y), h, self.color, -1)
        elif self.type == 'square':
            cv2.rectangle(img, (self.x - h, self.y - h), (self.x + h, self.y + h), self.color, -1)
        elif self.type == 'rectangle':
            cv2.rectangle(img, (self.x - self.size, self.y - h), (self.x + self.size, self.y + h), self.color, -1)
        elif self.type == 'triangle':
            pts = np.array([[self.x, self.y - h], [self.x - h, self.y + h], [self.x + h, self.y + h]], np.int32)
            cv2.fillPoly(img, [pts], self.color)

    def is_inside(self, px, py):
        h = self.size
        return self.x - h <= px <= self.x + h and self.y - h <= py <= self.y + h


active_shapes = []
selected_shape = None
can_spawn_shape = True

draw_btn = (0, 0, 120, 60)
shape_mode_btn = (120, 0, 260, 60)
quit_btn = (1180, 0, 1280, 60)
colors = [(260, 0, 410, 60, (0, 0, 255)),
          (410, 0, 560, 60, (0, 255, 0)),
          (560, 0, 710, 60, (255, 0, 0))]
shape_btns = [("circle", 720, 0, 820, 60), ("square", 840, 0, 940, 60),
              ("rectangle", 960, 0, 1060, 60), ("triangle", 1080, 0, 1180, 60)]


def fingers_up(hand):
    tips = [4, 8, 12, 16, 20]
    fingers = [hand.landmark[tips[0]].x < hand.landmark[tips[0] - 1].x]
    for i in range(1, 5):
        fingers.append(hand.landmark[tips[i]].y < hand.landmark[tips[i] - 2].y)
    return fingers


cv2.namedWindow("Smart Board", cv2.WINDOW_NORMAL)
cv2.setWindowProperty("Smart Board", cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN)

while True:
    ret, frame = cap.read()
    if not ret:
        break
    frame = cv2.resize(cv2.flip(frame, 1), (1280, 720))
    result = hands.process(cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
    display = board.copy()

    # ---- Top bar ----
    cv2.rectangle(display, (0, 0), (120, 60), (0, 200, 0) if mode == "draw" else (200, 200, 200), -1)
    cv2.putText(display, "DRAW", (20, 40), cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 0), 2)
    cv2.rectangle(display, (120, 0), (260, 60), (0, 200, 0) if mode == "shape" else (200, 200, 200), -1)
    cv2.putText(display, "SHAPES", (130, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.9, (0, 0, 0), 2)
    for (x1, y1, x2, y2, color) in colors:
        cv2.rectangle(display, (x1, y1), (x2, y2), color, -1)
    for (stype, x1, y1, x2, y2) in shape_btns:
        cv2.rectangle(display, (x1, y1), (x2, y2), (220, 220, 220), -1)
        cv2.rectangle(display, (x1, y1), (x2, y2), (0, 0, 0), 2)
        cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
        if stype == "circle":
            cv2.circle(display, (cx, cy), 15, (0, 0, 0), 2)
        elif stype == "square":
            cv2.rectangle(display, (cx - 15, cy - 15), (cx + 15, cy + 15), (0, 0, 0), 2)
        elif stype == "rectangle":
            cv2.rectangle(display, (cx - 20, cy - 10), (cx + 20, cy + 10), (0, 0, 0), 2)
        else:
            pts = np.array([[cx, cy - 15], [cx - 15, cy + 15], [cx + 15, cy + 15]], np.int32)
            cv2.polylines(display, [pts], True, (0, 0, 0), 2)
    cv2.rectangle(display, (1180, 0), (1280, 60), (0, 0, 255), -1)
    cv2.putText(display, "QUIT", (1190, 40), cv2.FONT_HERSHEY_SIMPLEX, 0.7, (255, 255, 255), 2)

    if result.multi_hand_landmarks:
        hand = result.multi_hand_landmarks[0]
        mpDraw.draw_landmarks(display, hand, mpHands.HAND_CONNECTIONS)
        fingers = fingers_up(hand)
        finger_count = fingers.count(True)

        idx_x = int(hand.landmark[8].x * 1280)
        idx_y = int(hand.landmark[8].y * 720)
        smooth_x += (idx_x - smooth_x) // smoothening
        smooth_y += (idx_y - smooth_y) // smoothening
        index_only = fingers[1] and finger_count == 1

        # Button clicks
        if smooth_y < 60 and index_only:
            if quit_btn[0] < smooth_x < quit_btn[2]:
                break
            elif draw_btn[0] < smooth_x < draw_btn[2]:
                mode = "draw"
            elif shape_mode_btn[0] < smooth_x < shape_mode_btn[2]:
                mode = "shape"
            for (x1, y1, x2, y2, color) in colors:
                if x1 < smooth_x < x2:
                    draw_color = color

        # Open hand clears everything
        if finger_count == 5:
            canvas[:] = 0
            active_shapes.clear()

        if mode == "draw":
            if index_only and smooth_y > 60:
                if prev_x == 0:
                    prev_x, prev_y = smooth_x, smooth_y
                cv2.line(canvas, (prev_x, prev_y), (smooth_x, smooth_y), draw_color, brush_thickness)
                prev_x, prev_y = smooth_x, smooth_y
            else:
                prev_x, prev_y = 0, 0

        elif mode == "shape":
            pinch = fingers[0] and fingers[1]
            th_x = int(hand.landmark[4].x * 1280)
            th_y = int(hand.landmark[4].y * 720)

            if smooth_y < 80 and index_only:
                for (stype, x1, y1, x2, y2) in shape_btns:
                    if x1 < smooth_x < x2 and can_spawn_shape:
                        active_shapes.append(DraggableShape(stype, smooth_x, 150, draw_color))
                        can_spawn_shape = False
            else:
                can_spawn_shape = True

            if pinch:
                cx, cy = (idx_x + th_x) // 2, (idx_y + th_y) // 2
                dist = math.hypot(idx_x - th_x, idx_y - th_y)
                if selected_shape is None:
                    for s in reversed(active_shapes):
                        if s.is_inside(cx, cy):
                            selected_shape = s
                            break
                if selected_shape:
                    selected_shape.x, selected_shape.y = cx, cy
                    selected_shape.size = max(30, int(dist))
            else:
                selected_shape = None

    # Merge drawing layer with board
    gray = cv2.cvtColor(canvas, cv2.COLOR_BGR2GRAY)
    _, mask = cv2.threshold(gray, 1, 255, cv2.THRESH_BINARY)
    bg = cv2.bitwise_and(display, display, mask=cv2.bitwise_not(mask))
    fg = cv2.bitwise_and(canvas, canvas, mask=mask)
    final = cv2.add(bg, fg)
    for s in active_shapes:
        s.draw(final)

    cv2.imshow("Smart Board", final)
    if cv2.waitKey(1) & 0xFF == ord('q'):
        break

cap.release()
cv2.destroyAllWindows()

Real-world uses

  • Classroom teaching
  • Online classes and demos
  • Touch-free presentations
  • Learning gesture interfaces

Frequently asked questions

What is a AI Smart Board (Gesture Whiteboard)?

A gesture-controlled smart board that turns your webcam into an interactive whiteboard. Your index finger is the cursor.

What components are needed for the AI Smart Board (Gesture Whiteboard)?

You need: Laptop / Computer (1), Webcam (built-in or external) (1). Software: Python 3.11, OpenCV (opencv-python), MediaPipe, NumPy, PyCharm (recommended).

Is the AI Smart Board (Gesture Whiteboard) project good for beginners?

It is rated advanced and takes about 2–3 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 Smart Board (Gesture Whiteboard)?

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

Do I need any hardware for the AI Smart Board (Gesture Whiteboard)?

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