def main(): if canvas_instruction_validator(): cleaned_data = canvas_instruction_validator() canvas = initialize_canvas(cleaned_data) draw_into_output(canvas) all_instructions = get_instructions() if all_instructions: for instruction in all_instructions: instruction = instruction.split() if pre_validate_instruction(instruction): command, parameters = pre_validate_instruction(instruction) if command == 'L' and line_validator( cleaned_data, parameters): clean_parameters = line_validator( cleaned_data, parameters) add_line(canvas, clean_parameters) draw_into_output(canvas) elif command == 'R' and rectangle_validator( cleaned_data, parameters): clean_parameters = rectangle_validator( cleaned_data, parameters) coordinates = get_coordinates_to_draw_rect_with_addline_function( clean_parameters) add_rectangle(canvas, coordinates) draw_into_output(canvas) elif command == 'B' and flood_fill_validator( cleaned_data, parameters): pos_x, pos_y, color = flood_fill_validator( cleaned_data, parameters) to_flood_fill(canvas, pos_x, pos_y, color) draw_into_output(canvas)
import cv2 import numpy as np import time cap = cv2.VideoCapture(0) # To use a video file as input # cap = cv2.VideoCapture('filename.mp4') while True: timer = cv2.getTickCount() _, img = cap.read() img = cv2.flip(img, 1) faces, eyes = functions.true_eyes_and_faces(img) mouths = functions.detect_mouths(img) noses = functions.detect_noses(img) functions.add_rectangle(img, faces) true_mouths, faces_mouths_noses = functions.best_mouth_to_face( mouths, faces) functions.add_rectangle(img, true_mouths, (0, 255, 0)) # groen true_noses = functions.best_nose_to_face(noses, faces, faces_mouths_noses) functions.add_rectangle(img, true_noses, (0, 255, 255)) # geel functions.mask_due_haar(img, faces_mouths_noses) fps = int(cv2.getTickFrequency() / (cv2.getTickCount() - timer)) cv2.putText(img, str(fps), (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0)) cv2.imshow('img', img) # Stop if escape key is pressed k = cv2.waitKey(30) & 0xff if k == 27: break
import numpy as np import time cap = cv2.VideoCapture(0) # To use a video file as input # cap = cv2.VideoCapture('filename.mp4') while True: _, img = cap.read() img = cv2.flip(img, 1) img1 = img.copy() faces1 = functions.detect_faces(img) faces, eyes = functions.true_eyes_and_faces(img) mouths = functions.detect_mouths(img) noses = functions.detect_noses(img) functions.add_rectangle(img1, mouths) functions.add_rectangle(img, faces) # blauw functions.add_rectangle(img, eyes, (0, 0, 255)) # rood true_mouths, faces_mouths_noses = functions.best_mouth_to_face(mouths, faces) true_noses = functions.best_nose_to_face(noses, faces, faces_mouths_noses) functions.add_rectangle(img, true_noses, (0, 255, 255)) # geel functions.add_rectangle(img, true_mouths, (0, 255, 0)) # groen pos = [] for face in faces: middle_pos = functions.middle_position(face) pos.append(middle_pos) for (x, y) in pos: cv2.circle(img, (x, y), 5, (0, 0, 255), -1) cv2.imshow('img', img) cv2.imshow('img1', img1) # Stop if escape key is pressed
while True: # Read the frame _, img = cap.read() img = cv2.flip(img, 1) img1 = img.copy() faces = functions.detect_faces(img) eyes = functions.detect_eyes(img) true_eyes, true_faces = functions.true_eyes_and_faces(img) functions.add_counter(img1, faces) functions.add_counter(img1, eyes, (100, 50), (0, 255, 0)) functions.add_counter(img, true_faces) functions.add_counter(img, true_eyes, (100, 50), (0, 255, 0)) functions.add_rectangle(img1, faces) functions.add_rectangle(img1, eyes, (0, 255, 0)) functions.add_rectangle(img, true_faces) functions.add_rectangle(img, true_eyes, (0, 255, 0)) # Display cv2.imshow('origineel', img1) cv2.imshow('echte gezichten', img) # Stop if escape key is pressed k = cv2.waitKey(30) & 0xff if k == 27: break # Release the VideoCapture object cap.release()
import functions import cv2 import numpy as np import time cap = cv2.VideoCapture(0) # To use a video file as input # cap = cv2.VideoCapture('filename.mp4') while True: timer = cv2.getTickCount() _, img = cap.read() img = functions.resize_image(img, 100) img = cv2.flip(img, 1) faces1 = functions.detect_faces(img) faces, eyes = functions.true_eyes_and_faces(img) functions.add_rectangle(img, faces) functions.mask_due_color(img, faces) fps = int(cv2.getTickFrequency() / (cv2.getTickCount() - timer)) cv2.putText(img, str(fps), (50, 50), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 0, 0)) img = functions.resize_image(img, 100) cv2.imshow('img', img) # Stop if escape key is pressed k = cv2.waitKey(30) & 0xff if k == 27: break # Release the VideoCapture object cap.release()