+
    {Dìjó  ã                   ó¶   € R t ^ RIt^ RIt^ RIt^ RIt^ RIHt R
w  tt	t
tRt]P                  ! 4       tR tR tR t ! R R4      t]! ]P&                  R	7      tR# )a(  
MediaPipe Pose wrapper + landmark smoothing.

THREAD SAFETY
-------------
A MediaPipe Pose object is NOT safe to share between threads. We therefore keep
one instance per thread (threading.local), created lazily on first use. Each
gunicorn worker process / thread ends up with its own detector.
N)Úsettingsç      à?c                  ó¼   € \        \        R R4      p V fG   ^ RIpVP                  P                  P                  R\        P                  RRR7      p V \        n        V # )ÚposeNTr   )Ústatic_image_modeÚmodel_complexityÚenable_segmentationÚmin_detection_confidence)ÚgetattrÚ_localÚ	mediapipeÚ	solutionsr   ÚPoser   ÚPOSE_MODEL_COMPLEXITY)r   Úmps     Útryon\services\pose_detector.pyÚ	_get_poser      sY   € Ü”6˜6 4Ó(€DØ‚|Ûà�|‰|× Ñ ×%Ñ%ð #Ü%×;Ñ;Ø $Ø%(ð &ó 
ˆð ŒŒØ€Kó    c           
     ó–
  aaa a!€ \         P                  ! V \         P                  4      p\        4       P	                  V4      pVP
                  '       g   R# VP
                  P                  oV P                  R,          w  r4V3R lp. pR F3  w  rxršVP                  V! V4      V! V4      V! V	4      V! V
4      34       K5  	  \        V^ ,          ^ ,          ^,          V^,          ^ ,          ^,          4      \        8  d   R# VP                  R R7       V^ ,          ^ ,          V^,          ^ ,          uw  r¼w  rÜ\        P                  ! WC.\        P                  R7      o WÛ,
          S ,          p\        \        P                   P#                  V4      4      o!\        P                  ! V^,          ) V^ ,          .\        P                  R7      \%        S!R4      ,          oVV V!3R lp\        V^ ,          ^,          ^,          V^,          ^,          ^,          4      \        8¬  ;'       dH    \%        V^ ,          ^,          ^ ,          ^,          V^,          ^,          ^ ,          ^,          4      R	8*  pW½.pV'       d<   \'        V^ ,          ^,          ^ ,          V^,          ^,          ^ ,          .R
 R7      pM\)        W½V P                  4      pVV,          p\+        V4       F«  w  ppV^ ,          ^ ,          pV^ 8X  d   RMRpV\%        S!R4      ,          V,          pV^,          ^,          R8¼  d   V^,          ^ ,          M9VS ,          SS!,          R,          ,           VS!,          R,          ,           S ,          pVP                  V4       K­  	  \+        V4       F«  w  ppV^ ,          ^ ,          pV^ 8X  d   RMRpV\%        S!R4      ,          V,          pV^,          ^,          R8¼  d   V^,          ^ ,          M9VS ,          SS!,          R,          ,           VS!,          R,          ,           S ,          pVP                  V4       K­  	  Rp\-        VRR4      pVe*   VR8„  P/                  \        P0                  4      ^ÿ,          pV! ^4      V! ^4      .p\        V^ ,          ^,          V^,          ^,          4      \        8¬  ;'       d:    \%        V^ ,          ^ ,          ^,          V^,          ^ ,          ^,          4      R8*  pR\        P                  ! V\        P                  R7      RVR\3        V4      R\3        V4      /# )aŽ  
Return a dict or None if no person is found:
  points : (8, 2) NORMALISED coords, order
           [L shoulder, R shoulder, L hip, R hip, L elbow, R elbow, L wrist, R wrist]
           ("L" = left side OF THE IMAGE, so mirroring never matters)
  mask   : uint8 person mask (0/255) same size as the frame, or None
Missing hips / elbows / wrists (person too close) are estimated from the shoulders.
NºNé   Nc                 ó¾   <€ \         P                  ! SV ,          P                  SV ,          P                  .\         P                  R 7      SV ,          P
                  3# )©Údtype)ÚnpÚarrayÚxÚyÚfloat32Ú
visibility)ÚiÚlms   &€r   ÚptÚdetect_body.<locals>.pt9   s<   ø€ Ü�xŠx˜˜A�Ÿ™ " Q¥%§'¡'Ð*´"·*±*Ô=¸rÀ!½u×?OÑ?OÐOÐOr   c                 ó0   € V ^ ,          ^ ,          ^ ,          # ©é    © )Úts   &r   Ú<lambda>Údetect_body.<locals>.<lambda>B   s   € ˜Q˜q�T !�W QžZr   ©Úkeyr   ç      ð?c                 óN   <€ V S,          SS,          V,          ,           S,          # ©Nr'   )Ús_normÚkÚdownÚscaleÚsws   &&€€€r   ÚestÚdetect_body.<locals>.estK   s   ø€ Ø˜• ¨¥¨Q¥Õ.°%Õ7Ð7r   g      ø?c                 ó   € V ^ ,          # r%   r'   )Úps   &r   r)   r*   R   s   € ÀaÈÆdr   gš™™™™™Ù?çÍÌÌÌÌÌì?gš™™™™™¹?g333333û?g333333Ã?Úsegmentation_maskr   ÚpointsÚmaskÚhips_okÚlegs_ok))é   é   é   é   )é   é   é   é   g      ð¿)Úcv2ÚcvtColorÚCOLOR_BGR2RGBr   ÚprocessÚpose_landmarksÚlandmarkÚshapeÚappendÚminÚMIN_VISIBILITYÚsortr   r   r   ÚfloatÚlinalgÚnormÚmaxÚsortedÚ_estimate_hipsÚ	enumerater
   ÚastypeÚuint8Úbool)"Ú	frame_bgrÚrgbÚresultsÚhÚwr"   ÚsidesÚsh_iÚel_iÚwr_iÚhp_iÚlsÚ_ÚrsÚvecr5   r=   ÚoutÚhipsÚidxÚsider0   Ú	side_signÚout_vecÚelbowÚwristr<   ÚsegÚankr>   r2   r!   r3   r4   s"   &                             @@@@r   Údetect_bodyrt   )   s$  û€ ô �,Š,�y¤#×"3Ñ"3Ó
4€CÜ‹k×!Ñ! #Ó&€GØ×!×!Ð!ÙØ	×	Ñ	×	(Ñ	(€BØ�?‰?˜2Õ�D€AõPð €EÛ"FÑˆ�DØ�‰‘b˜“h¡ 4£©"¨T«(±B°t³HÐ=Ö>ñ #Gä
ˆ5��8�A�;�q�>˜5 �8 A�; q�>Ó*¬^Ô;ÙØ	‡J�JÑ'€JÔ(Ø˜Q•x •{ E¨!¥H¨Q¥KÐ�G€R‰Wˆbô �HŠH�a�V¤2§:¡:Ô.€EØ�7�eÕ
€CÜ	Œr�y‰y�~‰~˜cÓ"Ó	#€BÜ�8Š8�c˜!•f�W˜c !�fÐ%¬R¯Z©ZÔ8¼3¸rÀ3»<ÕG€D÷8ô �%˜•(˜1•+˜a•. %¨¥(¨1¥+¨a¥.Ó1´^ÑC×xÐxÌÈEÐRSÍHÐUVÍKÐXYÍNÐ[\ÕL]Ð_dÐefÕ_gÐhiÕ_jÐklÕ_mÐnoÕ_pÓHqÐuxÑHx€GØˆ(€CçÜ�u˜Q•x •{ 1•~ u¨Q¥x°¥{°1¥~Ð6¹NÔK‰ä˜b i§o¡oÓ6ˆØˆ4…K€Cä˜uÖ%‰	ˆˆTØ�a•˜•ˆØ 1œH‘D¨#ˆ	Øœ˜R ›Õ%¨Õ2ˆØ" 1�g a�j¨CÔ/��Q•˜–
°f¸uµnÀtÈbÅyÐSVÅÕ6VÐY`ÐceÕYeÐhkÕYkÕ6kÐotÕ5tˆØ�
‰
�5Öñ &ô ˜uÖ%‰	ˆˆTØ�a•˜•ˆØ 1œH‘D¨#ˆ	Øœ˜R ›Õ%¨Õ2ˆØ" 1�g a�j¨CÔ/��Q•˜–
°f¸uµnÀtÈbÅyÐSVÅÕ6VÐY`ÐceÕYeÐhlÕYlÕ6lÐpuÕ5uˆØ�
‰
�5Öñ &ð €DÜ
�'Ð.°Ó
5€CØ
‚Ø�s‘×"Ñ"¤2§8¡8Ó,°Õ3ˆñ ˆb‹6‘2�b“6Ð
€CÜ�#�a•&˜•)˜S �V A�YÓ'¬>Ñ9×dÐd¼cÀ#ÀaÅ&ÈÅ)ÈAÅ,ÐPSÐTUÕPVÐWXÕPYÐZ[ÕP\Ó>]ÐadÑ>d€Gà”b—h’h˜s¬"¯*©*Ô5°v¸tØ”t˜G“} i´°g³ð@ð @r   c                ó¤  € VR,          w  r4WV.,          pWV.,          pWe,
          p\         P                  P                  V4      pV^8  d   W.# \         P                  ! V^,          ) V^ ,          .4      V,          p	WV,           ^,          W˜,          R,          ,           p
V^,          R,          pW«,
          WC.,          W«,           WC.,          .# )zQGuess hip positions ~1.6 shoulder-widths below the shoulders (normalised coords).r   gš™™™™™ù?r9   )r   rS   rT   r   )Úleft_sÚright_srM   r_   r`   rf   rh   ri   Úwidthr2   ÚmidÚhalfs   &&&         r   rW   rW   q   s°   € à��9�D€Aà	�a�&�€BØ	�q�6Õ	€BØ
�'€CÜ�I‰I�N‰N˜3Ó€EØˆq„yØÐ Ð Ü�8Š8�c˜!•f�W˜c !�fÐ%Ó&¨Õ.€DØ�7�a�-˜$�,¨Õ,Õ
,€CØ��7�S�=€DØ�Z˜A˜6Õ! C¥J°1°&Õ#8Ð9Ð9r   c                   ó@   a € ] tR t^�t o RtRR ltR tR tR tRt	V t
R# )	ÚLandmarkSmoothera4  
Exponential moving average per browser session:
    smoothed = alpha * new + (1 - alpha) * previous
State is kept in memory, guarded by a lock, and expires automatically.
NOTE: with several gunicorn *processes*, each process has its own state;
that is fine because the smoothing only affects visual jitter.
c                ól   € Wn         W n        W0n        / V n        \        P
                  ! 4       V n        R # r/   )ÚalphaÚttlÚmax_sessionsÚ_stateÚ	threadingÚLockÚ_lock)Úselfr~   Úttl_secondsr€   s   &&&&r   Ú__init__ÚLandmarkSmoother.__init__Š   s'   € ØŒ
ØŒØ(ÔØˆŒÜ—^’^Ó%ˆŽ
r   c                óÀ  € \         P                  ! 4       pV P                  ;_uu_ 4        V P                  V4       V P                  P                  V4      pVeX   W4^ ,          ,
          V P                  8  d:   V P                  V,          RV P                  ,
          V^,          ,          ,           pW23V P                  V&   R R R 4       V#   + '       g   i     T# ; i)Nr-   )ÚtimeÚ	monotonicr„   Ú_evictr�   Úgetr   r~   )r…   r,   r;   ÚnowÚprevs   &&&  r   ÚsmoothÚLandmarkSmoother.smooth‘   sœ   € Ü�nŠnÓˆØ�Z�Z‹ZØ�K‰K˜ÔØ—;‘;—?‘? 3Ó'ˆDØÒ C¨q­'¥M°D·H±HÔ$<ØŸ™ fÕ,°°d·j±jÕ0@ÀDÈÅGÕ/KÕK�Ø #˜}ˆD�K‰K˜Ñ÷ ð ˆ÷ ŽZð ˆús   ªBCÃC	c                ó    € V P                   ;_uu_ 4        V P                  P                  VR 4       R R R 4       R #   + '       g   i     R # ; ir/   )r„   r�   Úpop)r…   r,   s   &&r   ÚresetÚLandmarkSmoother.reset›   s)   € Ø�Z�Z‹ZØ�K‰K�O‰O˜C Ô&÷ �Z�ZŠZús	   •<¼A	c                ó¾  a € \        S P                  4      S P                  8  d   R # S P                  P                  4        UUUu. uF#  w  pw  r4W,
          S P                  8”  g   K!  VNK%  	  uppp F  pS P                  V K  	  \        S P                  4      S P                  8¼  d+   \        S P                  V 3R lR7      pS P                  V R # R # u upppi )Nc                 ó8   <€ SP                   V ,          ^ ,          # r%   )r�   )r1   r…   s   &€r   r)   Ú)LandmarkSmoother._evict.<locals>.<lambda>¥   s   ø€ °D·K±KÀµNÀ1Ö4Er   r+   )Úlenr�   r€   Úitemsr   rO   )r…   rŽ   r1   r(   rg   Úoldests   f&    r   rŒ   ÚLandmarkSmoother._evictŸ   s¥   ø€ Üˆt�{‰{Ó˜d×/Ñ/Ô/ÙØ%)§[¡[×%6Ñ%6Ô%8ÕOÑ%8™	˜™6˜A¸C½GÀdÇhÁhÑ<N—!�!Ñ%8ÖOˆAØ—‘˜A’ñ Päˆt�{‰{Ó˜t×0Ñ0Ô0Ü˜Ÿ™Ô*EÔFˆFØ—‘˜FÒ#ñ 1ùô Ps   ÁCÁ)C)r„   r�   r~   r€   r   N)r   éx   iè  )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r‡   r�   r”   rŒ   Ú__static_attributes__Ú__classdictcell__)Ú__classdict__s   @r   r|   r|   �   s#   ø‡ € ñô&òò'÷$ð $r   r|   )r~   )r?   rC   rB   rF   )r¢   r‚   rŠ   rG   Únumpyr   Údjango.confr   Ú
L_SHOULDERÚ
R_SHOULDERÚL_HIPÚR_HIPrP   Úlocalr   r   rt   rW   r|   ÚSMOOTHING_ALPHAÚsmootherr'   r   r   Ú<module>r¯      sk   ðñó Û ã 
Û Ý  ð (6Ñ $€
ˆJ˜˜uØ€à	�ŠÓ	€òò"E@òP:÷ %$ñ %$ñP  (×":Ñ":Ô;‚r   