Created
November 16, 2017 13:42
-
-
Save meksor/4cac803a66004ecd2a921d91c83925bd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
from random import randint, random | |
intensity = 10 | |
glitch_row_size = 20 | |
img = cv2.imread('/tmp/screenshot.png') | |
org_rows, org_cols, cnls = img.shape | |
img = cv2.resize(img, (0,0), fx=0.3, fy=0.3) | |
rows, cols, cnls = img.shape | |
b, g, r = cv2.split(img) | |
channels = [] | |
fixed_channel = False | |
for c in (b, g, r): | |
if (random() > 0.4) and not fixed_channel: | |
M = np.float32([[1, random() /100, randint(intensity * -1, intensity)],[random()/100, 1, randint(intensity * -1, intensity)]]) | |
c = cv2.warpAffine(c,M,(cols,rows)) | |
fixed_channel = True | |
for i in range(0,5): | |
begin = randint(0, rows) | |
if (begin > rows - glitch_row_size): | |
end = randint(begin, rows) | |
else: | |
end = begin + randint(0, glitch_row_size) | |
area = c[begin:end, :] | |
offset = randint(begin*-1, rows-end) | |
area = np.resize(area, (end-begin, cols-abs(offset))) | |
print(offset, cols) | |
c[(begin+offset):(end+offset), abs(offset):cols] = area | |
channels.append(c) | |
channels = tuple(channels) | |
img = cv2.merge(channels) | |
img = cv2.resize(img, (org_cols, org_rows), interpolation= cv2.INTER_NEAREST) | |
cv2.imwrite('/tmp/screen_locked.png', img) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment