
    9i                         S SK JrJrJrJr  S SKJr  S SKJr  S SK	J
r
  S SKJr  S SKJr  S SKJr  S SKJr  \" 5       r\R(                  " \R*                  \R*                  S	9 " S
 S\
5      5       rg)    )AnyDictListUnion)	Pipelines)Model)Pipeline)	PIPELINES)Tasks)Image)
get_logger)module_namec                      ^  \ rS rSrSrS\4U 4S jjrS\\\	\   4   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$ )CardDetectionPipeline   aD  Card Detection Pipeline.

Examples:

>>> from modelscope.pipelines import pipeline

>>> detector = pipeline('card-detection', 'damo/cv_resnet_carddetection_scrfd34gkps')
>>> detector("http://www.modelscope.cn/api/v1/models/damo/cv_resnet_carddetection_scrfd34gkps/repo?Revision=master"
>>>             "&FilePath=description/card_detection1.jpg")
>>>   {
>>>    "boxes": [
>>>        [
>>>        446.9007568359375,
>>>        36.374977111816406,
>>>        907.0919189453125,
>>>        337.439208984375
>>>        ],
>>>        [
>>>        454.3310241699219,
>>>        336.08477783203125,
>>>        921.26904296875,
>>>        641.7871704101562
>>>        ]
>>>    ],
>>>    "keypoints": [
>>>        [
>>>        457.34710693359375,
>>>        339.02044677734375,
>>>        446.72271728515625,
>>>        52.899078369140625,
>>>         902.8200073242188,
>>>        35.063236236572266,
>>>        908.5877685546875,
>>>        325.62030029296875
>>>         ],
>>>         [
>>>        465.2864074707031,
>>>        642.8411254882812,
>>>       454.38568115234375,
>>>        357.4076232910156,
>>>        902.5343017578125,
>>>        334.18377685546875,
>>>        922.0982055664062,
>>>         621.0704345703125
>>>        ]
>>>    ],
>>>    "scores": [
>>>        0.9296008944511414,
>>>        0.9260380268096924
>>>    ]
>>>   }
>>>
modelc                    > [         TU ]  " SSU0UD6  [        U R                  [        5      (       d   S5       eU R                  R                  U R                  5      nX0l        g)z
use `model` to create a face detection pipeline for prediction
Args:
    model: model id on modelscope hub or `ScrfdDetect` Model.
    preprocessor: `SCRFDPreprocessor`.
r   z model object is not initialized.N )super__init__
isinstancer   r   todevicedetector)selfr   kwargsr   	__class__s       o/var/www/html/land-doc-ocr/venv/lib/python3.13/site-packages/modelscope/pipelines/cv/card_detection_pipeline.pyr   CardDetectionPipeline.__init__H   s_     	/u//$**! ! 	E"D	E !::==-     inputc                 &   > [         TU ]  " U40 UD6$ )aI  
Detect objects (bounding boxes or keypoints) in the image(s) passed as inputs.

Args:
    input (`Image` or `List[Image]`):
        The pipeline handles three types of images:

        - A string containing an HTTP(S) link pointing to an image
        - A string containing a local path to an image
        - An image loaded in PIL or opencv directly

        The pipeline accepts either a single image or a batch of images. Images in a batch must all be in the
        same format.


Return:
    A dictionary of result or a list of dictionary of result. If the input is an image, a dictionary
    is returned. If input is a list of image, a list of dictionary is returned.

    The dictionary contain the following keys:

    - **scores** (`List[float]`) -- The detection score for each card in the image.
    - **boxes** (`List[float]) -- The bounding boxe [x1, y1, x2, y2] of detected objects in in image's
        original size.
    - **keypoints** (`List[Dict[str, int]]`, optional) -- The corner kepoint [x1, y1, x2, y2, x3, y3, x4, y4]
        of detected object in image's original size.
)r   __call__)r   r!   r   r   s      r   r#   CardDetectionPipeline.__call__U   s    8 w000r    returnc                 (   U R                  U5      nSU;   az  SSKJnJn  U" U/SS9n[	        U R
                  R                  5       5      R                  (       a8  U" U[	        U R
                  R                  5       5      R                  /5      S   nU$ )N	img_metasr   )collatescatter   )samples_per_gpu)	preprocessormmcv.parallelr(   r)   nextr   
parametersis_cudar   )r   r!   resultr(   r)   s        r   
preprocess CardDetectionPipeline.preprocesss   s    ""5) & 6fXq9FDJJ))+,44 "&tzz'<'<'>"?"F"F!GIIJLr    c                 &    U R                   " S0 UD6$ )Nr   r   )r   r!   s     r   forwardCardDetectionPipeline.forward   s    }}%u%%r    inputsc                     U$ )Nr   )r   r8   s     r   postprocess!CardDetectionPipeline.postprocess   s    r    r5   )__name__
__module____qualname____firstlineno____doc__strr   r   r   r   r#   r   r   r2   r6   r:   __static_attributes____classcell__)r   s   @r   r   r      s    4l!c !1eE4;$67 1< $sCx. &T#s(^ &S#X &$sCx. T#s(^  r    r   N)typingr   r   r   r   modelscope.metainfor   !modelscope.models.base.base_modelr   modelscope.pipelines.baser	   modelscope.pipelines.builderr
   modelscope.utils.constantr   $modelscope.utils.input_output_typingr   modelscope.utils.loggerr   loggerregister_modulecard_detectionr   r   r    r   <module>rO      sc    ) ) ) 3 . 2 + 6 .	 	i&>&>@sH s@sr    