
    9i                     ,   S SK r S SKrS SKJrJr  S SKrS SKrS SKrS SK	J
r
  S SKJrJrJrJrJr  S SKJr  S SKJr  S SKJrJrJr  S SKJr  S S	KJrJr  S S
KJr  \" 5       r \RB                  " \RD                  \
RD                  S9 " S S\5      5       r#g)    N)AnyDict)	Pipelines)keep_largestreconstructionsave_obj_meshsave_obj_mesh_with_color	to_tensor)
OutputKeys)pipeline)InputModelPipeline)	PIPELINES)	ModelFileTasks)
get_logger)module_namec                      ^  \ rS rSrS\4U 4S jjrS\S\\\4   4S jr	S\\\4   S\\\4   4S jr
S\\\4   S\\\4   4S	 jrS
rU =r$ )HumanReconstructionPipeline   modelc                    > [         TU ]  " SSU0UD6  [        U R                  [        5      (       d   [
        R                  S5        [        S5      eg)aW  The inference pipeline for human reconstruction task.
Human Reconstruction Pipeline. Given one image generate a human mesh.

Args:
    model (`str` or `Model` or module instance): A model instance or a model local dir
        or a model id in the model hub.

Example:
    >>> from modelscope.pipelines import pipeline
    >>> test_input = 'human_reconstruction.jpg' # input image path
    >>> pipeline_humanRecon = pipeline('human-reconstruction',
        model='damo/cv_hrnet_image-human-reconstruction')
    >>> result = pipeline_humanRecon(test_input)
    >>> output =  result[OutputKeys.OUTPUT]
r   z model object is not initialized.N )super__init__
isinstancer   r   loggererror	Exception)selfr   kwargs	__class__s      u/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/human_reconstruction_pipeline.pyr   $HumanReconstructionPipeline.__init__   sI      	/u//$**e,,LL;<>?? -    inputreturnc                 :   U R                   R                  U5      nU R                   R                  U5      u  p4U R                   R                  X45      u  pV[	        U5      S-  S-
  n[	        U5      S-  S-
  n[	        U5      S-  S-
  n[	        U5      nUUUUS.nU$ )N      )imgmasknormal_Fnormal_B)r   crop_imgget_maskgeneration_normalr
   )	r!   r'   img_cropr,   r-   normal_fnormal_bimageresults	            r$   
preprocess&HumanReconstructionPipeline.preprocess1   s    ::&&u-JJ''1	!ZZ99#D(#a'!+X&*Q.X&*Q.  	
 r&   c                    US   nUS   nUS   nUS   nUS   * US'   US   * US'   X#-  nXS-  nXC-  n[         R                  " XhU/SS9R                  5       nUR                  S5      R	                  U R
                  R                  5      n	U R
                  R                  n
U R
                  R                  nUR                  U	5        [        XU R
                  R                  U R
                  R                  5      u  p[        R                  " XS	S
S9n[        U5      nUR                   nUR"                  n[         R$                  " UR&                  5      R                  S5      R	                  U R
                  R                  5      R                  5       n[         R(                  " UR*                  5      nSn[-        [/        U5      U-  5       H{  nUU-  nUU-  U-   nU[/        U5      U-  S-
  :X  a  SnUR1                  US S 2S S 2UU24   U
5      nUS   R3                  5       R5                  5       S-  S-   nUR&                  UUU& M}     [6        R8                  " US S 2S4   5      nUS S 2S4   U-
  US S 2S4'   [;        SX5        [=        SXUR?                  5       5        XUR?                  5       S.n[@        RB                  U0$ )Nr,   r-   r.   r/   )r+   .)r   .r   )dimFT)processmaintain_orderi N  r+   g      ?zhuman_reconstruction.objzhuman_color.obj)verticesfacescolors)"torchcatfloat	unsqueezetor   devicecalib	meshmodelextract_featuresr   coordsmattrimeshTrimeshr   r?   r@   
from_numpyTzerosshaperangelen	query_rgbdetachcpunpminr   r	   numpyr   OUTPUT)r!   r'   r6   r-   normFnormBr,   r5   r4   image_tensorcalib_tensornetvertsr@   pre_mesh
final_meshverts_tensorcolorintervalileftright
pred_colorrgbvert_minresultss                             r$   forward#HumanReconstructionPipeline.forwardA   s   eV}j!j!vfvfl<<ii1q9??A}}Q'**4::+<+<=zz''jj""\*%c9J9J&*jjnn6??%>!(+
##  ''0::1=@@JJ$uw 	EKK(s5zX-.Ax<DL8+ECJ(*Q..|Aq$u*4D'E'35JQ-&&(,,.4s:C #E$u / 66%1+&AqDkH,ad0%? !2E!&	0$N!!7++r&   inputsc                     U$ )Nr   )r!   rp   s     r$   postprocess'HumanReconstructionPipeline.postprocessl   s    r&   r   )__name__
__module____qualname____firstlineno__strr   r   r   r   r8   rn   rr   __static_attributes____classcell__)r#   s   @r$   r   r      sx    @c @* $sCx.  ),T#s(^ ),S#X ),V$sCx. T#s(^  r&   r   )$osshutiltypingr   r   rZ   rX   rB   rM   modelscope.metainfor   /modelscope.models.cv.human_reconstruction.utilsr   r   r   r	   r
   modelscope.outputsr   modelscope.pipelinesr   modelscope.pipelines.baser   r   r   modelscope.pipelines.builderr   modelscope.utils.constantr   r   modelscope.utils.loggerr   r   register_modulehuman_reconstructionr   r   r&   r$   <module>r      s~    	      )  * ) < < 2 6 .	 	I,J,JLS( SLSr&   