Skip to content

Instantly share code, notes, and snippets.

View ventusff's full-sized avatar
🎯
Focusing

Jeff / Jianfei Guo ventusff

🎯
Focusing
View GitHub Profile
@ventusff
ventusff / closest_point_on_spline.py
Last active December 30, 2021 13:32
closest point on spline
# NOTE: 给定一个点,找到其在一个样条函数上的最近点(或者说,投影点)
import numpy as np, matplotlib.pyplot as pp, mpl_toolkits.mplot3d as mp
import scipy.interpolate as si, scipy.optimize as so, scipy.spatial.distance as ssd
data = (1,2,3,4,5,6,7,8),(1,2.5,4,5.5,6.5,8.5,10,12.5),(1,2.5,4.5,6.5,8,8.5,10,12.5)
p = 6.5,9.5,9
# Fit a spline to the data - s is the amount of smoothing, tck is the parameters of the resulting spline
(tck, uu) = si.splprep(data, s=0)
if __name__ == "__main__":
from scipy.spatial.transform import Rotation as R
from scipy.interpolate import interp1d
# test = 'easy'
test = 'hard'
_intr3x3 = torch.tensor([[500,0,1000],[0,500,500],[0,0,1]])
cam_intrinsic = torch.eye(4, dtype=torch.double)
cam_intrinsic[:3, :3] = _intr3x3
'''
camera extrinsics visualization tools
modified from https://github.com/opencv/opencv/blob/master/samples/python/camera_calibration_show_extrinsics.py
'''
from utils.print_fn import log
import numpy as np
import cv2 as cv
@ventusff
ventusff / test_hashgrid_bwdbwd.py
Last active August 16, 2023 07:11
Derivations and code tests for second-order gradients of hashgrids of tiny-cuda-nn.
import torch
import torch.nn as nn
from torch import autograd
from torch.optim import Adam
import torch.nn.functional as F
import tinycudann as tcnn
class SDF(nn.Module):
def __init__(self, hash=True, n_levels=12, log2_hashmap_size=15, base_resolution=16, smoothstep=False) -> None:
@ventusff
ventusff / gpu_matrix.h
Created April 20, 2022 09:07
tiny-cuda-nn-debug-fork
/*
* Copyright (c) 2020-2022, NVIDIA CORPORATION. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted
* provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this list of
* conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
import numpy as np
import scipy
from scipy.spatial.transform import Rotation as R
np.set_printoptions(precision=4,suppress=True)
rot = R.random().as_matrix()
trans = np.random.uniform(size=(3,))
c2w = np.eye(4)
c2w[:3,:3] = rot
c2w[:3,3] = trans
@ventusff
ventusff / rend_util.py
Last active September 20, 2022 15:26
def ray_sphere_intersection_rough(
rays_o: torch.Tensor, rays_d: torch.Tensor, *,
r=1.0, keepdim=True, t_min_cons: float=0.0, t_max_cons: float=None) -> Tuple[torch.Tensor, torch.Tensor]:
"""
NOTE: Modified from https://github.com/Totoro97/NeuS
rays_o: camera center's coordinate
rays_d: camera rays' directions. already normalized.
"""
dir_scale = rays_d.norm(dim=-1, keepdim=keepdim).clamp_min_(1e-10)
# NOTE: (minus) the length of the line projected from [the line from camera to sphere center] to [the line of camera rays]
@ventusff
ventusff / depth_completion_pytorch.py
Last active December 28, 2023 08:41
depth_completion
"""
Modified from https://github.com/kujason/ip_basic.git
Uses kornia tensor operations as pytorch alternatives for cv2 operations.
@inproceedings{ku2018defense,
title={In Defense of Classical Image Processing: Fast Depth Completion on the CPU},
author={Ku, Jason and Harakeh, Ali and Waslander, Steven L},
booktitle={2018 15th Conference on Computer and Robot Vision (CRV)},
pages={16--22},
year={2018},
# This is the CMakeCache file.
# For build in directory: /home/guojianfei/ai_ws/direct-rtx-umesh-renderer/build
# It was generated by CMake: /home/guojianfei/anaconda3/envs/ml/bin/cmake
# You can edit this file to change values found and used by cmake.
# If you do not want to change any of the values, simply exit the editor.
# If you do want to change a value, simply edit, save, and exit the editor.
# The syntax for the file is as follows:
# KEY:TYPE=VALUE
# KEY is the name of a variable in the cache.
# TYPE is a hint to GUIs for the type of VALUE, DO NOT EDIT TYPE!.