Augmented Maze
unknown
python
4 years ago
1.2 kB
13
Indexable
import cv2 import numpy as np import imutils import cvzone from cvzone.HandTrackingModule import HandDetector lower = np.array([0, 200, 20]) upper = np.array([5, 255, 255]) cap = cv2.VideoCapture(1) cap.set(3, 1280) cap.set(4, 720) detector = HandDetector(detectionCon=0.8) png1 = cv2.imread("PNG/maze_red.png", cv2.IMREAD_UNCHANGED) png2 = cv2.imread("PNG/maze_green.png", cv2.IMREAD_UNCHANGED) while True: success, img = cap.read() img = cv2.flip(img, 1) img = detector.findHands(img) lmList, _ = detector.findPosition(img) img = cvzone.overlayPNG(img, png1, [0, 0]) image = cv2.cvtColor(img, cv2.COLOR_BGR2HSV) mask = cv2.inRange(image, lower, upper) cnts = cv2.findContours(mask, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE) cnts = imutils.grab_contours(cnts) for c in cnts: area = cv2.contourArea(c) if area > 1000: cv2.drawContours(img, [c], -1, (0, 255, 0), 1) if lmList: cursor = lmList[8] if 100 < cursor[0] < 300 and 100 < cursor[1] < 300: img = cvzone.overlayPNG(img, png2, [0, 0]) print("1") cv2.imshow("mask", mask) cv2.imshow("webcam", img) cv2.waitKey(1)
Editor is loading...