Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update utils #42

Merged
merged 1 commit into from
Nov 17, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 5 additions & 12 deletions flip/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,11 @@ def rotate_bound(image, angle):
M[0, 2] += (nW / 2) - cX
M[1, 2] += (nH / 2) - cY

# distance matrix
# dst_mat = np.zeros((h, w, 4), np.uint8)

# perform the actual rotation and return the image
return cv2.warpAffine(
image,
M,
(nW, nH),
# dst_mat,
# flags=cv2.INTER_LINEAR,
# borderMode=cv2.BORDER_TRANSPARENT,
(nW, nH)
)


Expand All @@ -57,8 +51,8 @@ def overlay_transparent(

mask = cv2.GaussianBlur(mask, (7, 7), 0)

x = x #or 0
y = y #or 0
x = x
y = y
if x==None or y==None:
return background
if x >= background_width or y >= background_height:
Expand Down Expand Up @@ -98,6 +92,8 @@ def overlay_transparent(


def crop_from_contour(image):
if image.shape[2] != 4:
image = cv2.cvtColor(image, cv2.COLOR_RGB2BGRA)
_, _, _, a = cv2.split(image)
ret, thresh = cv2.threshold(a, 127, 255, 0)
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
Expand All @@ -109,7 +105,4 @@ def crop_from_contour(image):
rect = cv2.boundingRect(contours[index])
cropped_img = image[rect[1]:(rect[1] + rect[3]), rect[0]:(rect[0] + rect[2])]

# plt.imshow(cropped_img)
# plt.show()

return cropped_img