Beispiel #1
0
    def crop_by_region(self, frame, region, clip_flow=True):
        thermal = region.subimage(frame.thermal)
        filtered = region.subimage(frame.filtered)
        if frame.flow is not None:
            flow_h = region.subimage(frame.flow_h)
            flow_v = region.subimage(frame.flow_v)
            if clip_flow and not frame.flow_clipped:
                flow_h = get_clipped_flow(flow_h)
                flow_v = get_clipped_flow(flow_v)
        else:
            flow_h = None
            flow_v = None

        mask = region.subimage(frame.mask).copy()
        # make sure only our pixels are included in the mask.
        mask[mask != region.id] = 0
        mask[mask > 0] = 1

        # stack together into a numpy array.
        # by using int16 we lose a little precision on the filtered frames, but not much (only 1 bit)
        if flow_h is not None and flow_v is not None:
            return np.int16(
                np.stack((thermal, filtered, flow_h, flow_v, mask), axis=0))
        else:
            empty = np.zeros(filtered.shape)
            return np.int16(
                np.stack((thermal, filtered, empty, empty, mask), axis=0))
        return frame
Beispiel #2
0
    def add_frame(self, frame):
        self.open()
        frames = self.db["frames"]
        frame_group = frames.create_group(str(frame.frame_number))
        frame_group.attrs["ffc_affected"] = frame.ffc_affected

        height, width = frame.thermal.shape

        chunks = (1, height, width)

        dims = (5, height, width)
        frame_node = frame_group.create_dataset("frame",
                                                dims,
                                                chunks=chunks,
                                                dtype=np.float16)
        scaled_flow = get_clipped_flow(frame.flow)
        frame_val = (
            np.float16(frame.thermal),
            np.float16(frame.filtered),
            np.float16(scaled_flow[:, :, 0]),
            np.float16(scaled_flow[:, :, 1]),
            np.float16(frame.mask),
        )
        frame_node[:, :, :] = frame_val
        if not self.keep_open:
            self.close()
Beispiel #3
0
    def get_flow_split(self, clip_flow=False):
        if self.flow is not None:
            if self.clip_flow and not self.flow_clipped:
                flow_c = get_clipped_flow(self.flow)
                return flow_c[:, :, 0], flow_c[:, :, 1]

            else:
                return self.flow_h, self.flow_v
        return None, None
Beispiel #4
0
    def add_frame(self, frame):
        self.open()
        frames = self.db["frames"]
        frame_group = frames.create_group(str(frame.frame_number))
        frame_group.attrs["ffc_affected"] = frame.ffc_affected
        height, width = frame.thermal.shape

        chunks = (1, height, width)
        channels = []
        dims = 0
        data = []
        if frame.thermal is not None:
            channels.append(TrackChannels.thermal)
            dims += 1
            data.append(np.float32(frame.thermal))
        if frame.filtered is not None:
            channels.append(TrackChannels.filtered)
            dims += 1
            data.append(np.float32(frame.filtered))

        if frame.flow is not None:
            channels.append(TrackChannels.flow)
            scaled_flow = get_clipped_flow(frame.flow)
            scaled_flow_h = np.float32(scaled_flow[:, :, 0])
            scaled_flow_v = np.float32(scaled_flow[:, :, 1])
            data.append(scaled_flow_h)
            data.append(scaled_flow_v)
            dims += 2
        if frame.mask is not None:
            channels.append(TrackChannels.mask)
            data.append(np.float32(frame.mask))
            dims += 1
        frame_group.attrs["channels"] = np.uint8(channels)

        dims = (dims, height, width)
        frame_node = frame_group.create_dataset("frame",
                                                dims,
                                                chunks=chunks,
                                                dtype=np.float32)

        frame_node[:, :, :] = data
        if not self.keep_open:
            self.close()
Beispiel #5
0
 def clip_flow(self):
     if self.flow is not None:
         self.flow = get_clipped_flow(self.flow)
         self.flow_clipped = True
Beispiel #6
0
 def clip_flow(self):
     self.flow = get_clipped_flow(self.flow)
     self.flow_clipped = True