예제 #1
0
nossy_mask = cv2.imread("assets/Dog_Filter_assets/dog_filter_nose_mask.png")

detect = dlib.get_frontal_face_detector()
predictor = dlib.shape_predictor("shape_predictor_68_face_landmarks.dat")

shape = None
x = 0
y = 0
w = 0
h = 0
(le1, le2) = face_utils.FACIAL_LANDMARKS_IDXS["left_eyebrow"]
(re1, re2) = face_utils.FACIAL_LANDMARKS_IDXS["right_eyebrow"]
(n1, n2) = (31, 36)

while True:
    output = live()
    output = imutils.resize(output, width=500)
    gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY)
    rects = detect(gray, 1)
    for (i, rect) in enumerate(rects):
        shape = predictor(gray, rect)
        shape = face_utils.shape_to_np(shape)
        (x, y, w, h) = face_utils.rect_to_bb(rect)

        left = shape[le1:le2]
        right = shape[re1:re2]
        nose = shape[n1:n2]

        dy = right[3][1] - right[1][1]
        dx = right[3][0] - right[1][0]
        re_angle = calc_angle(dx, dy)
args = vars(ap.parse_args())

# load our serialized model from disk
print("[INFO] loading model...")
net = cv2.dnn.readNetFromCaffe(args["prototxt"], args["model"])

# initialize the video stream and allow the cammera sensor to warmup
print("[INFO] starting video stream...")
# vs = VideoStream(src=0).start()
# time.sleep(2.0)

# loop over the frames from the video stream
while True:
	# grab the frame from the threaded video stream and resize it
	# to have a maximum width of 400 pixels
	frame = live()
	frame = imutils.resize(frame, width=400)

	# grab the frame dimensions and convert it to a blob
	(h, w) = frame.shape[:2]
	blob = cv2.dnn.blobFromImage(cv2.resize(frame, (300, 300)), 1.0,
		(300, 300), (104.0, 177.0, 123.0))

	# pass the blob through the network and obtain the detections and
	# predictions
	net.setInput(blob)
	detections = net.forward()

	# loop over the detections
	for i in range(0, detections.shape[2]):
		# extract the confidence (i.e., probability) associated with the
예제 #3
0
from live_cam import live

fourcc = cv2.VideoWriter_fourcc(*'XVID')
res = cv2.VideoWriter('Results/output.avi', fourcc, 20.0, (640, 480))

cv2.namedWindow("Sort", cv2.WINDOW_NORMAL)

# img = cv2.imread("Test/"+sys.argv[1])


def midpoint(ptA, ptB):
    return ((ptA[0] + ptB[0]) * 0.5, (ptA[1] + ptB[1]) * 0.5)


while True:
    img = live()
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    blur = cv2.GaussianBlur(gray, (5, 5), 0)
    canny = cv2.Canny(gray, 100, 220)
    canny = cv2.dilate(canny, None, iterations=1)
    canny = cv2.erode(canny, None, iterations=1)

    # thresh = cv2.threshold(gray, 110, 255,cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]

    cnts = cv2.findContours(canny.copy(), cv2.RETR_EXTERNAL,
                            cv2.CHAIN_APPROX_SIMPLE)
    cnts = imutils.grab_contours(cnts)
    out = img.copy()

    print(len(cnts))
예제 #4
0
import time
import cv2
import numpy as np
import imutils
from live_cam import live

# time.sleep(2)
count = 0
background = 0
for i in range(60):
	background  =live()
background = np.flip(background,axis=1)

while True:
	img = live()
	count+=1
	img = np.flip(img,axis=1)
	hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
	lower_red = np.array([0, 125, 50])
	upper_red = np.array([10, 255,255])
	mask1 = cv2.inRange(hsv, lower_red, upper_red)

	lower_red = np.array([170, 120, 70])
	upper_red = np.array([180, 255, 255])
	mask2 = cv2.inRange(hsv, lower_red, upper_red)

	mask1 = mask1 + mask2

	mask1 = cv2.morphologyEx(mask1, cv2.MORPH_OPEN, np.ones((3, 3), np.uint8))
	mask1 = cv2.morphologyEx(mask1, cv2.MORPH_DILATE, np.ones((3, 3), np.uint8))