Example #1
0
    def save_calibration_exr(self,fname):
        state_dict = self._get_state_as_dict()
        obj = {'pinhole_wizard_input':state_dict}

        tcs = np.zeros( (self.dsc.height,self.dsc.width,2))-1
        dist = np.nan*np.ones( (self.dsc.height,self.dsc.width))
        angle = np.nan*np.ones( (self.dsc.height,self.dsc.width))
        allmask = np.zeros((self.dsc.height,self.dsc.width))

        di = self.dsc.get_display_info()

        for row in self.vdisp_store:
            vdisp = row[VS_VDISP]

            for d in di['virtualDisplays']:
                if d['id'] != vdisp:
                    continue
                else:
                    break

            assert d['id'] == vdisp

            polygon_verts = d['viewport']
            maskarr = np.zeros( allmask.shape, dtype=np.uint8 )
            fill_polygon.fill_polygon(polygon_verts, maskarr)
            if np.max(maskarr)==0: # no mask
                maskarr += 1

            allmask += maskarr
            mask = np.nonzero(maskarr)

            camera = row[VS_CAMERA_OBJECT]
            assert camera is not None

            this_tcs = self.geom.compute_for_camera_view(camera,
                                                         what='texture_coords')
            this_dist = self.geom.compute_for_camera_view(camera,
                                                          what='distance' )
            this_angle = self.geom.compute_for_camera_view(camera,
                                                           what='incidence_angle' )

            this_tcs[ np.isnan(this_tcs) ] = -1.0 # nan -> -1

            # copy the important parts to the full display image
            tcs[mask] = this_tcs[mask]
            dist[mask] = this_dist[mask]
            angle[mask] = this_angle[mask]
        r=tcs[:,:,0]
        g=tcs[:,:,1]
        if 0:
            # Replace this code with something that calculates a real
            # blending value here based on distance. Probably need to
            # normalize by the maximum distance.
            raise NotImplementedError("b = f(dist,angle)")
        else:
            b=np.ones_like(tcs[:,:,1])

        exr.save_exr( fname, r=r, g=g, b=b)

        if 1:
            # save low dynamic range .png image
            ri = np.array( r*255, dtype=np.uint8 )
            gi = np.array( g*255, dtype=np.uint8 )
            bi = np.array( b*255, dtype=np.uint8 )

            h,w = r.shape[:2]
            imi = np.empty( (h,w,3), dtype=np.uint8 )
            imi[:,:,0] = ri
            imi[:,:,1] = gi
            imi[:,:,2] = bi
            scipy.misc.imsave(fname+'.png', imi)
Example #2
0
    def save_calibration_exr(self, fname):
        state_dict = self._get_state_as_dict()
        obj = {'pinhole_wizard_input': state_dict}

        tcs = np.zeros((self.dsc.height, self.dsc.width, 2)) - 1
        dist = np.nan * np.ones((self.dsc.height, self.dsc.width))
        angle = np.nan * np.ones((self.dsc.height, self.dsc.width))
        allmask = np.zeros((self.dsc.height, self.dsc.width))

        di = self.dsc.get_display_info()

        for row in self.vdisp_store:
            vdisp = row[VS_VDISP]

            for d in di['virtualDisplays']:
                if d['id'] != vdisp:
                    continue
                else:
                    break

            assert d['id'] == vdisp

            polygon_verts = d['viewport']
            maskarr = np.zeros(allmask.shape, dtype=np.uint8)
            fill_polygon.fill_polygon(polygon_verts, maskarr)
            if np.max(maskarr) == 0:  # no mask
                maskarr += 1

            allmask += maskarr
            mask = np.nonzero(maskarr)

            camera = row[VS_CAMERA_OBJECT]
            assert camera is not None

            this_tcs = self.geom.compute_for_camera_view(camera,
                                                         what='texture_coords')
            this_dist = self.geom.compute_for_camera_view(camera,
                                                          what='distance')
            this_angle = self.geom.compute_for_camera_view(
                camera, what='incidence_angle')

            this_tcs[np.isnan(this_tcs)] = -1.0  # nan -> -1

            # copy the important parts to the full display image
            tcs[mask] = this_tcs[mask]
            dist[mask] = this_dist[mask]
            angle[mask] = this_angle[mask]
        r = tcs[:, :, 0]
        g = tcs[:, :, 1]
        if 0:
            # Replace this code with something that calculates a real
            # blending value here based on distance. Probably need to
            # normalize by the maximum distance.
            raise NotImplementedError("b = f(dist,angle)")
        else:
            b = np.ones_like(tcs[:, :, 1])

        exr.save_exr(fname, r=r, g=g, b=b)

        if 1:
            # save low dynamic range .png image
            ri = np.array(r * 255, dtype=np.uint8)
            gi = np.array(g * 255, dtype=np.uint8)
            bi = np.array(b * 255, dtype=np.uint8)

            h, w = r.shape[:2]
            imi = np.empty((h, w, 3), dtype=np.uint8)
            imi[:, :, 0] = ri
            imi[:, :, 1] = gi
            imi[:, :, 2] = bi
            scipy.misc.imsave(fname + '.png', imi)
Example #3
0
    def update_bg_image(self):
        arr = np.zeros( (self.dsc.height,self.dsc.width,3), dtype=np.uint8 )
        di = self.dsc.get_display_info()
        # draw beachballs ----------------------

        for row in self.vdisp_store:
            if not row[VS_SHOW_BEACHBALL]:
                continue
            cam = row[VS_CAMERA_OBJECT]
            if cam is None:
                continue

            vdisp = row[VS_VDISP]
            for d in di['virtualDisplays']:
                if d['id'] != vdisp:
                    continue
                else:
                    break

            assert d['id'] == vdisp

            farr = self.geom.compute_for_camera_view( cam,
                                                      what='texture_coords' )

            u = farr[:,:,0]
            good = ~np.isnan( u )
            print 'showing beachball for %r'%row[VS_VDISP]
            print '  npix0',np.sum( np.nonzero( good ) )

            arr2 = simple_geom.tcs_to_beachball(farr)

            h,w = arr2.shape[:2]
            maskarr = np.zeros( (h,w), dtype=np.uint8 )
            polygon_verts = d['viewport']
            fill_polygon.fill_polygon(polygon_verts, maskarr)
            if np.max(maskarr)==0: # no mask
                maskarr += 1

            arr3 = maskarr[:,:,np.newaxis]*arr2

            print '  npix1',np.sum(np.nonzero(arr2))
            arr = arr+arr3

            print '  npix2',np.sum(np.nonzero(arr))

        # draw individual points ---------------

        showing = []
        for row in self.point_store:
            if not row[SHOWPT]:
                continue
            xf,yf = row[DISPLAYX], row[DISPLAYY]
            try:
                x = int(np.round(xf))
                y = int(np.round(yf))
            except ValueError:
                # Likely cannot convert nan to integer.
                continue
            if 0 <= x and x < self.dsc.width:
                if 0 <= y and y < self.dsc.height:
                    arr[y,x] = 255
                    showing.append( (x,y) )
        self.dsc.show_pixels(arr)
        return arr
Example #4
0
    def update_bg_image(self):
        arr = np.zeros((self.dsc.height, self.dsc.width, 3), dtype=np.uint8)
        di = self.dsc.get_display_info()
        # draw beachballs ----------------------

        for row in self.vdisp_store:
            if not row[VS_SHOW_BEACHBALL]:
                continue
            cam = row[VS_CAMERA_OBJECT]
            if cam is None:
                continue

            vdisp = row[VS_VDISP]
            for d in di['virtualDisplays']:
                if d['id'] != vdisp:
                    continue
                else:
                    break

            assert d['id'] == vdisp

            farr = self.geom.compute_for_camera_view(cam,
                                                     what='texture_coords')

            u = farr[:, :, 0]
            good = ~np.isnan(u)
            print 'showing beachball for %r' % row[VS_VDISP]
            print '  npix0', np.sum(np.nonzero(good))

            arr2 = simple_geom.tcs_to_beachball(farr)

            h, w = arr2.shape[:2]
            maskarr = np.zeros((h, w), dtype=np.uint8)
            polygon_verts = d['viewport']
            fill_polygon.fill_polygon(polygon_verts, maskarr)
            if np.max(maskarr) == 0:  # no mask
                maskarr += 1

            arr3 = maskarr[:, :, np.newaxis] * arr2

            print '  npix1', np.sum(np.nonzero(arr2))
            arr = arr + arr3

            print '  npix2', np.sum(np.nonzero(arr))

        # draw individual points ---------------

        showing = []
        for row in self.point_store:
            if not row[SHOWPT]:
                continue
            xf, yf = row[DISPLAYX], row[DISPLAYY]
            try:
                x = int(np.round(xf))
                y = int(np.round(yf))
            except ValueError:
                # Likely cannot convert nan to integer.
                continue
            if 0 <= x and x < self.dsc.width:
                if 0 <= y and y < self.dsc.height:
                    arr[y, x] = 255
                    showing.append((x, y))
        self.dsc.show_pixels(arr)
        return arr