def _check_twilight(illumination=None):
	"""Check for daylight."""
	if illumination:
		illumination = illumination if date.today() == illumination[2] else twilight(coordinates(address))
	else:
		illumination = twilight(coordinates(address))
	result = 'daytime' if illumination[0] <= datetime.now() <= illumination[1] else 'nighttime'
	return (result, illumination)
コード例 #2
0
def _check_twilight(illumination=None):
    """Check for daylight."""
    if illumination:
        illumination = illumination if date.today(
        ) == illumination[2] else twilight(coordinates(address))
    else:
        illumination = twilight(coordinates(address))
    result = 'daytime' if illumination[0] <= datetime.now(
    ) <= illumination[1] else 'nighttime'
    return (result, illumination)
コード例 #3
0
ファイル: app.py プロジェクト: LuigiLegion/deimosy
def main():
    # Create image from image file path
    img = image()
    # Prompt user for starting and target points
    coords = coordinates(img)
    # Find optimal path based on starting and target points
    find_optimal_path(img, coords)
コード例 #4
0
def page(location):
    info = utils.getWiki(location)
    if info:
        info = info.decode("utf-8")
    coord = utils.coordinates(location)
    return render_template("page.html",
                           location=location,
                           info=info,
                           coord=coord)
コード例 #5
0
def path():
    if request.method == 'POST':
        # Extract start and end points coordinates from request
        coords = coordinates(request)
        # Create image from image file path
        img = Image.open(DEFAULT_IMAGE)
        # Find optimal path based on start and end points
        path = find_optimal_path(img, coords)

        return jsonify(path), 200
コード例 #6
0
def compute_ssd(target, candidate, is_empty, patch_side_len):
    """ The sum of squared differences between candidate texture and target patch to fill, for all non-empty pixels. """
    offset = 2 * patch_side_len  # can't put the target patch right on the edge because it will overflow
    ssd_matrix = np.zeros((candidate.shape[0] - offset, candidate.shape[1] - offset), np.uint64)

    target = target.astype(np.int32)  # coerce into uint16 because we square uint8
    is_valid = ~is_empty  # valid only if pixel is not empty

    for target_row, target_col in zip(*is_valid.nonzero()):  # go through every target patch pixel that is filled
        target_pixel = target[target_row, target_col]
        for r, c in coordinates(ssd_matrix):  # compute its distance from all pixels in the candidate
            texture_pixel = candidate[r + target_row, c + target_col]
            ssd_matrix[r, c] += ((target_pixel - texture_pixel) ** 2).sum()  # times: .sum < np.sum < builtin sum

    return ssd_matrix
コード例 #7
0
ファイル: app.py プロジェクト: RJZheng1/API-Project
def page(location):
    info = utils.getWiki(location)
    if info:
        info = info.decode("utf-8")
    coord = utils.coordinates(location)
    return render_template("page.html", location = location, info = info, coord = coord)
コード例 #8
0
    def transform(self, data, transform=None, old_origin=None,
                  align_corners=False):
        """ Applies a 3x4 linear transformation to the TSDF.

        Each voxel is moved according to the transformation and a new volume
        is constructed with the result.

        Args:
            data: items from data loader
            transform: 4x4 linear transform
            old_origin: origin of the voxel volume (xyz position of voxel (0, 0, 0))
                default (None) is the same as the input
            align_corners:

        Returns:
            Items with new TSDF and occupancy in the transformed coordinates
        """

        # ----------computing visual frustum hull------------
        bnds = torch.zeros((3, 2))
        bnds[:, 0] = np.inf
        bnds[:, 1] = -np.inf

        for i in range(data['imgs'].shape[0]):
            size = data['imgs'][i].shape[1:]
            cam_intr = data['intrinsics'][i]
            cam_pose = data['extrinsics'][i]
            view_frust_pts = get_view_frustum(self.max_depth, size, cam_intr, cam_pose)
            bnds[:, 0] = torch.min(bnds[:, 0], torch.min(view_frust_pts, dim=1)[0])
            bnds[:, 1] = torch.max(bnds[:, 1], torch.max(view_frust_pts, dim=1)[0])

        # -------adjust volume bounds-------
        num_layers = 3
        center = (torch.tensor(((bnds[0, 1] + bnds[0, 0]) / 2, (bnds[1, 1] + bnds[1, 0]) / 2, -0.2)) - data[
            'vol_origin']) / self.voxel_size
        center[:2] = torch.round(center[:2] / 2 ** num_layers) * 2 ** num_layers
        center[2] = torch.floor(center[2] / 2 ** num_layers) * 2 ** num_layers
        origin = torch.zeros_like(center)
        origin[:2] = center[:2] - torch.tensor(self.voxel_dim[:2]) // 2
        origin[2] = center[2]
        vol_origin_partial = origin * self.voxel_size + data['vol_origin']

        data['vol_origin_partial'] = vol_origin_partial

        # ------get partial tsdf and occupancy ground truth--------
        if 'tsdf_list_full' in data.keys():
            # -------------grid coordinates------------------
            old_origin = old_origin.view(1, 3)

            x, y, z = self.voxel_dim
            coords = coordinates(self.voxel_dim, device=old_origin.device)
            world = coords.type(torch.float) * self.voxel_size + vol_origin_partial.view(3, 1)
            world = torch.cat((world, torch.ones_like(world[:1])), dim=0)
            world = transform[:3, :] @ world
            coords = (world - old_origin.T) / self.voxel_size

            data['tsdf_list'] = []
            data['occ_list'] = []

            for l, tsdf_s in enumerate(data['tsdf_list_full']):
                # ------get partial tsdf and occ-------
                vol_dim_s = torch.tensor(self.voxel_dim) // 2 ** l
                tsdf_vol = TSDFVolumeTorch(vol_dim_s, vol_origin_partial,
                                           voxel_size=self.voxel_size * 2 ** l, margin=3)
                for i in range(data['imgs'].shape[0]):
                    depth_im = data['depth'][i]
                    cam_intr = data['intrinsics'][i]
                    cam_pose = data['extrinsics'][i]

                    tsdf_vol.integrate(depth_im, cam_intr, cam_pose, obs_weight=1.)

                tsdf_vol, weight_vol = tsdf_vol.get_volume()
                occ_vol = torch.zeros_like(tsdf_vol).bool()
                occ_vol[(tsdf_vol < 0.999) & (tsdf_vol > -0.999) & (weight_vol > 1)] = True

                # grid sample expects coords in [-1,1]
                coords_world_s = coords.view(3, x, y, z)[:, ::2 ** l, ::2 ** l, ::2 ** l] / 2 ** l
                dim_s = list(coords_world_s.shape[1:])
                coords_world_s = coords_world_s.view(3, -1)

                old_voxel_dim = list(tsdf_s.shape)

                coords_world_s = 2 * coords_world_s / (torch.Tensor(old_voxel_dim) - 1).view(3, 1) - 1
                coords_world_s = coords_world_s[[2, 1, 0]].T.view([1] + dim_s + [3])

                # bilinear interpolation near surface,
                # no interpolation along -1,1 boundry
                tsdf_vol = torch.nn.functional.grid_sample(
                    tsdf_s.view([1, 1] + old_voxel_dim),
                    coords_world_s, mode='nearest', align_corners=align_corners
                ).squeeze()
                tsdf_vol_bilin = torch.nn.functional.grid_sample(
                    tsdf_s.view([1, 1] + old_voxel_dim), coords_world_s, mode='bilinear',
                    align_corners=align_corners
                ).squeeze()
                mask = tsdf_vol.abs() < 1
                tsdf_vol[mask] = tsdf_vol_bilin[mask]

                # padding_mode='ones' does not exist for grid_sample so replace
                # elements that were on the boarder with 1.
                # voxels beyond full volume (prior to croping) should be marked as empty
                mask = (coords_world_s.abs() >= 1).squeeze(0).any(3)
                tsdf_vol[mask] = 1

                data['tsdf_list'].append(tsdf_vol)
                data['occ_list'].append(occ_vol)
            data.pop('tsdf_list_full')
            data.pop('depth')
        data.pop('epoch')
        return data