class Evaluator(object):
    def __init__(self):
        self.System_Markers = {}
        self.GT_Markers = {}
        self.gt_db = None
        self.system_db = None

    def load_GT_marker_from_clickpoints(self, path, type):
        self.gt_db = DataFileExtended(path)
        markers = np.asarray([[m.image.sort_index, m.x, m.y] for m in self.gt_db.getMarkers(type=type)])
        self.GT_Markers.update(dict([[t, markers[markers.T[0]==t].T[1:]] for t in set(markers.T[0])]))

    def load_System_marker_from_clickpoints(self, path, type):
        self.system_db = DataFileExtended(path)
        image_filenames = set([img.filename for img in self.gt_db.getImages()]).intersection([img.filename for img in self.system_db.getImages()])
        markers = np.asarray([[self.gt_db.getImage(filename=m.image.filename).sort_index, m.x, m.y] for m in self.system_db.getMarkers(type=type) if m.image.filename in image_filenames])
        self.System_Markers.update(dict([[t, markers[markers.T[0]==t].T[1:]] for t in set(markers.T[0])]))

    def save_marker_to_GT_db(self, markers, path, type):
        # if function is None:
        #     function = lambda x : x
        self.gt_db = DataFileExtended(path)

        with self.gt_db.db.atomic() as transaction:
            self.gt_db.deleteMarkers(type=type)
            for t in markers:
                self.gt_db.setMarkers(image=self.gt_db.getImage(frame=t),x=markers[t].T[0],y=markers[t].T[1], type=type)

    def save_marker_to_System_db(self, markers, path, type):
        if function is None:
            function = lambda x : x
        self.system_db = DataFileExtended(path)

        with self.system_db.db.atomic() as transaction:
            self.system_db.deleteMarkers(type=type)
            for t in markers:
                self.system_db.setMarkers(image=self.system_db.getImage(frame=t),x=markers[t].T[0],y=markers[t].T[1], type=type)
Example #2
0
                                             [min(orth_y),
                                              max(orth_y)]])
    hist *= scale
    hist[hist == 0.] = np.nan

    cx = cy = 6
    hist_img, binx_img, biny_img = np.histogram2d(Positions_Img.T[0],
                                                  Positions_Img.T[1],
                                                  bins=[4608 / cx, 2592 / cy],
                                                  range=[[0, 4608], [0, 2592]])
    hist_img *= scale * cx * cy
    hist_img[hist_img == 0.] = np.nan

    # beauty-corrections for background image
    from skimage.exposure import equalize_adapthist, adjust_gamma
    image = equalize_adapthist(db.getImage(0).data)
    image = adjust_gamma(image, gamma=.5)

    # Plotting
    fig, ax = plt.subplots()
    ax.set_title("Position Heatmap")
    ax.set_xlabel("X-Distance to camera in m")
    ax.set_ylabel("Y-Distance to camera in m")
    ax.imshow(CT.getTopViewOfImage(
        image, [-max(binx), -min(binx),
                min(biny), max(biny)]),
              extent=[-max(binx), -min(binx),
                      min(biny), max(biny)])
    hist_plot = ax.imshow(
        hist.T[::-1, ::-1],
        extent=[-max(binx), -min(binx),
Example #3
0
State_Dist = ss.multivariate_normal(cov=Q)  # Initialize Distributions for Filter
Meas_Dist = ss.multivariate_normal(cov=R)  # Initialize Distributions for Filter

# Initialize Filter
MultiKal = MultiFilter(KalmanFilter, model, np.diag(Q),
                       np.diag(R), meas_dist=Meas_Dist, state_dist=State_Dist)
# MultiKal.LogProbabilityThreshold = -300.
MultiKal.MeasurementProbabilityThreshold = 0.
# MultiKal = MultiFilter(Filter, model)
print("Initialized Tracker")

# Init_Background from Image_Median
# Initialize segmentation with init_image and start updating the first 10 frames.
N = db.getImages().count()
init = np.array(np.median([np.asarray(db.getImage(frame=j).data, dtype=np.int)
                           for j in np.arange(0,10)], axis=0), dtype=np.int)
# VB = ViBeSegmentation(n=2, init_image=init, n_min=2, r=25, phi=1)
VB = ViBeSegmentation(n=3, init_image=init, n_min=3, r=40, phi=1)
print("Debug")
for i in range(10,20):
    mask = VB.detect(db.getImage(frame=i).data, do_neighbours=False)
print("Detecting!")


import matplotlib.pyplot as plt
# for i in range(10306,10311):
#     mask = VB.detect(db.getImage(frame=i).data, do_neighbours=False)
#     fig, ax = plt.subplots(1)
#     # ax.imshow(np.vstack((mask*2**8, db.getImage(frame=i).data)))
#     ax.imshow(np.vstack((mask[:,16000:18000]*2**8, db.getImage(frame=i).data[:,16000:18000])))
Example #4
0
    cov=Q)  # Initialize Distributions for Filter
Meas_Dist = ss.multivariate_normal(
    cov=R)  # Initialize Distributions for Filter

# Initialize Filter
MultiKal = MultiFilter(KalmanFilter,
                       model,
                       np.diag(Q),
                       np.diag(R),
                       meas_dist=Meas_Dist,
                       state_dist=State_Dist)

# Init_Background from Image_Median
N = db.getImages().count()
init = np.asarray(np.median([
    np.asarray(rgb2gray(db.getImage(frame=j).data), dtype=np.int)
    for j in np.random.randint(0, N, 10)
],
                            axis=0),
                  dtype=np.int)

# Load horizon-markers
horizont_type = db.getMarkerType(name="Horizon")
try:
    horizon_markers = np.asarray([[m.x, m.y]
                                  for m in db.getMarkers(type=horizont_type)
                                  ]).T
except ValueError:
    raise ValueError("No markers with name 'Horizon'!")

# Load penguin-markers