class Evaluator(object):
    def __init__(self):
        self.pos_System_Markers = {}
        self.neg_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_pos_System_marker_from_clickpoints(self, path, type):
        self.system_db = DataFileExtended(path)
        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 self.gt_db.getImage(filename=m.image.filename) is not None])
        self.pos_System_Markers.update(dict([[t, markers[markers.T[0]==t].T[1:]] for t in set(markers.T[0])]))

    def load_neg_System_marker_from_clickpoints(self, path, type):
        self.system_db = DataFileExtended(path)
        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 self.gt_db.getImage(filename=m.image.filename) is not None])
        self.neg_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)
예제 #2
0
if __name__ == '__main__':
    import my_plot
    import numpy as np
    import clickpoints
    import matplotlib.pyplot as plt
    from PenguTrack.DataFileExtended import DataFileExtended

    # Load Data from Databases
    db = DataFileExtended(
        "/home/birdflight/Desktop/PT_Test_full_n3_r7_A20_filtered.cdb")
    db2 = DataFileExtended("/home/birdflight/Desktop/252_GT_Detections.cdb")
    LogType = db.getMarkerType(name="PT_Detection_Marker")
    ImgType = db.getMarkerType(name="PT_Track_Marker")
    # Positions_Log = np.asarray([[m.x, m.y, m.image.sort_index] for m in db.getMarkers(type=LogType) if not m.text.count("inf")])
    Positions_Img = np.asarray([[m.x, m.y, m.image.sort_index]
                                for m in db.getMarkers(type=ImgType)
                                if m.track.markers.count() > 3])

    # Do Correction for Position Data
    from CameraTransform import CameraTransform
    CT = CameraTransform(14, [17, 9], [4608, 2592],
                         observer_height=31.,
                         angel_to_horizon=(np.pi / 2. - 0.24) * 180 / np.pi)
    orth_x, orth_y, orth_z = CT.transCamToWorld(Positions_Img.T[:2], Z=0.525)

    # Calculate Histogramms
    cx = cy = 2
    times = np.asarray(sorted([i.timestamp for i in db.getImages()]))
    scale = 1. / (cx * cy) / ((times[-1] - times[0]).seconds / 3600.)
    hist, binx, biny = np.histogram2d(orth_x,
                                      orth_y,
예제 #3
0
    while True:
        img, meta = getImage()
        if img is not None:
            print("Got img from cam")
            init_buffer.append(img)
            print(init_buffer[-1].shape)
            print(init_buffer[-1].dtype)
            break

init = np.array(np.median(init_buffer, axis=0))

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

# Load penguin-markers
penguin_type = db_start.getMarkerType(name="Penguin_Size")
try:
    penguin_markers = np.array([[m.x1, m.y1, m.x2, m.y2]
                                for m in db_start.getLines(type="Penguin_Size")
                                ]).T
except ValueError:
    raise ValueError("No markers with name 'Horizon'!")

VB = SiAdViBeSegmentation(horizon_markers,
                          14e-3, [17e-3, 9e-3],
                          penguin_markers,
예제 #4
0
                       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
penguin_type = db.getMarkerType(name="Penguin_Size")
try:
    penguin_markers = np.asarray([[m.x1, m.y1, m.x2, m.y2]
                                  for m in db.getLines(type="Penguin_Size")]).T
except ValueError:
    raise ValueError("No markers with name 'Horizon'!")

# Initialize segmentation with init_image and start updating the first 10 frames.
VB = SiAdViBeSegmentation(horizon_markers,
                          14e-3, [17e-3, 9e-3],