3
\\                 @   s   d dl T G dd dZdS )    )*c               @   s   e Zd ZejdejdejfddZ	dd Z
ejfddZddd	Zd
d Zdd Zdd Zdd Zdd Zdd Zdd Zedd Zedd ZdS )BoundingBoxNc             C   st  || _ || _|tjkr&|dkr&td|	tjkr@|
dkr@td|
| _|	| _|| _	|| _
|tjkrt|||||f\| _| _| _| _|d | _|d | _|tjkr| j| _| j| _| j| j | _| j| j | _ntdnj|| _|| _|tjkr|| _|| _| j| j | _| j| j | _n(|| _|| _| j| j | _| j| j | _|dkr\d| _d| _n|d | _|d | _dS )a  Constructor.
        Args:
            imageName: String representing the image name.
            classId: String value representing class id.
            x: Float value representing the X upper-left coordinate of the bounding box.
            y: Float value representing the Y upper-left coordinate of the bounding box.
            w: Float value representing the width bounding box.
            h: Float value representing the height bounding box.
            typeCoordinates: (optional) Enum (Relative or Absolute) represents if the bounding box
            coordinates (x,y,w,h) are absolute or relative to size of the image. Default:'Absolute'.
            imgSize: (optional) 2D vector (width, height)=>(int, int) represents the size of the
            image of the bounding box. If typeCoordinates is 'Relative', imgSize is required.
            bbType: (optional) Enum (Groundtruth or Detection) identifies if the bounding box
            represents a ground truth or a detection. If it is a detection, the classConfidence has
            to be informed.
            classConfidence: (optional) Float value representing the confidence of the detected
            class. If detectionType is Detection, classConfidence needs to be informed.
            format: (optional) Enum (BBFormat.XYWH or BBFormat.XYX2Y2) indicating the format of the
            coordinates of the bounding boxes. BBFormat.XYWH: <left> <top> <width> <height>
            BBFormat.XYX2Y2: <left> <top> <right> <bottom>.
        NzJParameter 'imgSize' is required. It is necessary to inform the image size.zLFor bbType='Detection', it is necessary to inform the classConfidence value.r      zDFor relative coordinates, the format must be XYWH (x,y,width,height))
_imageName_typeCoordinatesCoordinatesTypeZRelativeIOErrorBBTypeZDetected_classConfidence_bbType_classId_formatZconvertToAbsoluteValues_x_y_w_h
_width_img_height_imgBBFormatXYWH_x2_y2)selfZ	imageNameclassIdxywhtypeCoordinatesimgSizebbTypeclassConfidenceformat r#   @/home/pxk8301/PycharmProjects/Capstone/Evaluation/BoundingBox.py__init__   sN    !
"




zBoundingBox.__init__c             C   s   dj | j | j| j| j| jS )Nz{} {} {} {} {})r"   getImageNamer   r   r   r   )r   r#   r#   r$   __str__Z   s    zBoundingBox.__str__c             C   s@   |t jkr| j| j| j| jfS |t jkr<| j| j| j| jfS d S )N)	r   r   r   r   r   r   XYX2Y2r   r   )r   r"   r#   r#   r$   getAbsoluteBoundingBox]   s    

z"BoundingBox.getAbsoluteBoundingBoxc             C   sx   |d kr$| j d kr$| jd kr$td|d krRt|d |d f| j| j| j| jfS t| j | jf| j| j| j| jfS d S )NzJParameter 'imgSize' is required. It is necessary to inform the image size.r   r   )r   r   r   ZconvertToRelativeValuesr   r   r   r   )r   r   r#   r#   r$   getRelativeBoundingBoxc   s    z"BoundingBox.getRelativeBoundingBoxc             C   s   | j S )N)r   )r   r#   r#   r$   r&   n   s    zBoundingBox.getImageNamec             C   s   | j S )N)r
   )r   r#   r#   r$   getConfidenceq   s    zBoundingBox.getConfidencec             C   s   | j S )N)r   )r   r#   r#   r$   	getFormatt   s    zBoundingBox.getFormatc             C   s   | j S )N)r   )r   r#   r#   r$   
getClassIdw   s    zBoundingBox.getClassIdc             C   s   | j | jfS )N)r   r   )r   r#   r#   r$   getImageSizez   s    zBoundingBox.getImageSizec             C   s   | j S )N)r   )r   r#   r#   r$   getCoordinatesType}   s    zBoundingBox.getCoordinatesTypec             C   s   | j S )N)r   )r   r#   r#   r$   	getBBType   s    zBoundingBox.getBBTypec             C   s   | j  }| j }|j  }|j }| j |j kr| j|j kr|d |d kr|d |d kr|d |d kr|d |d kr|d |d kr|d |d krdS dS )Nr   r         TF)r)   r.   r-   r!   ZclassConfidenc)Zdet1Zdet2Zdet1BBZdet1ImgSizeZdet2BBZdet2ImgSizer#   r#   r$   compare   s    zBoundingBox.comparec             C   sZ   | j tjd}t| j | j |d |d |d |d | j | j | j | j	 tjd}|S )N)r"   r   r   r1   r2   )r   r   r    r!   r"   )
r)   r   r   r   r&   r-   r/   r.   r0   r+   )ZboundingBoxZabsBBZnewBoundingBoxr#   r#   r$   clone   s    
zBoundingBox.clone)N)__name__
__module____qualname__r   Absoluter	   GroundTruthr   r   r%   r'   r)   r*   r&   r+   r,   r-   r.   r/   r0   staticmethodr3   r4   r#   r#   r#   r$   r      s"   J
r   N)utilsr   r#   r#   r#   r$   <module>   s   