import math
import cv2
from skimage.segmentation import slic,mark_boundaries
import numpy as np
from skimage import color

class Show_Seg:

    def __init__(self):
        self.distance = 80

    def obtain_patch(self,Image,Depth,dep,center,angle):
        ret, mask = cv2.threshold(Depth, 1.7, 1, cv2.THRESH_BINARY_INV)
        mask = np.uint8(mask)
        dep = cv2.bitwise_not(dep)
        mask = cv2.bitwise_and(mask,dep)
        masked_data = cv2.bitwise_and(Image, Image, mask=mask)
        s0=50
        s1=50
        s2=50
        s3=50
        if angle < 45 and angle > -45:
            s2 += 50
        elif angle >45 and angle < 90:
            s3 += 50
        elif angle > 90 or angle <-90:
            s0 -=50
        else:
            s1 -= 50
        masked_data[0:center[1]-s1,:]=0
        masked_data[center[1] + s3:480, :] = 0
        masked_data[:,0:center[0] - s0] = 0
        masked_data[:,center[0] + s2:640] = 0
        cv2.rectangle(masked_data,(center[0]-s0,center[1]-s1),(center[0]+s2,center[1]+s3),(255,255,0),3)
        return masked_data