Exemple #1
0
 def decode(self, data): 
     msg = image_t.decode(data)
     if msg.pixelformat == image_t.PIXEL_FORMAT_GRAY: 
         return im_resize(np.asarray(bytearray(msg.data), dtype=np.uint8).reshape(msg.height, msg.width), scale=self.scale)
     elif msg.pixelformat == image_t.PIXEL_FORMAT_MJPEG: 
         im = cv2.imdecode(np.asarray(bytearray(msg.data), dtype=np.uint8), -1)
         return im_resize(im, scale=self.scale)
     else: 
         raise RuntimeError('Unknown pixelformat for ImageDecoder')
Exemple #2
0
    def decode(self, msg):
        try:
            if self.compressed:
                im = compressed_imgmsg_to_cv2(msg, self.encoding)
            else:
                im = self.bridge.imgmsg_to_cv2(msg, self.encoding)
        except CvBridgeError as e:
            raise Exception('ImageDecoder.decode :: {}'.format(e))

        return im_resize(im, scale=self.scale)
Exemple #3
0
    def extract(self, im):
        self.segnet.forward(im)
        labels = self.segnet.extract(layer='argmax')

        # Resize labels to image
        out = labels.astype(np.uint8)
        out = im_resize(out, shape=im.shape[:2][::-1], interpolation=cv2.INTER_NEAREST)
        cout = np.dstack([out, out, out])
        colored = cv2.LUT(cout, self.colors)

        return colored        
    def extract(self, im):
        self.segnet.forward(im)
        labels = self.segnet.extract(layer='argmax')

        # Resize labels to image
        out = labels.astype(np.uint8)
        out = im_resize(out,
                        shape=im.shape[:2][::-1],
                        interpolation=cv2.INTER_NEAREST)
        cout = np.dstack([out, out, out])
        colored = cv2.LUT(cout, self.colors)

        return colored
Exemple #5
0
    def visualize(self, root=0):
        if len(self.frames_) < 2:
            return

        if self.fixed_reference_:
            ref = self.ref_frame_
            root = -1
        else:
            assert (root >= 0 and root < len(self.frames_))
            try:
                ref = self.frames_[root]
            except:
                raise RuntimeError("Unable to index to root")

        vis = {}

        # Detect features in the reference image, else
        # use provided features
        if ref.points is not None:
            pts = ref.points
        else:
            try:
                pts = self.fdet_.process(to_gray(ref.im))
            except:
                return

        if not len(pts):
            return

        print(pts.shape, pts.dtype)

        # Draw epipoles across all other images/poses
        for idx, f in enumerate(self.frames_):
            F_10 = ref.camera.F(f.camera)
            vis[idx] = plot_epipolar_line(f.im,
                                          F_10,
                                          pts,
                                          im_0=ref.im if idx == 0 else None)

            # print 'F b/w ref and idx={:}, \ncurr={:}\n\nF={:}\n'.format(idx, f.camera, F_10)

        if len(vis):
            imshow_cv('epi_out',
                      im_resize(np.vstack(list(vis.values())), scale=0.5))
Exemple #6
0
    def visualize(self, root=0):
        if len(self.frames_) < 2:
            return

        if self.fixed_reference_:
            ref_im = self.ref_frame_.im
            ref_camera = self.ref_frame_.camera
            root = -1
        else:
            assert (root >= 0 and root < len(self.frames_))
            try:
                ref_im = self.frames_[root].im
                ref_camera = self.frames_[root].camera
            except:
                raise RuntimeError("Unable to index to root")

        vis = {}

        # Detect features in the reference image
        try:
            pts = self.fdet_.process(to_gray(ref_im))
            # pts = pts.reshape(len(pts)/4,-1,2).mean(axis=1)
        except:
            return

        if not len(pts):
            return

        # Draw epipoles across all other images/poses
        for idx, f in enumerate(self.frames_):
            F_10 = ref_camera.F(f.camera)
            vis[idx] = plot_epipolar_line(f.im,
                                          F_10,
                                          pts,
                                          im_0=ref_im if idx == 0 else None)

            # print 'F b/w ref and idx={:}, \ncurr={:}\n\nF={:}\n'.format(idx, f.camera, F_10)

        if len(vis):
            imshow_cv('epi_out', im_resize(np.vstack(vis.values()), scale=0.5))
Exemple #7
0
 def dispread_process_cb(scale=1.0):
     """Scale disparity values for depth images"""
     return lambda fn: im_resize(cv2.imread(fn, cv2.IMREAD_UNCHANGED), scale=scale) * scale
Exemple #8
0
def imread_process_cb(scale=1.0, grayscale=False):
    return lambda fn: im_resize(cv2.imread(
        fn, cv2.IMREAD_GRAYSCALE if grayscale else cv2.IMREAD_UNCHANGED),
                                scale=scale)
Exemple #9
0
 def process(self, im): 
     boxes = self.proposer_.process(im_resize(im, scale=self.scale_))
     return (boxes * 1 / self.scale_).astype(np.int32)
Exemple #10
0
def write_video(fn, im, scale=1.0, as_images=False):
    global g_fn_map
    if fn not in g_fn_map:
        g_fn_map[fn] = VideoWriter(fn, as_images=as_images)
    im_scaled = im_resize(im, scale=scale) if scale != 1.0 else im
    g_fn_map[fn].write(im_scaled)