Browse Source

Fix some overlay issue

White border was add when using a overlay than less than 512x512
master
PommeDroid 3 years ago
parent
commit
53e7c46276
  1. 22
      utils.py

22
utils.py

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
import cv2
import numpy as np
from opencv_transform.dress_to_correct import correct_color
desired_size = 512
@ -10,15 +10,23 @@ def crop_input(img,x1,y1,x2,y2): @@ -10,15 +10,23 @@ def crop_input(img,x1,y1,x2,y2):
return resize_input(crop)
def overlay_original_img(original_img,img,x1,y1,x2,y2):
img = cv2.resize(img, (abs(x1-x2), abs(y1-y2)))
original_img = original_img[:,:,:3]
def overlay_original_img(original_img, img, x1, y1, x2, y2):
# Remove white border add by resizing in case of the overlay selection was less than 512x512
if abs(x1 - x2) < 512 or abs(y1 - y2) < 512:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray = 255 * (gray < 128).astype(np.uint8)
coords = cv2.findNonZero(gray)
x, y, w, h = cv2.boundingRect(coords)
img = img[y:y + h, x:x + w]
#
img = cv2.resize(img, (abs(x1 - x2), abs(y1 - y2)))
original_img = original_img[:, :, :3]
img = img[:, :, :3]
original_img = correct_color(original_img,5)
original_img[y1:y2,x1:x2] = img[:,:,:3]
original_img = correct_color(original_img, 5)
original_img[y1:y2, x1:x2] = img[:, :, :3]
return original_img
def resize_input(img):
old_size = img.shape[:2]
ratio = float(desired_size)/max(old_size)

Loading…
Cancel
Save