U
    ?h                     @   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dddddgfdddddddg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dddddgdd  Zd!d" Zejdddddddddg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,d0ggd)d)gd*d*gd-d-ggd)d.gd*d/gd-d0ggd.d.gd/d/gd0d0g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.d0ggd(d(gd*d*gd/d/ggd(d,gd*d-gd/d0ggd,d,gd-d-gd0d0gggfdd&d&d'd'gd(d(gd*d*gd)d)gggfgd1d2 Zejd3d4d5gd6d7 ZdS )8    )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 5 Q R X tddd\}}tt$ t|dddd|d d |d	 W 5 Q R X 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   Q/var/www/html/venv/lib/python3.8/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   c                 C   s`   t jd| d}t|}|j}d|jkr:t |jdd}t|dddd|d}|j|ks\td S )	Nr   r   Zuintu r   r   r   )r   r   r   r   namereplacer   AssertionError)r   r   r   r   Zexpected_dtyper*   r   r   r   !test_haar_like_feature_fused_type2   s    
r1   c                  C   sX   t jdt jd} t| }dddddg}t|ddd	d	|d
}t|ddd	d	}t|| d S )Nr   r   r   r!   r"   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   c              	   C   s   t jdt jd}t|}t| trVt|  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@t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   allr0   )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 5 Q R X |jd	ksttt ||kst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   shaper0   Zcount_nonzero)rC   Z
nnz_valuesr   Zcoord_imager   r   r   test_draw_haar_like_feature   s    rH   )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@   rH   r   r   r   r   <module>   s    



  
 
 &
	
