CoolFace
Apppublic

blanchon/Metric3D

sourceHugging Facegpl-3.0updated 2y agoView on Hugging Face
0likes
unproj_pcd.cpython-39.pyc35 linesDownload Raw Back to __pycache__
1a

2�6�d��@sHddlZddlZddlmZmZddlZdd�Zd3dd�Zddd	�Z	dS)�N)�PlyData�4PlyElementcCs�t�d|�}t�||df�}|�tj�}||}t�d|�}	t�|	|df�j}5|6�tj�}7|8|}||}||}9t�|�}tj||10|gdd�}
|
S)Nr��)�axis)�np�arange�tile�astype�float32�T�	ones_like�stack)�H�W�u0�v0�fx�fy�x_row�xZu_m_u0�y_col�yZv_m_v0�z�pw�r�GC:\Users\JUGG\Documents\GitHub\Metric3DPrivate\mono\utils\unproj_pcd.py�get_pcd_bases11rc12Csxt|�tjkr|������}t�|d�}|durN|j\}}t	||||||�}|dd�dd�df|}	|rtd|	|<|	S)N�r)13�type�torch�__name__�cpu�numpy�squeeze�cv2�14medianBlur�shaper)15�depthrrrrZpcd_base�maskrr�pcdrrr�reconstruct_pcds16r+Tc	Cs�|jd|jdksJ�|durTt�tjdgtjd�|jddf�}t�||f�}nt�||f�}ttttttf}gd�}|dur�g}t|jd�D]*}	||	}17|�	t18dd	�t||19�D���q�tj||d�}t�
|d20�}t|g��|�n�t�|dd�df�}
t�|dd�df�}t�|dd�df�}t�|dd�df�}t�|dd�d
f�}t�|dd�df�}d|jd}tj|tj|
|||||fd|dd�dS)z�Save an RGB point cloud as a PLY file.21    :paras22        @pcd: Nx3 matrix, the XYZ coordinates23        @rgb: Nx3 matrix, the rgb colors for each 3D point24    rN�)�dtype�))r�f4)rr/)rr/)�red�u1)�greenr1)�bluer1Tcss|]\}}||�VqdS)Nr)�.0r-�pointrrr�	<genexpr>=s�z#save_point_cloud.<locals>.<genexpr>�vertexrr�rz�ply25format ascii 1.026element vertex %d27property float x28property float y29property float z30property uchar red31property uchar green32property uchar blue33end_headerz%f %f %f %d %d %d�)�fmt�header�comments)r'rr	�array�uint8�hstack�float�int�range�append�tuple�zipr�describer�writer$�savetxt�column_stack)r*�rgb�filename�binaryZgray_concatZ	points_3dZpython_typesZ	npy_types�vertices�row_idxZ	cur_pointZvertices_array�elrrr�r�g�bZply_headrrr�save_point_cloud&s>���	�rS)NN)T)34r#rr Zplyfilerrr%rr+rSrrrr�<module>s35