import cv2 import time from yolo.detector import YOLO from fingertip import Fingertips hand = YOLO(weights='weights/yolo.h5', threshold=0.5) fingertip = Fingertips(model='vgg', weights='weights/vgg16.h5') cam = cv2.VideoCapture(0) while True: tic = time.time() ret, image = cam.read() if ret is False: print('camera not found! :( ') break tl, br = hand.detect(image) if tl or br is not None: xmin, ymin, xmax, ymax = int(tl[0]), int(tl[1]), int(br[0]), int(br[1]) cropped_image = image[ymin:ymax, xmin:xmax] cols, rows, _ = cropped_image.shape # heights, width, channel resized_image = cv2.resize(cropped_image, (128, 128)) position = fingertip.classify(image=resized_image) for i in range(0, len(position), 2): position[i] = (position[i]) * rows position[i + 1] = (position[i + 1]) * cols for i in range(0, len(position), 2):
import cv2 import numpy as np from yolo.detector import YOLO from compare.net.dtfd import dtfd hand = YOLO('../../weights/yolo.h5', threshold=0.3) fingertip = dtfd() fingertip.load_weights('../../compare/weights/dtfd.h5') def classify(img): """ Fingertip detection """ global fingertip img = img / 255.0 img = np.expand_dims(img, axis=0) keys = fingertip.predict(img) keys = keys[0] return keys user = 2 transformation = 'translation' f_count = 0 cam = cv2.VideoCapture('../../data/' + transformation + '/' + str(user) + '.mp4') f = open('../../data/' + transformation + '/' + transformation + '_' + str(user) + '.txt', 'r') lines = f.readlines() f.close() xt = [] yt = []
import os import cv2 import time import numpy as np import imgaug as ia from imgaug import augmenters as iaa from yolo.detector import YOLO from compare.net.dtfd import dtfd hand = YOLO(weights='../weights/yolo.h5', threshold=0.5) fingertip = dtfd() fingertip.load_weights('weights/dtfd.h5') def classify(img): """ Fingertip detection """ global fingertip img = img / 255.0 img = np.expand_dims(img, axis=0) keys = fingertip.predict(img) keys = keys[0] return keys def flip_horizontal(img, keys): """ Flipping """ aug = iaa.Sequential([iaa.Fliplr(1.0)]) seq_det = aug.to_deterministic() keys = ia.KeypointsOnImage([ ia.Keypoint(x=keys[0], y=keys[1]), ia.Keypoint(x=keys[2], y=keys[3]),