import cv2 import random import numpy as np import imgaug as ia from preprocess.flag import flag import imgaug.augmenters as iaa from preprocess.labelgen import label_generator f = flag() size = f.target_size def augment(image, bbox): x = random.randint(-100, 100) y = random.randint(-100, 100) aug = iaa.Sequential([iaa.Multiply(random.uniform(0.15, 1.5)), iaa.AdditiveGaussianNoise(random.uniform(0, 0.1) * 255), iaa.Affine(translate_px={"x": x, "y": y}, scale=random.uniform(0.35, 1.5), rotate=random.uniform(-180, 180), cval=(0, 255))]) bbs = ia.BoundingBoxesOnImage([ ia.BoundingBox(x1=bbox[0], y1=bbox[1], x2=bbox[2], y2=bbox[3])], shape=image.shape) aug = aug.to_deterministic() image_aug = aug.augment_image(image) bbs_aug = aug.augment_bounding_boxes([bbs])[0] b = bbs_aug.bounding_boxes bbs_aug = [b[0].x1, b[0].y1, b[0].x2, b[0].y2] bbs_aug = np.asarray(bbs_aug)
import cv2 import numpy as np from solo import hand_model from preprocess.flag import flag model = hand_model() model.load_weights('weights/solo.h5') grid_size = flag().grid_size cam = cv2.VideoCapture(0) while True: ret, ori_image = cam.read() height, width, _ = ori_image.shape if ret is False: break image = cv2.resize(ori_image, (416, 416)) img = image / 255.0 img = np.expand_dims(img, axis=0) grid_output = model.predict(img) grid_output = grid_output[0] output = (grid_output > 0.6).astype(int) """ Finding bounding box """ prediction = np.where(output > 0.5) row_wise = prediction[0] col_wise = prediction[1] try: x1 = min(col_wise) * grid_size y1 = min(row_wise) * grid_size