Air Canvas Project
Air Canvas Project
import cv2
import numpy as np
import mediapipe as mp
from collections import deque
bpoints = [deque(maxlen=1024)]
gpoints = [deque(maxlen=1024)]
rpoints = [deque(maxlen=1024)]
ypoints = [deque(maxlen=1024)]
colors = [(255, 0, 0), (0, 255, 0), (0, 0, 255), (0, 255, 255)]
colorIndex = 0
In summary, this code block sets up the initial graphical user interface (GUI) for a
painting application. It creates a canvas with color choices and labels for the user to
interact with, and the canvas is displayed in a resizable window named 'Paint'.
# initialize mediapipe
mpHands = mp.solutions.hands
hands = mpHands.Hands(max_num_hands=1, min_detection_confidence=0.7)
mpDraw = mp.solutions.drawing_utils
Overall, these lines of code set up the MediaPipe library for hand tracking, configure
the detection parameters, and prepare drawing utilities to visualize the hand
landmarks and connections on the images or frames you capture.
x, y, c = frame.shape
landmarks.append([lmx, lmy])
paintWindow[67:,:,:] = 255
elif 160 <= center[0] <= 255:
colorIndex = 0 # Blue
elif 275 <= center[0] <= 370:
colorIndex = 1 # Green
elif 390 <= center[0] <= 485:
colorIndex = 2 # Red
elif 505 <= center[0] <= 600:
colorIndex = 3 # Yellow
else :
if colorIndex == 0:
bpoints[blue_index].appendleft(center)
elif colorIndex == 1:
gpoints[green_index].appendleft(center)
elif colorIndex == 2:
rpoints[red_index].appendleft(center)
elif colorIndex == 3:
ypoints[yellow_index].appendleft(center)
# Append the next deques when nothing is detected to avois messing up
else:
bpoints.append(deque(maxlen=512))
blue_index += 1
gpoints.append(deque(maxlen=512))
green_index += 1
rpoints.append(deque(maxlen=512))
red_index += 1
ypoints.append(deque(maxlen=512))
yellow_index += 1
cv2.imshow("Output", frame)
cv2.imshow("Paint", paintWindow)
if cv2.waitKey(1) == ord('q'):
break