o
    e                     @   s  d dl mZ d dlZd dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ d d	lmZ d
d Zejdejejejejgejddddgfdddgfddg dfddg dfdddgfgdd Zejdejejejejgejdg ddd Zdd Zejddddddg d gd!d" Zejd#dd$d$d%d%gd&d&ggd%d'gd&d(ggd'd'gd(d(gggfdd$d$d%d%gd'd'ggd%d&gd'd(ggd&d&gd(d(gggfdd)d)d%d%gd&d&gd*d*ggd%d'gd&d(gd*d+ggd%d,gd&d-gd*d.ggd'd'gd(d(gd+d+ggd'd,gd(d-gd+d.ggd,d,gd-d-gd.d.gggfdd)d)d%d%gd'd'gd,d,ggd%d&gd'd(gd,d-ggd%d*gd'd+gd,d.ggd&d&gd(d(gd-d-ggd&d*gd(d+gd-d.ggd*d*gd+d+gd.d.gggfdd$d$d%d%gd&d&gd(d(gd'd'gggfgd/d0 Zejd1d2d3gd4d5 ZdS )6    )shuffleN)assert_allclose)assert_array_equal)expected_warnings)integral_image)haar_like_featurehaar_like_feature_coord)draw_haar_like_featurec               
   C   s   t jdt jd} t| }d}tt# t|dddd|d tdd|d t	| dddd|d W d    n1 s9w   Y  tddd\}}tt t|dddd|d d |d	 W d    d S 1 sfw   Y  d S )
N   r   dtypeZunknown_typer   r   feature_typetype-2-x   r   Zfeature_coord)
nponesfloat32r   pytestZraises
ValueErrorr   r	   r
   )imgimg_iir   
feat_coord	feat_type r   OD:\Projects\ConvertPro\env\Lib\site-packages\skimage/feature/tests/test_haar.pytest_haar_like_feature_error   s   "r   r   z1feature_type,shape_feature,expected_feature_valuer   )T   g        type-2-ytype-3-x)*   )g      g      g       g      type-3-ytype-4)$   c                 C   sD   t jd|d}t|}t|dddd| d}tt t || d S )Nr   r   r   r   r   )r   r   r   r   r   sortunique)r   Zshape_featureZexpected_feature_valuer   r   r   haar_featurer   r   r   test_haar_like_feature    s   r+   r   r   r!   r"   r%   r&   c                 C   s`   t jd| d}t|}|j}d|jv rt |jdd}t|dddd|d}|j|ks.J d S )	Nr   r   Zuintu r   r   r   )r   r   r   r   namereplacer   )r   r   r   r   Zexpected_dtyper*   r   r   r   !test_haar_like_feature_fused_type2   s   
r1   c                  C   sR   t jdt jd} t| }g d}t|dddd|d}t|dddd}t|| d S )Nr   r   r,   r   r   r   )r   r   int8r   r   r   )r   r   r   Z	haar_listZhaar_allr   r   r   test_haar_like_feature_listD   s   r3   )r!   r"   r&   c              	   C   s   t jdt jd}t|}t| tr+t|  tdd | D  \}}t |}t |}nt	dd| \}}t
|dddd||d}t
|dddd| }t|| d S )Nr   r   c                 S   s   g | ]}t d d |qS )r   r   ).0Zfeat_tr   r   r   
<listcomp>Z   s    z6test_haar_like_feature_precomputed.<locals>.<listcomp>r   r   r   )r   r   r2   r   
isinstancelistr   zipZconcatenater	   r   r   )r   r   r   r   r   Zhaar_feature_precomputedr*   r   r   r   "test_haar_like_feature_precomputedN   s    

r9   z(feature_type,height,width,expected_coord   )r   r   )r      )r;   r   )r;   r;   r   )r   r:   )r;   r:   )r:   r   )r:   r;   )r:   r:   c                 C   sD   t ||| \}}tdd |D }t|| t|| ks J d S )Nc                 S   s   g | ]}|qS r   r   )r4   Zhfr   r   r   r5      s    z0test_haar_like_feature_coord.<locals>.<listcomp>)r	   r   arrayr   all)r   heightwidthZexpected_coordr   r   r   r   r   test_haar_like_feature_coordg   s   '
r@   zmax_n_features,nnz_values)N.   )r;      c                 C   s   t jdt jd}tddd\}}t|dddd|| dd}tdg t|dddd|| dd W d    n1 s8w   Y  |jd	ksDJ t ||ksMJ d S )
Nr   r   r   r&   r   )max_n_featuresrngz'`random_state` is a deprecated argument)rC   Zrandom_state)r   r   r   )r   Zzerosr   r	   r
   r   shapeZcount_nonzero)rC   Z
nnz_valuesr   coord_imager   r   r   test_draw_haar_like_feature   s   rI   )randomr   r   numpyr   Znumpy.testingr   r   Zskimage._shared._warningsr   Zskimage.transformr   Zskimage.featurer   r	   r
   r   markZparametrizeZuint8r2   r   Zfloat64r+   r1   r3   r9   r@   rI   r   r   r   r   <module>   s    






&
	