# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


import sys
import os
import Tkinter
import numpy as np
import cPickle as pickle
import time
import imgaug as ia
from lib import replay_memory
from lib import util
from PIL import Image, ImageTk
    def previous_state(self, autosave):
        print("Switching to previous state...")
        self.current_state_idx -= EVERY_NTH
        assert self.current_state_idx >= self.memory.id_min, "Start of memory reached (%d vs %d)" % (self.current_state_idx, self.memory.id_min)
        self.switch_to_state(self.current_state_idx, autosave=autosave)

    def next_state(self, autosave):
        print("Switching to next state...")
        self.current_state_idx += EVERY_NTH
        assert self.current_state_idx <= self.memory.id_max, "End of memory reached (%d vs %d)" % (self.current_state_idx, self.memory.id_max)
        self.switch_to_state(self.current_state_idx, autosave=autosave)

    def switch_to_state(self, idx, autosave):
        print("Switching to state %d (autosave=%s)..." % (idx, str(autosave)))
        self.current_state = self.memory.get_state_by_id(idx)
        assert self.current_state is not None
        self.current_state_idx = idx

        if autosave:
            if self.last_autosave+1 % AUTOSAVE_EVERY == 0:
                self.save_annotations()
                self.last_autosave = 0
            else:
                self.last_autosave += 1

        key = str(self.current_state_idx)
        if key in self.annotations:
            self.current_annotation = self.annotations[key]
        else:
            img = self.current_state.screenshot_rs

# Path: lib/replay_memory.py
# class ReplayMemory(object):
#     def __init__(self, filepath, max_size, max_size_tolerance):
#     def create_instance_supervised(val=False):
#     def create_instance_reinforced(val=False):
#     def create_instance_by_config(cfg_name):
#     def add_states(self, states, shrink=True):
#     def add_state(self, state, commit=True, shrink=True):
#     def update_state(self, idx, state, commit=True):
#     def get_state_by_id(self, idx):
#     def get_states_by_ids(self, ids):
#     def get_random_states(self, count):
#     def get_states_range(self, pos_start, length):
#     def get_random_state_chain(self, length, from_pos_range=None):
#     def get_random_state_chain_timediff(self, length, max_timediff_ms=500, depth=50):
#     def update_caches(self):
#     def is_above_tolerance(self):
#     def shrink_to_max_size(self, force=False):
#     def commit(self):
#     def close(self):
#     def connect(self):
# 
# Path: lib/util.py
# def template_match(needle, haystack):
# def compress_to_jpg(img):
# def compress_img(img, method):
# def decompress_img(img_compressed):
# def draw_image(img, other_img, x, y, copy=True, raise_if_oob=False):
# def draw_point(img, y, x, size=5, color=[255, 0, 0], alpha=1.0, copy=True):
# def draw_line(img, y1, x1, y2, x2, color=[0, 255, 0], alpha=1.0, thickness=1, clip_result=True, copy=True):
# def draw_direction_circle(img, y, x, r_inner, r_outer, angle_start, angle_end, color_border=[0, 255, 0], color_fill=[0, 200, 0], alpha=1.0):
# def draw_text(img, y, x, text, color=[0, 255, 0], size=25):
# def to_variable(inputs, volatile=False, requires_grad=True):
# def to_variables(inputs, volatile=False, requires_grad=True):
# def to_cuda(inputs, gpu=Config.GPU):
# def to_numpy(var):
# def draw_heatmap_overlay(img, heatmap, alpha=0.5):
# def create_2d_gaussian_old(size, fwhm=3, center=None):
# def create_2d_gaussian(size, sigma):
# FONT_CACHE = dict()


# Path: annotate/annotate_street_boundaries.py
import sys
import os
import Tkinter
import numpy as np
import cPickle as pickle
import time
import imgaug as ia
from lib import replay_memory
from lib import util
from PIL import Image, ImageTk

    def previous_state(self, autosave):
        print("Switching to previous state...")
        self.current_state_idx -= EVERY_NTH
        assert self.current_state_idx >= self.memory.id_min, "Start of memory reached (%d vs %d)" % (self.current_state_idx, self.memory.id_min)
        self.switch_to_state(self.current_state_idx, autosave=autosave)

    def next_state(self, autosave):
        print("Switching to next state...")
        self.current_state_idx += EVERY_NTH
        assert self.current_state_idx <= self.memory.id_max, "End of memory reached (%d vs %d)" % (self.current_state_idx, self.memory.id_max)
        self.switch_to_state(self.current_state_idx, autosave=autosave)

    def switch_to_state(self, idx, autosave):
        print("Switching to state %d (autosave=%s)..." % (idx, str(autosave)))
        self.current_state = self.memory.get_state_by_id(idx)
        assert self.current_state is not None
        self.current_state_idx = idx

        if autosave:
            if self.last_autosave+1 % AUTOSAVE_EVERY == 0:
                self.save_annotations()
                self.last_autosave = 0
            else:
                self.last_autosave += 1

        key = str(self.current_state_idx)
        if key in self.annotations:
            self.current_annotation = self.annotations[key]
        else:
            img = self.current_state.screenshot_rs

            grid = np.zeros((img.shape[0], img.shape[1]), dtype=np.float32)