예제 #1
0
def moving_average():

    avg = []
    lst_time = []
    datafile = 'E:/Users/Matt/Documents/Programming Projects/ME-499/HW2/image_data.csv'
    dir = 'E:/Users/Matt/Documents/Programming Projects/ME-499/HW2/images/'
    if os.path.isfile(dir + datafile) == True:
        raise OSError("File already exists, please rename file")
    else:
        pass
    while time.time() < 1527607800:
        with open(datafile, 'w', newline='') as f:
            now = time.time()

            filename = 'MU_{}.jpg'.format(now)
            mu_live = webcam.Webcam().grab_image()
            mu_live.save(dir + filename, 'JPEG')

            print("image grabbed at {}".format(now))
            intensity = mu_live.getdata()
            pxlavg = []
            for i in list(intensity):
                pxlavg.append(np.mean(i))

            avg.append(np.mean(pxlavg))
            lst_time.append(now)

            csvRow = [now, np.mean(pxlavg)]
            wr = csv.writer(f)
            wr.writerow(csvRow)
            time.sleep(1)

    avg = []
    lst_time = []
    with open(datafile) as file:
        for row in csv.reader(file):
            lst_time.append(float(row[0]))
            avg.append(float(row[1]))

    t0 = lst_time[0]
    lst_time[:] = [(x - t0) / 60 for x in lst_time]

    b, a = signal.butter(5, 0.025)
    zi = signal.lfilter_zi(b, a)
    z, _ = signal.lfilter(b, a, avg, zi=zi * avg[0])
    z2, _ = signal.lfilter(b, a, z, zi=zi * z[0])
    y = signal.filtfilt(b, a, avg)

    plt.plot(lst_time, avg, 'k', lst_time, y, 'r--')
    plt.xlabel('Minutes')
    plt.ylabel('Average Intensity')
    plt.legend(('Average Image Intensity', 'Smoothed Average Image Intensity'),
               loc='best')
    plt.title('Average Image Intensity from 5:45 PM to 8:30 AM PST, May 29th')
    plt.grid()
    plt.show()
예제 #2
0
파일: hw2_alt.py 프로젝트: mahoep/ME-499
    def common_color():
        image = webcam.Webcam().grab_image()
        pixels = mu_live.getcolors()

        most_frequent_pixel = pixels[0]

        # for count, colour in pixels:
        #     if count > most_frequent_pixel[0]:
        #         most_frequent_pixel = (count, colour)

        return most_frequent_pixel
def main():
    pygame.init()
    game = Game()
    cam = webcam.Webcam()
    cam.thread_webcam()

    while True:
        frame = cam.get_currentFrame()
        frame = cv2.resize(frame, (window_width, window_height),
                           cv2.INTER_CUBIC)
        #  connect webcam

        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = np.rot90(frame)
        frame = pygame.surfarray.make_surface(frame)
        display_surf.blit(frame, (0, 0))

        Draw_Elements()
        game.update()
        pygame.display.update()
        fps_clock.tick(fps)
예제 #4
0
def Init():
    pygame.init()
    cam = webcam.Webcam()
    cam.thread_webcam()
    pygame.mixer.music.load("song\\opening-song.mp3")
    pygame.mixer.music.play(1)

    while True:
        frame = cam.get_currentFrame()
        frame = cv2.resize(frame, (window_width, window_height))
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = np.rot90(frame)
        frame = pygame.surfarray.make_surface(frame)

        display_surf.blit(frame, (0, 0))
        Start()  # start menu

        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                mouse = pygame.mouse.get_pos()
                if 350 + 500 > mouse[0] > 500 and 800 > mouse[1] > 500:
                    pygame.mixer.music.stop()
                    main()
        pygame.display.update()
예제 #5
0
def main():
    game = Game()
    cam = webcam.Webcam()
    cam.thread_webcam()
    SONG_END = pygame.USEREVENT + 1
    pygame.mixer.music.set_endevent(SONG_END)

    while True:
        frame = cam.get_currentFrame()
        frame = cv2.resize(frame, (window_width, window_height),
                           cv2.INTER_CUBIC)

        # connect webcam
        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = np.rot90(frame)
        frame = pygame.surfarray.make_surface(frame)
        display_surf.blit(frame, (0, 0))
        Draw_Elements()

        if game.upLeft.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.upLeft.isMissed = False
        elif game.upRight.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.upRight.isMissed = False
        elif game.downLeft.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.downLeft.isMissed = False
        elif game.downRight.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.downRight.isMissed = False

        if cam.get_pos(buttonUpLeft[1], buttonUpLeft[0]):
            # upLeft
            if len(game.upLeft.points) != 0:
                game.upLeft.isMissed = False
                currentPoint_x = game.upLeft.points[0][0]
                currentPoint_y = game.upLeft.points[0][1]
                button_x = buttonUpLeft[0]
                button_y = buttonUpLeft[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x,
                                    button_y)
                if currentPoint_x >= 10 and currentPoint_y >= 10:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonUpLeft)
                    game.upLeft.points.remove([currentPoint_x, currentPoint_y])

        if cam.get_pos(buttonUpRight[1], buttonUpRight[0]):
            if len(game.upRight.points) != 0:
                game.upRight.isMissed = False
                currentPoint_x = game.upRight.points[0][0]
                currentPoint_y = game.upRight.points[0][1]
                button_x = buttonUpRight[0]
                button_y = buttonUpRight[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x,
                                    button_y)
                if currentPoint_x <= window_width - 74 and currentPoint_y >= 10:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonUpRight)
                    game.upRight.points.remove(
                        [currentPoint_x, currentPoint_y])

        if cam.get_pos(buttonDownLeft[1], buttonDownLeft[0]):
            if len(game.downLeft.points) != 0:
                game.downLeft.isMissed = False
                currentPoint_x = game.downLeft.points[0][0]
                currentPoint_y = game.downLeft.points[0][1]
                button_x = buttonDownLeft[0]
                button_y = buttonDownLeft[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x,
                                    button_y)
                if currentPoint_x >= 10 and currentPoint_y <= window_height - 74:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonDownLeft)
                    game.downLeft.points.remove(
                        [currentPoint_x, currentPoint_y])

        if cam.get_pos(buttonDownRight[1], buttonDownRight[0]):
            if len(game.downRight.points) != 0:
                game.downRight.isMissed = False
                currentPoint_x = game.downRight.points[0][0]
                currentPoint_y = game.downRight.points[0][1]
                button_x = buttonDownRight[0]
                button_y = buttonDownRight[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x,
                                    button_y)
                if currentPoint_x <= window_width - 74 and currentPoint_y <= window_height - 74:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonDownRight)
                    game.downRight.points.remove(
                        [currentPoint_x, currentPoint_y])
        for event in pygame.event.get():
            if event.type == SONG_END:
                Result(game.perfect, game.great, game.bad, game.miss,
                       game.score.score)
        game.update()
        pygame.display.update()
        fps_clock.tick(fps)
예제 #6
0
파일: hw2_alt.py 프로젝트: mahoep/ME-499
 def __init__(self):
     self.image = webcam.Webcam().grab_image()
     self.imdata = self.image.getdata()
예제 #7
0
def main():
    pygame.init()
    game = Game()
    cam = webcam.Webcam()
    cam.thread_webcam()

    while True:
        frame = cam.get_currentFrame()
        frame = cv2.resize(frame, (window_width, window_height),
                           cv2.INTER_CUBIC)

        # connect webcam

        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = np.rot90(frame)
        frame = pygame.surfarray.make_surface(frame)
        display_surf.blit(frame, (0, 0))
        Draw_Elements()

        if game.upLeft.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.upLeft.isMissed = False
        elif game.upRight.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.upRight.isMissed = False
        elif game.downLeft.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.downLeft.isMissed = False
        elif game.downRight.isMissed:
            game.performance = "MISS"
            game.miss += 1
            game.downRight.isMissed = False

        for event in pygame.event.get():
            if event.type == pygame.KEYDOWN:
                if event.key == K_q:
                    # upLeft
                    # Scoring(upLeft, buttonUpLeft) ko dc??
                    if len(game.upLeft.points) != 0:
                        game.upLeft.isMissed = False
                        currentPoint_x = game.upLeft.points[0][0]
                        currentPoint_y = game.upLeft.points[0][1]
                        button_x = buttonUpLeft[0]
                        button_y = buttonUpLeft[1]
                        distance = Distance(currentPoint_x, currentPoint_y,
                                            button_x, button_y)
                        if currentPoint_x >= 10 and currentPoint_y >= 10:  # inside
                            if distance <= d / 3:
                                game.score.score += 200
                                game.performance = "PERFECT"
                                game.perfect += 1
                            elif distance <= 2 * d / 3:
                                game.score.score += 100
                                game.performance = "GREAT"
                                game.great += 1
                            else:
                                game.performance = "BAD"
                                game.bad += 1
                            display_surf.blit(upLeftActive, buttonUpLeft)
                            display_surf.blit(glow, buttonUpLeft)
                            game.upLeft.points.remove(
                                [currentPoint_x, currentPoint_y])

                        else:
                            game.performance = "MISS"
                            game.miss += 1

                if event.key == K_p:
                    # upRight
                    if len(game.upRight.points) != 0:
                        game.upRight.isMissed = False
                        currentPoint_x = game.upRight.points[0][0]
                        currentPoint_y = game.upRight.points[0][1]
                        button_x = buttonUpRight[0]
                        button_y = buttonUpRight[1]
                        distance = Distance(currentPoint_x, currentPoint_y,
                                            button_x, button_y)
                        if currentPoint_x <= window_width - 74 and currentPoint_y >= 10:  # inside
                            if distance <= d / 3:
                                game.score.score += 200
                                game.performance = "PERFECT"
                            elif distance <= 2 * d / 3:
                                game.score.score += 100
                                game.performance = "GREAT"
                            else:
                                game.performance = "BAD"
                            display_surf.blit(upRightActive, buttonUpRight)
                            display_surf.blit(glow, buttonUpRight)
                            game.upRight.points.remove(
                                [currentPoint_x, currentPoint_y])

                        else:
                            game.performance = "MISS"

                if event.key == K_z:
                    # downLeft
                    if len(game.downLeft.points) != 0:
                        game.downLeft.isMissed = False
                        currentPoint_x = game.downLeft.points[0][0]
                        currentPoint_y = game.downLeft.points[0][1]
                        button_x = buttonDownLeft[0]
                        button_y = buttonDownLeft[1]
                        distance = Distance(currentPoint_x, currentPoint_y,
                                            button_x, button_y)
                        if currentPoint_x >= 10 and currentPoint_y <= window_height - 74:  # inside
                            if distance <= d / 3:
                                game.score.score += 200
                                game.performance = "PERFECT"
                            elif distance <= 2 * d / 3:
                                game.score.score += 100
                                game.performance = "GREAT"
                            else:
                                game.performance = "BAD"
                            display_surf.blit(downLeftActive, buttonDownLeft)
                            display_surf.blit(glow, buttonDownLeft)
                            game.downLeft.points.remove(
                                [currentPoint_x, currentPoint_y])

                        else:
                            game.performance = "MISS"
                if event.key == K_m:
                    # downRight
                    if len(game.downRight.points) != 0:
                        game.downRight.isMissed = False
                        currentPoint_x = game.downRight.points[0][0]
                        currentPoint_y = game.downRight.points[0][1]
                        button_x = buttonDownRight[0]
                        button_y = buttonDownRight[1]
                        distance = Distance(currentPoint_x, currentPoint_y,
                                            button_x, button_y)
                        if currentPoint_x <= window_width - 74 and currentPoint_y <= window_height - 74:  # inside
                            if distance <= d / 3:
                                game.score.score += 200
                                game.performance = "PERFECT"
                            elif distance <= 2 * d / 3:
                                game.score.score += 100
                                game.performance = "GREAT"
                            else:
                                game.performance = "BAD"
                            display_surf.blit(downRightActive, buttonDownRight)
                            display_surf.blit(glow, buttonDownRight)
                            game.downRight.points.remove(
                                [currentPoint_x, currentPoint_y])

                        else:
                            game.performance = "MISS"
        game.update()
        try:
            if keyboard.is_pressed('a'):
                break
            else:
                pass
        except:
            break
        # if game.upLeft.spawnTime == 1000: ?????
        #     break
        pygame.display.update()
        fps_clock.tick(fps)
예제 #8
0
 def __init__(self):
     self.distracted_tracker = np.zeros(8)
     self.inattn_counter = 0
     self.wb = webcam.Webcam()
     self.punish_mode = 'Off'
예제 #9
0
import webcam
import cv2

test = webcam.Webcam()
test.thread_webcam()
while True:
    frame = test.get_currentFrame()
    # cv2.imshow("aa",frame)
    # cv2.waitKey(30)
    #cv2.rectangle(frame, (10, 786 - 74), (10 + 64, 786 - 74 + 64), (0, 0, 0), 3)
    cv2.imshow("a", frame)
    cv2.waitKey(30)
    print(test.get_pos(10, 10))
예제 #10
0
def main():
    pygame.init()
    game = Game()
    cam = webcam.Webcam()
    cam.thread_webcam()
    cap = cv2.VideoCapture(0)

    # def Scoring(pos, pos_button):
    #     if len(game.pos.points) != 0:
    #         currentPoint_x = game.pos.points[0][0]
    #         currentPoint_y = game.pos.points[0][1]
    #         button_x = pos_button[0]
    #         button_y = pos_button[1]
    #         distance = Distance(currentPoint_x, currentPoint_y, button_x, button_y)
    #         if currentPoint_x >= 10 and currentPoint_y >= 10:  # inside
    #             if distance <= d / 3:
    #                 game.score.score += 200
    #             elif distance <= 2 * d / 3:
    #                 game.score.score += 100
    #             else:
    #                 game.score.score += 50
    #             display_surf.blit(glow, pos_button)
    #             game.pos.points.remove([currentPoint_x, currentPoint_y])

    while True:
        frame = cap.read()[1]
        # frame = cv2.flip(frame, 1)
        frame = cv2.resize(frame, (window_width, window_height), cv2.INTER_CUBIC)


        # convert to bin
        hsvImage = cv2.cvtColor(frame, cv2.COLOR_RGB2HSV)
        binImage = cv2.inRange(hsvImage, lower, higher)
        binImage = cv2.flip(binImage, 1)

        # connect webcam

        frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
        frame = np.rot90(frame)
        frame = pygame.surfarray.make_surface(frame)
        display_surf.blit(frame, (0, 0))
        Draw_Elements()

        # scoring
        # upLeft
        if Scan(binImage, buttonUpLeft[0], buttonUpLeft[1]):
            if len(game.upLeft.points) != 0:
                game.upLeft.isMissed = False
                currentPoint_x = game.upLeft.points[0][0]
                currentPoint_y = game.upLeft.points[0][1]
                button_x = buttonUpLeft[0]
                button_y = buttonUpLeft[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x, button_y)
                if currentPoint_x >= 10 and currentPoint_y >= 10:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonUpLeft)
                    game.upLeft.points.remove([currentPoint_x, currentPoint_y])

                else:
                    game.performance = "MISS"
                    game.miss += 1

        # upRight
        if Scan(binImage, buttonUpRight[0], buttonUpRight[1]):
            if len(game.upRight.points) != 0:
                game.upRight.isMissed = False
                currentPoint_x = game.upRight.points[0][0]
                currentPoint_y = game.upRight.points[0][1]
                button_x = buttonUpRight[0]
                button_y = buttonUpRight[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x, button_y)
                if currentPoint_x <= window_width - 74 and currentPoint_y >= 10:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonUpRight)
                    game.upRight.points.remove([currentPoint_x, currentPoint_y])

                else:
                    game.performance = "MISS"
                    game.miss += 1

        # downLeft
        if Scan(binImage, buttonDownLeft[0], buttonDownLeft[1]):
            if len(game.downLeft.points) != 0:
                game.downLeft.isMissed = False
                currentPoint_x = game.downLeft.points[0][0]
                currentPoint_y = game.downLeft.points[0][1]
                button_x = buttonDownLeft[0]
                button_y = buttonDownLeft[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x, button_y)
                if currentPoint_x >= 10 and currentPoint_y <= window_height - 74:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonDownLeft)
                    game.downLeft.points.remove([currentPoint_x, currentPoint_y])

                else:
                    game.performance = "MISS"
                    game.miss += 1

        # downRight
        if Scan(binImage, buttonDownRight[0], buttonDownRight[1]):
            if len(game.downRight.points) != 0:
                game.downRight.isMissed = False
                currentPoint_x = game.downRight.points[0][0]
                currentPoint_y = game.downRight.points[0][1]
                button_x = buttonDownRight[0]
                button_y = buttonDownRight[1]
                distance = Distance(currentPoint_x, currentPoint_y, button_x, button_y)
                if currentPoint_x <= window_width - 74 and currentPoint_y <= window_height - 74:  # inside
                    if distance <= d / 3:
                        game.score.score += 200
                        game.performance = "PERFECT"
                        game.perfect += 1
                    elif distance <= 2 * d / 3:
                        game.score.score += 100
                        game.performance = "GREAT"
                        game.great += 1
                    else:
                        game.performance = "BAD"
                        game.bad += 1
                    display_surf.blit(glow, buttonDownRight)
                    game.downRight.points.remove([currentPoint_x, currentPoint_y])

                else:
                    game.performance = "MISS"
                    game.miss += 1
        game.update()
        pygame.display.update()
        fps_clock.tick(fps)