# -*- coding: utf-8 -*-
"""input_image.ipynb

Automatically generated by Colaboratory.

Original file is located at
    https://colab.research.google.com/drive/1n4mOXiDrCxQL0abSwwIbBP5YXaFn_Axj
"""

import torch
from torchvision import transforms
from google.colab.patches import cv2_imshow
import cv2
import numpy as np
from random import *
from imgaug import augmenters as iaa
import math
# Commented out IPython magic to ensure Python compatibility.
# %cd /content/drive/My Drive/image_cutout/

####Randomly cutout paricular portion of the bounding box
path='이미지 상대경로 및 절대경로'

cutout=cv2.imread(path)
label=open('/content/drive/My Drive/label_cutout/__95bDVirnJgqPmjbHjQAA.txt','r')
list=label.readline()
while(list):
    list=list.split()
    x_center=float(list[1])
    y_center=float(list[2])
    height=float(list[4])*832
    width=float(list[3])*1664
    x_center_new=x_center*1664
    y_center_new=y_center*832
    print(x_center_new,y_center_new)
    #radomly set x1 which is greater than leftmost x coordinates and less than center+1/4 of width
    x1=uniform(x_center_new-width/2,x_center_new+width/4)
    #radomly set y1 which is greater than leftmost y coordinates and less than center+1/4 of height
    y1=uniform(y_center_new-height/2,y_center_new+height/4)
    mark=width/2 #2 is empirical number 
    x2=x1+mark
    y2=y1+mark
    x1=int(x1)
    x2=int(x2)
    y1=int(y1)
    y2=int(y2)
    print(x1," ",y1," ",x2," ",y2)
    cutoout = cv2.rectangle(cutout, (x1, y1), (x2,y2), (0, 0, 0), cv2.FILLED)
    list=label.readline()


cv2_imshow(cutout)

