from PIL import Image, ImageDraw, ImageOps

def showImage(image, shape, outfile):
    img = Image.new("RGBA",(int(image.size[0]), int(image.size[1])))
    draw = ImageDraw.Draw(img)
    for poly in shape:
        draw.polygon(poly,fill ="#eeeeff", outline ="black")
    new_image = Image.blend(img,image,0.1)
    # new_image.show()
    new_image.save("output/bbox/" + outfile)

def solveImage(poly):
    x = []
    y = []
    for coord in poly:
        x.append(coord[0])
        y.append(coord[1])
    center_farme = ((max(x)+min(x))/2,(max(y)+min(y))/2)

    result = [(center_farme),(max(x),min(x)),(max(y),min(y)) ]
    return result

def save2PngColor(image, solve, outfile):
    img = image.crop((solve[1][1],solve[2][1],solve[1][0],solve[2][0]))
    img.save(outfile)


from PIL import Image, ImageDraw, ImageOps

def showImage(image, shape, outfile):
    img = Image.new("RGBA",(int(image.size[0]), int(image.size[1])))
    draw = ImageDraw.Draw(img)
    for poly in shape:
        draw.polygon(poly,fill ="#eeeeff", outline ="black")
    new_image = Image.blend(img,image,0.1)
    # new_image.show()
    new_image.save("output/bbox/" + outfile)

def solveImage(poly):
    x = []
    y = []
    for coord in poly:
        x.append(coord[0])
        y.append(coord[1])
    center_farme = ((max(x)+min(x))/2,(max(y)+min(y))/2)

    result = [(center_farme),(max(x),min(x)),(max(y),min(y)) ]
    return result

def save2PngColor(image, solve, outfile):
    img = image.crop((solve[1][1],solve[2][1],solve[1][0],solve[2][0]))
    img.save(outfile)


# new_image.show()