Exemplo n.º 1
0
def training_begin(cap, borders):
    seed(5)
    start_time = time.time()
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)  # odbicie lustrzane
    points = define_trace(borders)
    point1 = points.get()
    point2 = points.get()
    points.put([10000, 10000])
    points.put([10000, 10000])
    while (not points.empty()):
        ret, frame = cap.read()
        frame = cv2.flip(frame, 1)  # odbicie lustrzane
        bin = binarize_paddles(frame)
        if point_reched(point1, frame) and point_reched(
                point2, frame) and not points.empty():
            point1 = points.get()
            point2 = points.get()
        if point1[0] < 2000:
            frame = cv2.circle(frame, (point1[0], point1[1]), 2, (0, 255, 255),
                               20)
            frame = cv2.circle(frame, (point2[0], point2[1]), 2, (0, 255, 255),
                               20)

        cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
        cv2.setWindowProperty("window", cv2.WND_PROP_FULLSCREEN,
                              cv2.WINDOW_FULLSCREEN)
        cv2.imshow("window", frame)
        if cv2.waitKey(1) & 0xFF == ord('e'):
            end_time = time.time()
            return count_score(start_time, end_time)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
    end_time = time.time()
    return count_score(start_time, end_time)
Exemplo n.º 2
0
def point_reched(point, frame):
    bin = binarize_paddles(frame)
    reached = False
    for x in range(-3, 3):
        for y in range(-3, 3):
            if bin[point[1] + x, point[0] + y] == 255:
                reached = True
    return reached
Exemplo n.º 3
0
def camera_configured(cap):
    training_should_start = False
    debug = False
    while (not training_should_start):
        ret, rawframe = cap.read()
        rawframe = cv2.flip(rawframe, 1)  # odbicie lustrzane
        bin = binarize_paddles(rawframe)
        paddles_up = detectPaddlesUp(bin)
        if paddles_up:
            face_x, face_y = weighted_center_of_face(rawframe)
            print(face_x, face_y)
            if face_x != -1 and face_y != 0:
                human_core_y = face_y + int(round(0.5 * face_y))
                human_core_x = face_x
                height = len(rawframe)
                width = len(rawframe[0])
                scale_x = int(1.6 * face_y)
                left_point_x = max(human_core_x - scale_x, 0) + 5
                left_point_y = 5
                right_point_x = min(human_core_x + scale_x, width - 1) - 5
                right_point_y = height - 6
                if debug:
                    rawframe = cv2.circle(rawframe, (face_x, face_y), 15,
                                          (255, 0, 0), 2)
                    rawframe = cv2.circle(rawframe,
                                          (human_core_x, human_core_y), 15,
                                          (255, 255, 0), 2)
                    rawframe = cv2.rectangle(rawframe,
                                             (left_point_x, left_point_y),
                                             (right_point_x, right_point_y),
                                             (255, 0, 0), 2)
                    cv2.imshow("window", rawframe)
                    cv2.waitKey(0)
                cv2.destroyAllWindows()
                return [
                    int(round(left_point_x)),
                    int(round(left_point_y)),
                    int(round(right_point_x)),
                    int(round(right_point_y))
                ]

        rawframe = cv2.putText(
            rawframe,
            "Prosze podniesc paletki do gornej krawedzi ekranu", (45, 50),
            cv2.FONT_HERSHEY_COMPLEX,
            0.6, (255, 0, 255),
            1,
            lineType=cv2.LINE_AA)

        cv2.namedWindow("window", cv2.WND_PROP_FULLSCREEN)
        cv2.setWindowProperty("window", cv2.WND_PROP_FULLSCREEN,
                              cv2.WINDOW_FULLSCREEN)
        cv2.imshow("window", rawframe)
        # cv2.imshow("binary", bin)
        if cv2.waitKey(1) & 0xFF == ord('e'):
            return [100, 100, 400, 400]
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
Exemplo n.º 4
0
def hello():
    cap = cv2.VideoCapture(0)
    seed(2)
    cnt = 0
    ret, rawframe = cap.read()
    frame = cv2.flip(rawframe, 1)  #odbicie lustrzane
    x_offset = 5
    y_offset = 65
    cv2.imshow("frame", frame)
    width = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    height = cap.get(cv2.CAP_PROP_FRAME_WIDTH)
    x = randint(x_offset, width - x_offset)
    y = randint(y_offset, height - y_offset)
    while (True):
        #cv2.waitKey(1000)
        ret, rawframe = cap.read()
        frame = cv2.flip(rawframe, 1)  #odbicie lustrzane
        pixel = frame[x, y, :]
        # Get R, G, B values (This are int from 0 to 255)
        red = pixel[2]
        green = pixel[1]
        blue = pixel[0]
        print(red, green, blue)
        if red > 200:
            x = randint(x_offset, width - x_offset)
            y = randint(y_offset, height - y_offset)
            print("wchodzę", x, y)
        frame = show_point(frame, x, y)
        cv2.namedWindow("frame", cv2.WND_PROP_FULLSCREEN)
        cv2.setWindowProperty("frame", cv2.WND_PROP_FULLSCREEN,
                              cv2.WINDOW_FULLSCREEN)
        cv2.imshow("frame", binarize_paddles(frame))
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break
        cnt += 1
    cap.release()
    cv2.destroyAllWindows()
Exemplo n.º 5
0
import os
import cv2
import time
from paddles import binarize_paddles

directory = '/home/michask/talus/zdjecia/'

for filename in os.listdir(directory):
    if filename.endswith(".jpg"):
        print(filename)
        img = cv2.imread(r'zdjecia/' + filename)
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        cv2.imshow('a', img)
        cv2.imshow('H', binarize_paddles(img))
        cv2.waitKey(1000)
Exemplo n.º 6
0
import os
import cv2
import time
from paddles import binarize_paddles
from kalibracja import detectPaddlesUp
from detect_face import weighted_center_of_face
directory = 'zdjecia_kuchnia/'
import math
for filename in os.listdir(directory):
    if filename.endswith(".bmp"):
        print(filename)
        img = cv2.imread(r'zdjecia_kuchnia/' + filename)
        hsv = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
        bin = binarize_paddles(img)

        is_paddles_up = detectPaddlesUp(bin)
        print(is_paddles_up)
        if is_paddles_up:
            face_x, face_y = weighted_center_of_face(img)
            print(face_x, face_y)
            if face_x != -1 and face_y != 0:
                human_core_y = face_y + int(round(0.5 * face_y))
                human_core_x = face_x
                height = len(img)
                width = len(img[0])
                scale_x = int(1.6 * face_y)
                left_point_x = max(human_core_x - scale_x, 0)
                left_point_y = 0
                right_point_x = min(human_core_x + scale_x, width - 1)
                right_point_y = height - 1
                img = cv2.circle(img, (face_x, face_y), 15, (255, 0, 0), 2)