o
    {qi{;                     @   sX   d dl mZmZmZmZ ddlmZmZ ddlm	Z	 G dd deZ
G dd deZd	S )
   )add_simple_inference_argsget_subcommand_argsperform_simple_inferencestr2bool   )PaddleXPipelineWrapperPipelineCLISubcommandExecutor)create_config_from_structurec                       s   e Zd Z																								d fdd	Zedd ZdddddddddddddddddZdddddddddddddddd	d
Zedd Z	dd Z
  ZS )SealRecognitionNc              	      s   i d|d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d||||||||d| _ t jdi | d S )N#doc_orientation_classify_model_name"doc_orientation_classify_model_dirdoc_unwarping_model_namedoc_unwarping_model_dirlayout_detection_model_namelayout_detection_model_dirseal_text_detection_model_nameseal_text_detection_model_dirtext_recognition_model_nametext_recognition_model_dirtext_recognition_batch_sizeuse_doc_orientation_classifyuse_doc_unwarpinguse_layout_detectionlayout_threshold
layout_nmslayout_unclip_ratio)layout_merge_bboxes_modeseal_det_limit_side_lenseal_det_limit_typeseal_det_threshseal_det_box_threshseal_det_unclip_ratioseal_rec_score_thresh )_paramssuper__init__)selfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   kwargs	__class__r#   l/home/app/PaddleOCR-VL/.venv_paddleocr/lib/python3.10/site-packages/paddleocr/_pipelines/seal_recognition.pyr&      sX   	

zSealRecognition.__init__c                 C      dS NZseal_recognitionr#   r'   r#   r#   r+   _paddlex_pipeline_nameS      z&SealRecognition._paddlex_pipeline_namer   r   r   layout_det_resr   r   r   r   r   r   r   r    r!   r"   c                K   s2   | j j|f||||||||	|
|||||d|S Nr1   )Zpaddlex_pipelinepredictr'   inputr   r   r   r2   r   r   r   r   r   r   r   r    r!   r"   r(   r#   r#   r+   predict_iterW   s(   zSealRecognition.predict_iterc                K   s4   t | j|f||||||||	|
|||||d|S r3   )listr7   r5   r#   r#   r+   r4   ~   s,   zSealRecognition.predictc                 C   s   t  S N)$SealRecognitionCLISubcommandExecutor)clsr#   r#   r+   get_cli_subcommand_executor   s   z+SealRecognition.get_cli_subcommand_executorc              
   C   s(  i d| j d d| j d d| j d d| j d d	| j d
 d| j d d| j d d| j d d| j d d| j d d| j d d| j d d| j d pS| j d d| j d d| j d d| j d d | j d! | j d" | j d# | j d$ | j d% | j d& | j d' | j d( | j d) d*}t|S )+NzISubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_namer   zHSubPipelines.DocPreprocessor.SubModules.DocOrientationClassify.model_dirr   z?SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_namer   z>SubPipelines.DocPreprocessor.SubModules.DocUnwarping.model_dirr   z%SubModules.LayoutDetection.model_namer   z$SubModules.LayoutDetection.model_dirr   z$SubModules.LayoutDetection.thresholdr   z%SubModules.LayoutDetection.layout_nmsr   z.SubModules.LayoutDetection.layout_unclip_ratior   z3SubModules.LayoutDetection.layout_merge_bboxes_moder   z9SubPipelines.DocPreprocessor.use_doc_orientation_classifyr   z.SubPipelines.DocPreprocessor.use_doc_unwarpingr   Zuse_doc_preprocessorz8SubPipelines.SealOCR.SubModules.TextDetection.model_namer   z7SubPipelines.SealOCR.SubModules.TextDetection.model_dirr   z<SubPipelines.SealOCR.SubModules.TextDetection.limit_side_lenr   z8SubPipelines.SealOCR.SubModules.TextDetection.limit_typer   r   r    r!   r   r   r   r"   r   )z4SubPipelines.SealOCR.SubModules.TextDetection.threshz8SubPipelines.SealOCR.SubModules.TextDetection.box_threshz:SubPipelines.SealOCR.SubModules.TextDetection.unclip_ratioz:SubPipelines.SealOCR.SubModules.TextRecognition.model_namez9SubPipelines.SealOCR.SubModules.TextRecognition.model_dirz:SubPipelines.SealOCR.SubModules.TextRecognition.batch_sizez<SubPipelines.SealOCR.SubModules.TextRecognition.score_threshr   )r$   r	   )r'   Z	STRUCTUREr#   r#   r+   _get_paddlex_config_overrides   s   


!#&),/Fz-SealRecognition._get_paddlex_config_overrides)NNNNNNNNNNNNNNNNNNNNNNNN)__name__
__module____qualname__r&   propertyr/   r7   r4   classmethodr<   r=   __classcell__r#   r#   r)   r+   r
      sz    9
+)
r
   c                   @   s(   e Zd Zedd Zdd Zdd ZdS )r:   c                 C   r,   r-   r#   r.   r#   r#   r+   subparser_name   r0   z3SealRecognitionCLISubcommandExecutor.subparser_namec                 C   s  t | |jdtdd |jdtdd |jdtdd |jdtd	d |jd
tdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jdtdd |jd td!d |jd"td#d |jd$td%d |jd&td'd |jd(td)d |jd*td+d |jd,td-d |jd.td/d |jd0td1d d S )2Nz%--doc_orientation_classify_model_namez<Name of the document image orientation classification model.)typehelpz$--doc_orientation_classify_model_dirzFPath to the document image orientation classification model directory.z--doc_unwarping_model_namez+Name of the document image unwarping model.z--doc_unwarping_model_dirz5Path to the document image unwarping model directory.z--layout_detection_model_namez#Name of the layout detection model.z--layout_detection_model_dirz-Path to the layout detection model directory.z --seal_text_detection_model_namez&Name of the seal text detection model.z--seal_text_detection_model_dirz0Path to the seal text detection model directory.z--text_recognition_model_namez#Name of the text recognition model.z--text_recognition_model_dirz-Path to the text recognition model directory.z--text_recognition_batch_sizez*Batch size for the text recognition model.z--use_doc_orientation_classifyz9Whether to use document image orientation classification.z--use_doc_unwarpingz(Whether to use document image unwarping.z--use_layout_detectionz Whether to use layout detection.z--layout_thresholdz%Threshold for layout detection model.z--layout_nmsz7Non-Maximum Suppression threshold for layout detection.z--layout_unclip_ratioz'Layout detection expansion coefficient.z--layout_merge_bboxes_modez4Mode for merging bounding boxes in layout detection.z--seal_det_limit_side_lenzZThis sets a limit on the side length of the input image for the seal text detection model.z--seal_det_limit_typez}This determines how the side length limit is applied to the input image before feeding it into the seal text detection model.z--seal_det_threshzDetection pixel threshold for the seal text detection model. Pixels with scores greater than this threshold in the output probability map are considered text pixels.z--seal_det_box_threshzDetection box threshold for the seal text detection model. A detection result is considered a text region if the average score of all pixels within the border of the result is greater than this threshold.z--seal_det_unclip_ratiozSeal text detection expansion coefficient, which expands the text region using this method. The larger the value, the larger the expansion area.z--seal_rec_score_threshz^Text recognition threshold. Text results with scores greater than this threshold are retained.)r   add_argumentstrintr   float)r'   Z	subparserr#   r#   r+   _update_subparser   s   
z6SealRecognitionCLISubcommandExecutor._update_subparserc                 C   s   t |}tt| d S r9   )r   r   r
   )r'   argsparamsr#   r#   r+   execute_with_argsv  s   z6SealRecognitionCLISubcommandExecutor.execute_with_argsN)r>   r?   r@   rA   rD   rK   rN   r#   r#   r#   r+   r:      s
    
|r:   N)Z
_utils.clir   r   r   r   baser   r   utilsr	   r
   r:   r#   r#   r#   r+   <module>   s    ]