Exemplo n.º 1
0
def game_over(score):
    game_over_screen = draw.get_game_over_surface(score)
    ladderboard_screen = draw.get_ladderboard_surface(score)
    draw.draw_surface(screen, game_over_screen, 0, 0)
    draw.draw_surface(screen, ladderboard_screen, 12, 2)
    draw.draw_rectangle(screen, 1, 1, 10, 20)
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    return True
        clock.tick(30)
Exemplo n.º 2
0
def pause():
    pause_screen = draw.get_pause_surface()
    instructions_surface = draw.get_instruction_surface()
    draw.draw_surface(screen, pause_screen, 0, 0)
    draw.draw_surface(screen, instructions_surface, 12, 2)
    draw.draw_rectangle(screen, 1, 1, 10, 20)
    pygame.display.update()
    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_p:
                    return True
        clock.tick(30)
Exemplo n.º 3
0
    def draw(self, frame, mask, points, output, scale=10, pref=''):
        out = draw.draw_rectangle(frame, mask, draw.cyan)
        avr_eps = self.get_avr_eps()
        for i in range(N):
            t0 = time.time()

            color = draw.green
            if self.eps[i] < avr_eps:
                color = draw.red
            if self.eps[i] == -1:
                color = draw.cyan
            pt1 = points[i][0]

            pt2 = pt1 + scale * np.array([self.x[i], self.y[i]])
            out = draw.draw_point(out, pt1, 1, draw.blue)
            out = draw.draw_point(out, pt2, 1, draw.blue)
            out = draw.draw_arrow(out, pt1, pt2, color)

            tk = time.time()
            times.append(tk - t0)
            T = (sum(times) / len(times)) * (N - i)
            t_min = np.int(T // 60)
            t_sec = T % 60
            print(pref + 'drawing: {} / {}\t {} min {:.2f} sec'.format(
                i, N, t_min, t_sec))
        cv2.imwrite(output, out)
Exemplo n.º 4
0
def main_menu():
    colors = sett.COLORS[2:]
    current_color = colors.pop()
    time = 0
    level = 1
    instructions_surface = draw.get_instruction_surface()
    menu_screen = draw.get_menu_surface(level, current_color)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                return False, level
            if event.type == 26:
                time += 100
                if time == 1000:
                    current_color = colors.pop()
                    if colors == []:
                        colors = sett.COLORS[2:]
                    menu_screen = draw.get_menu_surface(level, current_color)
                    time = 0
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_SPACE:
                    return True, level
                if event.key == pygame.K_w:
                    if level < 10:
                        level += 1
                        menu_screen = draw.get_menu_surface(
                            level, current_color)
                if event.key == pygame.K_s:
                    if level > 1:
                        level -= 1
                        menu_screen = draw.get_menu_surface(
                            level, current_color)

        draw.draw_surface(screen, menu_screen, 0, 0)
        draw.draw_surface(screen, instructions_surface, 12, 2)
        draw.draw_rectangle(screen, 1, 1, 10, 20)
        pygame.display.update()
        clock.tick(30)
Exemplo n.º 5
0
def draw_grid(img, grid):
    '''
        Draw grid on image by special variable 'grid'.
    '''
    rows = len(grid)
    cols = len(grid[0])
    out = img.copy()
    for i in range(rows):
        for j in range(cols):
            pt1 = grid[i][j][0]
            pt2 = grid[i][j][1]
            out = draw.draw_rectangle(out, [pt1, pt2], color=draw.cyan)
    return out
Exemplo n.º 6
0
def main():

    running = True
    main_menu_active = True
    pygame.time.set_timer(26, 100)

    while running:
        if main_menu_active:
            running, level = main_menu()
            tetrion = Tetrion()
            block = blocks.get_random_block()
            next_block = blocks.get_random_block()
            prepare_next = False
            score = 0
            time = 0
            move_time = 0
            move_time_limit = 1000 - (level - 1) * 100
            try_move_down = False
            try_move_left = False
            try_move_right = False
            try_rotate = False
            drop = False
            main_menu_active = False

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                running = False
            if event.type == 26:
                time += 100
                move_time += 100
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_a:
                    try_move_left = True
                elif event.key == pygame.K_d:
                    try_move_right = True
                elif event.key == pygame.K_s:
                    try_move_down = True
                elif event.key == pygame.K_p:
                    running = pause()
                elif event.key == pygame.K_r:
                    try_rotate = True
                elif event.key == pygame.K_SPACE:
                    drop = True

        if move_time == move_time_limit:
            try_move_down = True

        if try_move_right:
            if block.check_if_on_edge('right'):
                x, y = block.get_coords()
                part = tetrion.get_part(x + 1, y)
                if block.can_move(part):
                    block.move_right()
                    print(block.get_coords())
            try_move_right = False

        if try_move_left:
            if block.check_if_on_edge('left'):
                x, y = block.get_coords()
                part = tetrion.get_part(x - 1, y)
                if block.can_move(part):
                    block.move_left()
                    print(block.get_coords())
            try_move_left = False

        if drop:
            while not prepare_next:
                if block.check_if_on_edge('bottom'):
                    x, y = block.get_coords()
                    part = tetrion.get_part(x, y + 1)
                    if block.can_move(part):
                        block.move_down()
                    else:
                        prepare_next = True
                else:
                    prepare_next = True
            drop = False
            move_time = 0

        if try_move_down:
            if block.check_if_on_edge('bottom'):
                x, y = block.get_coords()
                part = tetrion.get_part(x, y + 1)
                if block.can_move(part):
                    block.move_down()
                else:
                    prepare_next = True
            else:
                prepare_next = True
            try_move_down = False
            move_time = 0

        if try_rotate:
            x, y = block.get_coords()
            part = tetrion.get_part(x, y)
            if block.can_rotate(part):
                block.rotate()
            try_rotate = False

        if prepare_next:
            tetrion.update_board(block.state, block.y, block.x)
            score += tetrion.remove_rows()**2 * 1000
            score += 100
            block = next_block
            next_block = blocks.get_random_block()
            prepare_next = False

        score_surface = draw.get_text_surface(f'SCORE: {score}')
        time_surface = draw.get_text_surface(f'TIME: {time // 1000}')
        level_surface = draw.get_text_surface(f'LEVEL: {level}')
        next_block_surface = draw.get_text_surface('next block:')

        draw.fill_surface(screen, sett.COLORS[1])
        draw.draw_squares(tetrion.board, screen)
        draw.draw_squares(block.state, screen, block.x, block.y)
        draw.draw_squares(next_block.state, screen, 17, 5)
        draw.draw_rectangle(screen, 1, 1, 10, 20)
        draw.draw_surface(screen, next_block_surface, 12, 4)
        draw.draw_surface(screen, score_surface, 12, 8)
        draw.draw_surface(screen, level_surface, 12, 9)
        draw.draw_surface(screen, time_surface, 12, 10)

        if tetrion.is_lost():
            running = game_over(score)
            main_menu_active = True

        pygame.display.update()
        clock.tick(30)
Exemplo n.º 7
0
def action(method):
    video = 'test1.mp4'
    
    cam = cv2.VideoCapture(video)
    lengh = np.int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
    print(lengh)
    _, frame1 = cam.read()
    y, x, z = frame1.shape
    x1, y1, x2, y2 = x // 3, 3*y//5, 2*x//3, 0.94 * y // 1
    p1 = np.array([x1, y1])
    p2 = np.array([x2, y2])
    mask = [p1, p2]
    
    times = deque(maxlen=lengh)
    #times = deque(maxlen=lengh)
    
    for itt in range(lengh):
        t0 = time.time()
        _, frame2 = cam.read()
        if not _:
            break
        frame2 = draw.draw_rectangle(frame2, mask, color=draw.cyan)
        area1 = sf.get_box(frame1, mask)
        area2 = sf.get_box(frame2, mask)
        y_, x_, z_ = area1.shape
        print(y_, x_)
        points1 = np.zeros((100, 2), dtype = np.float)
        yy0 = 0.02 * y_ // 1
        dy = (y_ - 2 * yy0) // 10
        xx0 = 0.02 * x_ // 1
        dx = (x_ - 2*xx0) // 10
        for i in range(10):
            for j in range(10):
                points1[i][0] = xx0 + i * dx
                points1[i][1] = yy0 + j * dy
               
        points1, points2 = pai.find_opt_flow(area1, area2, method=method)
        N = len(points1)
        N_ = len(points2)
        print(' N is {} and {}'.format(N, N_))
        out = frame2.copy()
        norms = deque(maxlen=N)
        for i in range(N):
            norms.append(np.linalg.norm(points1[i] - points2[i]))
        mid_norm = sum(norms) / N
        for i in range(N):
            p1 = points1[i] + mask[0]
            p2 = points2[i] + mask[0]
            if np.linalg.norm(p1 - p2) < mid_norm:
                out = draw.draw_point(out, p1, radius=3)
                out = draw.draw_point(out, p2, radius=3)
                out = draw.draw_arrow(out, p1, p2)
        out = draw.draw_text(img=out, pt=(3*x//4, 80), text='points: {}'.format(N),color=draw.blue, font_scale=1, line_type=2)
        out = draw.draw_text(img=out, pt=(0, 80), text='{}'.format(itt),color=draw.blue, font_scale=1, line_type=2)
    #    out = draw.draw_text(out, (3*x//4, 80),  text_properties)
#        small = cv2.resize(out, (0,0), fx=0.7, fy=0.7) 
#        cv2.imshow('frame', small)
        cv2.imwrite('out/{}.jpg'.format(itt), out)
#        #cv2.imshow('area', area)
#        
#        k = cv2.waitKey(20)
        frame1 = frame2
        
        
        tk = time.time()
        times.append(tk - t0)
        T = sum(times) / len(times)
        T = T * (lengh - itt)
        t_min = int(T // 60)
        t_sec = T % 60
        print('{} min {:.02f} sec'.format(t_min, t_sec))
        
    cv2.destroyAllWindows()
Exemplo n.º 8
0
 def animate(i):
     x1 = x1_list[i]
     x2 = x2_list[i]
     draw.draw_rectangle(wx[0], wx[1], wy[0], wy[1])
     draw.draw_circle(x1[0], x1[1], r1, c1, 0.7)
     draw.draw_circle(x2[0], x2[1], r2, c2, 0.7)
Exemplo n.º 9
0
Arquivo: Snake.py Projeto: SDRU/had
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0,len(snake_position)-1):
        draw_rectangle(PIECE*snake_position[i][0],PIECE*snake_position[i][1],PIECE*(snake_position[i][0]+1),PIECE*(snake_position[i][1]+1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE*snake_position[-1][0],PIECE*snake_position[-1][1],PIECE*(snake_position[-1][0]+1),PIECE*(snake_position[-1][1]+1))
    
    ### Food
    draw_rectangle(PIECE*food_position[0],PIECE*food_position[1],PIECE*(food_position[0]+1),PIECE*(food_position[1]+1))
    ### Score
    draw_text(str(N-20),PIECE*SCORE_POSITION[0],PIECE*SCORE_POSITION[1],'left', PIECE*FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu   
    draw_rectangle(0, 0, PIECE*WALL_THICKNESS, PIECE*HEIGHT)
    draw_rectangle(0, 0, PIECE*WIDTH, PIECE*WALL_THICKNESS)
    draw_rectangle(PIECE*WIDTH-PIECE*WALL_THICKNESS,0,PIECE*WIDTH,PIECE*HEIGHT)
    draw_rectangle(0,PIECE*HEIGHT-PIECE*WALL_THICKNESS,PIECE*WIDTH,PIECE*HEIGHT)

    if QUIT_SIGNAL==1:
        draw_text('GAME OVER',PIECE*WIDTH//2-PIECE*FONT_SIZE*4,PIECE*HEIGHT//2-PIECE*FONT_SIZE//2,'left', PIECE*FONT_SIZE)
Exemplo n.º 10
0
 def animate(i):
     x1 = x1_list[i]
     x2 = x2_list[i]
     draw.draw_rectangle(wx[0], wx[1], wy[0], wy[1])
     draw.draw_circle(x1[0], x1[1], r1, c1, 0.7)
     draw.draw_circle(x2[0], x2[1], r2, c2, 0.7)
Exemplo n.º 11
0
def make(video='C://Users//moshe.f//Desktop//TEST//calibration//23.mp4',
         m=100, k=100, nf=50, min_number_of_points=5, 
         out_data=None, out_pic=None):
    
    cam = cv2.VideoCapture(video)
    lengh = np.int(cam.get(cv2.CAP_PROP_FRAME_COUNT))
    print(lengh)
    lk_params = dict(winSize=(15, 15), maxLevel=2, criteria=(cv2.TERM_CRITERIA_EPS | cv2.TERM_CRITERIA_COUNT, 10, 0.3))
    
    _, frame1 = cam.read()
    y, x, z = frame1.shape
    
    # рабочая область
    x1, y1, x2, y2 = x // 5, y // 5, 4 * x // 5, 0.92 * y // 1
    p1 = np.array([x1, y1])
    p2 = np.array([x2, y2])
    mask = [p1, p2]
    
    # ___________________
    times = deque(maxlen=lengh)
    area1 = sf.get_box(frame1, mask)
    y_, x_, z_ = area1.shape
    
    # greed points
    points1 = np.zeros((m * k, 1, 2), dtype = np.float32)
    yy0 = 0.02 * y_ // 1
    dy = (y_ - 2 * yy0) // m
    xx0 = 0.02 * x_ // 1
    dx = (x_ - 2 * xx0) // k
    for i in range(m*k):
        points1[i][0][0] = xx0 + dx * (i % k)
        points1[i][0][1] = yy0 + dy * (i // k)
    #______________________
    
    sumX = np.zeros(m*k, dtype=np.float32)
    sumY = np.zeros(m*k, dtype=np.float32)
    sumX2 = np.zeros(m*k, dtype=np.float32)
    sumY2 = np.zeros(m*k, dtype=np.float32)
    Num = np.zeros(m*k, dtype=np.int)
    
    avr_x = np.zeros(m*k, dtype=np.float32)
    avr_y = np.zeros(m*k, dtype=np.float32)
    std_x2 = np.zeros(m*k, dtype=np.float32)
    std_y2 = np.zeros(m*k, dtype=np.float32)
    eps = np.zeros(m*k, dtype=np.float32)
    
    avr_eps = 0
    counter = 0
    # data collection
    for itt in range(nf):
        t0 = time.time()
        _, frame2 = cam.read()
        area1 = sf.get_box(frame1, mask)
        area2 = sf.get_box(frame2, mask)
        points2, st, err = cv2.calcOpticalFlowPyrLK(cv2.cvtColor(area1, cv2.COLOR_BGR2GRAY), cv2.cvtColor(area2, cv2.COLOR_BGR2GRAY), points1, None, **lk_params)     
        for i in range(m*k):
            if st[i] == 1:
                addX = points2[i][0][0] - points1[i][0][0]
                addY = points2[i][0][1] - points1[i][0][1]
                Num[i] += 1
                sumX[i] += addX
                sumY[i] += addY
                sumX2[i] += addX ** 2
                sumY2[i] += addY ** 2
        frame1 = frame2
        tk = time.time()
        times.append(tk - t0)
        if itt % (nf // 10) == 0:
            T = (sum(times) / len(times)) * (nf - itt)
            t_min = int(T // 60)
            t_sec = T % 60
            print('{} | {} min {:.02f} sec'.format(itt, t_min, t_sec))        
    times.clear()
    
    # data analysise
    for i in range(m*k):
        t0 = time.time()
        if Num[i] < min_number_of_points:
            eps[i] = -1
        else:
            avr_x[i] = sumX[i] / Num[i]
            avr_y[i] = sumY[i] / Num[i]
            std_x2[i] = sumX2[i] / Num[i] - avr_x[i] ** 2
            std_y2[i] = sumY2[i] / Num[i] - avr_y[i] ** 2
            
            eps[i] = np.sqrt(std_x2[i] + std_y2[i])
            if np.isnan(eps[i]):
                sys.exit('Arg sqrt in eps is bad in step {}!!! arg = {}'.format(i, std_x2[i] + std_y2[i]))
        tk = time.time()
        times.append(tk - t0)
        if i % 10 == 0:
            T = (sum(times) / len(times)) * (m*k - i)
            t_min = np.int(T // 60)
            t_sec = T % 60
            print('calculate {} | {} min {} sec'.format(i, t_min, t_sec))
    times.clear()
    
    with open('trace/eps.txt', 'w') as f:
        for i in range(m*k):
            f.write('{}\n'.format(eps[i]))
            
    # average eps
    avr_eps = avr(eps, -1)
    #        print(' >>> {} <<< '.format(i))
    print('avr_eps = {}'.format(avr_eps))
    color = draw.black
    frame2 = draw.draw_rectangle(frame2, mask, color=draw.cyan)
    #frame2 = sf.get_box(frame2, mask)
    if out_pic is not None:
        for i in range(m*k):
            #print(i, m*k)
            t0 = time.time()
            th = 2
            if eps[i] > avr_eps:
                color = draw.red
            elif eps[i] == -1:
                color = draw.purple
            else:
                color = draw.green
            if np.isnan(eps[i]):
                th = 3
                color = draw.black
            pt1 = points1[i][0] + mask[0]
            #dpt = np.array([0, 0])
            #if not np.isnan(avr_x[i]) and not np.isnan(avr_y[i]):
            dpt = np.array([avr_x[i], avr_y[i]])
            pt2 = pt1 + dpt
            frame2 = draw.draw_point(frame2, pt1, radius=1, color=draw.blue)
            frame2 = draw.draw_point(frame2, pt2, radius=1, color=draw.blue)
            frame2 = draw.draw_arrow(frame2, pt2, pt1, color, thickness=th)
            #frame2 = draw.draw_text(frame2, pt1, text='({}|{})'.format(i // k, i % k), font_scale=0.25, line_type=1)
            tk = time.time()
            times.append(tk - t0)
            if i % (m*k // 10) == 0:
                T = (sum(times) / len(times)) * (m*k - i)
                t_min = np.int(T // 60)
                t_sec = T % 60
                print(' drawing: {} | {} min {} sec'.format(i, t_min, t_sec))        
        cv2.imwrite(out_pic, frame2)
    if out_data is not None:
        with open(out_data, 'w') as f:
            for i in range(m*k):
                line = '{}|{}|{}|{}|{}\n'.format(i // k, i % k, avr_x[i], avr_y[i], eps[i])
                f.write(line)
            
    #    out = frame2.copy()
    #    for i in range(N):
    #         pt1 = pts1[i] + mask[0]
    #         pt2 = pts2[i] + mask[0]
    #         out = draw.draw_point(out, pt1, radius=3)
    #         out = draw.draw_point(out, pt2, radius=3)
    #         out = draw.draw_arrow(out, pt1, pt2)
    #    cv2.imwrite('out/{}.jpg'.format(itt), out)
    print('done')
    return avr_x, avr_y, eps
Exemplo n.º 12
0
            out = f2.copy()
            r_i_sq = sf.get_mahalanobis_distance_sq(pt, m, K_inv)
            r_i = np.sqrt(r_i_sq)
            # drawing point, arrow and text
            text = dict(text='r = ' + str(r_i), font_scale=1, line_type=2, 
                                                            color=draw.blue)
            if r_i_sq > r_sq:
                text['color'] = draw.red
            out = draw.draw_text(out, (0, 50), **text)
            text.pop('text')
            text.pop('color')
            out = draw.draw_text(out, (0, 80), text='x = ' + str(pt[0]), 
                                          color=draw.black, **text)
            out = draw.draw_text(out, (0, 110), 
                        text='y = ' + str(pt[1]), color=draw.black, **text)
            out = draw.draw_rectangle(out, mask, color=draw.cyan)
            out = draw.draw_arrow(out, m, pt)
            out = draw.draw_point(out, pt, radius=3, thickness=6, 
                                                          color=draw.red)
            #  mahalanobis ellipses
            out = draw.draw_mahalanobis_ellipse(out, r, m, K, 
                    color=draw.blue, draw_center_pt = True, 
                    draw_axes = True, draw_extremum_pts = True)
           
            out = draw.draw_mahalanobis_ellipse(out, 3*r, m, K, 
                    color=draw.red, draw_center_pt = False, 
                    draw_axes = False, draw_extremum_pts = False)           

            p = path + '{:05d}.jpg'.format(i)
            cv2.imwrite(p, out)
            
Exemplo n.º 13
0
def drawing():
    gl.glClear(gl.GL_COLOR_BUFFER_BIT)  # smaz obsah okna (vybarvi na cerno)
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu

    ### Plots the snake body
    for i in range(0, len(snake_position) - 1):
        draw_rectangle(PIECE * snake_position[i][0],
                       PIECE * snake_position[i][1],
                       PIECE * (snake_position[i][0] + 1),
                       PIECE * (snake_position[i][1] + 1))

    ### Snake head in blue
    gl.glColor3f(0, 0, 1)
    draw_rectangle(PIECE * snake_position[-1][0],
                   PIECE * snake_position[-1][1],
                   PIECE * (snake_position[-1][0] + 1),
                   PIECE * (snake_position[-1][1] + 1))

    ### Food
    draw_rectangle(PIECE * food_position[0], PIECE * food_position[1],
                   PIECE * (food_position[0] + 1),
                   PIECE * (food_position[1] + 1))
    ### Score
    draw_text(str(N - 20), PIECE * SCORE_POSITION[0],
              PIECE * SCORE_POSITION[1], 'left', PIECE * FONT_SIZE)
    ### Walls
    gl.glColor3f(0, 1, 0)  # nastav barvu kresleni na zelenu
    draw_rectangle(0, 0, PIECE * WALL_THICKNESS, PIECE * HEIGHT)
    draw_rectangle(0, 0, PIECE * WIDTH, PIECE * WALL_THICKNESS)
    draw_rectangle(PIECE * WIDTH - PIECE * WALL_THICKNESS, 0, PIECE * WIDTH,
                   PIECE * HEIGHT)
    draw_rectangle(0, PIECE * HEIGHT - PIECE * WALL_THICKNESS, PIECE * WIDTH,
                   PIECE * HEIGHT)

    if QUIT_SIGNAL == 1:
        draw_text('GAME OVER', PIECE * WIDTH // 2 - PIECE * FONT_SIZE * 4,
                  PIECE * HEIGHT // 2 - PIECE * FONT_SIZE // 2, 'left',
                  PIECE * FONT_SIZE)
Exemplo n.º 14
0
def do():
    video_adr = 'input/calibration_video.mp4'
    cam = cv2.VideoCapture(video_adr)
    _, img = cam.read()
    y, x, z = img.shape
    x1, y1, x2, y2 = x // 5, 0.45 * y // 1, 4 * x // 5, 0.85 * y // 1
    p1_rec = np.array([x1, y1])
    p2_rec = np.array([x2, y2])
    m_start = np.array([x // 2 - 50, y * 0.4], np.float32)
    #mask = [p1_rec, p2_rec]
    L = 10_000
    LINES = 250
    intensity_threshould = 25
    rows = 10
    cols = 20
    weight = 0.1
    N = rows * cols
    arrow_size_factor = 10

    max_cos = np.cos(20 * np.pi / 180)
    LINES = 20
    img2 = img
    grid = cf.get_grid(p1_rec, p2_rec, rows, cols)
    for itt_frame in range(4):
        img1 = img2
        img2 = cam.read()[1]
        out = draw.draw_rectangle(img2, [
            m_start + np.array([-5, -5], np.float32),
            m_start + np.array([5, 5], np.float32)
        ],
                                  color=draw.cyan)
        results = []
        time_per_frame = 0
        for du_m in range(-5, 5 + 1):
            for dv_m in range(-5, 5 + 1):
                T = 0
                m_temp = m_start + np.array([du_m, dv_m], np.float32)
                points, count = mn.get_points(550, 30 * np.pi / 180, LINES,
                                              m_temp)

                F_x = collections.deque()
                F_y = collections.deque()
                F_z = collections.deque()
                F_f = collections.deque()
                F_o = collections.deque()
                vector_result = []
                #                residuals = collections.deque()
                #                POINTS = collections.deque()
                print('START {} ITERATION'.format(itt_frame))
                if not _:
                    break
                print(' START points generation:', end=' ')
                t0 = time.time()
                pts_filtered = mn.intensity_threshould_filter_of_points(
                    img1, points, intensity_threshould)
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                print(' START optical flow:', end=' ')
                t0 = time.time()
                mod_pts = mn.modification_points(pts_filtered)
                pts1, pts2 = pai.find_opt_flow_lk_with_points(
                    img1, img2, mod_pts)
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                print(' START buildinig of vectors:', end=' ')
                t0 = time.time()
                for i in range(len(pts1)):
                    pt1 = pts1[i]
                    pt2_o = pts2[i]
                    #                    POINTS.append(pts1[i])
                    u = pts1[i][0] - m_temp[0]
                    v = pts1[i][1] - m_temp[1]
                    du_x, dv_x = vector_flow_rotation_x(u, v, L)
                    du_y, dv_y = vector_flow_rotation_y(u, v, L)
                    du_z, dv_z = vector_flow_rotation_z(u, v)
                    du_f, dv_f = vector_flow_forward(u, v, L)

                    F_x.append([du_x, dv_x])
                    F_y.append([du_y, dv_y])
                    F_z.append([du_z, dv_z])
                    F_f.append([du_f, dv_f])
                    F_o.append(pts2[i] - pts1[i])
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                print(' START calculations:', end=' ')
                t0 = time.time()
                M = np.zeros((4, 4), np.float32)
                V = np.zeros(4, np.float32)

                for i in range(len(F_f)):
                    M[0][0] += F_x[i][0]**2 + F_x[i][1]**2
                    M[0][1] += F_x[i][0] * F_y[i][0] + F_x[i][1] * F_y[i][1]
                    M[0][2] += F_x[i][0] * F_z[i][0] + F_x[i][1] * F_z[i][1]
                    M[0][3] += F_x[i][0] * F_f[i][0] + F_x[i][1] * F_f[i][1]
                    M[1][1] += F_y[i][0]**2 + F_y[i][1]**2
                    M[1][2] += F_y[i][0] * F_z[i][0] + F_y[i][1] * F_z[i][1]
                    M[1][3] += F_y[i][0] * F_f[i][0] + F_y[i][1] * F_f[i][1]
                    M[2][2] += F_z[i][0]**2 + F_z[i][1]**2
                    M[2][3] += F_z[i][0] * F_f[i][0] + F_z[i][1] * F_f[i][1]
                    M[3][3] += F_f[i][0]**2 + F_f[i][1]**2

                    V[0] += F_o[i][0] * F_x[i][0] + F_o[i][1] * F_x[i][1]
                    V[1] += F_o[i][0] * F_y[i][0] + F_o[i][1] * F_y[i][1]
                    V[2] += F_o[i][0] * F_z[i][0] + F_o[i][1] * F_z[i][1]
                    V[3] += F_o[i][0] * F_f[i][0] + F_o[i][1] * F_f[i][1]
                    for i in range(4):
                        for j in range(i):
                            M[i][j] = M[j][i]
                A_x, A_y, A_z, B = np.linalg.solve(M, V)
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                print(' START drawing:', end=' ')
                t0 = time.time()
                summ = 0
                counter = 0
                for i in range(len(pts1)):
                    pt = pts1[i]
                    vvx = A_x * np.array(F_x[i], np.float32)
                    vvy = A_y * np.array(F_y[i], np.float32)
                    vvz = A_z * np.array(F_z[i], np.float32)
                    vvf = B * np.array(F_f[i], np.float32)
                    pt2_v = vvx + vvy + vvz + vvf
                    pt2_o = F_o[i]
                    r = pt2_o - pt2_v
                    norm_r = np.linalg.norm(r)
                    vector_result.append(norm_r)
                    summ += norm_r
                    counter += 1


#                    with open('out/rotations/{}_{}/data.txt'.format(du_m, dv_m), 'a') as f:
#                        f.write('{}  /  {}  =  {} | summ = {}\n'.format(summ, counter, summ / counter, summ))
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                t0 = time.time()
                print(' Modification of points of infinity:', end=' ')
                tk = time.time()
                print(tk - t0)
                T += tk - t0
                print('TIME: {} min {:02.02f} sec'.format(
                    int((T) // 60), (T) % 60))
                results.append([summ, m_temp])
                #                with open('out/rotations/frame{}.txt'.format(itt_frame), 'a') as file:
                #                    file.write('{}|{}|{}|{}\n'.format(du_m, dv_m, summ, counter))

                time_per_frame += T
                vector_result.sort()
                LEN = int(0.9 * len(vector_result))
                counter = 0
                summ = 0
                for i in range(LEN):
                    counter += 1
                    summ += vector_result[i]
                with open('out/rotations/frame{}.txt'.format(itt_frame),
                          'a') as file:
                    file.write('{}|{}|{}|{}\n'.format(du_m, dv_m, summ,
                                                      counter))

        r = min(results)
        print('END FRAME ANALISYS: {} min {:02.04f} sec'.format(
            int(time_per_frame // 60), time_per_frame % 60))
        out = draw.draw_arrow(out, m_start, r[1])
        cv2.imwrite('out/rotations/{}.jpg'.format(itt_frame), out)
        m_start = (1 - weight) * m_start + weight * r[1]