Skip to content

Commit

Permalink
added draw matrix bulk script
Browse files Browse the repository at this point in the history
  • Loading branch information
maksimKorzh committed Jul 2, 2021
1 parent 6985ec0 commit 653f17a
Show file tree
Hide file tree
Showing 11 changed files with 120 additions and 1 deletion.
Binary file added src/bulk/face.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image6.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/bulk/image7.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
62 changes: 62 additions & 0 deletions src/draw-matrix-bulk.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##########################################
#
# Simple script to automate the process
# of drawing using Python
#
# by
#
# Code Monkey King
#
##########################################


# packages
import cv2
import pyautogui as pg
import time
import random

# wait before user clicks on window to within
time.sleep(5)

# global coordinates of where to start drawing (change if needed!)
x_start = 200
y_start = 200

# put mouse mointer into initial position
pg.moveTo(x_start, y_start)

# number of images
frames = 12

# loop over images
for i in range(1, frames + 1):
# open source image
originalImage = cv2.imread('./bulk/image' + str(i) + '.png')

# convert image to grayscale
grayImage = cv2.cvtColor(originalImage, cv2.COLOR_BGR2GRAY)

# convert image to black and white
(thresh, blackAndWhiteImage) = cv2.threshold(grayImage, 127, 255, cv2.THRESH_BINARY)

# uncomment below lines to preview image
#cv2.imshow('Black & white image', blackAndWhiteImage)
#cv2.waitKey(0)
#cv2.destroyAllWindows()

# loop over pixel rows
for y in range(len(blackAndWhiteImage)):
# init row
row = blackAndWhiteImage[y]

# loop over pixel cols
for x in range(len(row)):
if row[x] == 0:
# draw pixel!
pg.click(x_start + x, y_start + y, _pause=False)
print('Drawing at:', x_start + x, y_start + y)

# animation speed
time.sleep(0.008)

2 changes: 1 addition & 1 deletion src/draw.py → src/draw-matrix-random.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
# randomize cols traversal order
row = blackAndWhiteImage[y]
random_cols = list(range(len(row)))
random.shuffle(random_cols)
#random.shuffle(random_cols)

# loop over pixel cols
for x in random_cols:
Expand Down
57 changes: 57 additions & 0 deletions src/draw-matrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
##########################################
#
# Simple script to automate the process
# of drawing using Python
#
# by
#
# Code Monkey King
#
##########################################


# packages
import cv2
import pyautogui as pg
import time
import random

# open source image
originalImage = cv2.imread('image.png')

# convert image to grayscale
grayImage = cv2.cvtColor(originalImage, cv2.COLOR_BGR2GRAY)

# convert image to black and white
(thresh, blackAndWhiteImage) = cv2.threshold(grayImage, 127, 255, cv2.THRESH_BINARY)

# uncomment below lines to preview image
cv2.imshow('Black & white image', blackAndWhiteImage)
cv2.waitKey(0)
cv2.destroyAllWindows()

# global coordinates of where to start drawing (change if needed!)
x_start = 250
y_start = 150

# wait before user clicks on window to within
time.sleep(5)

# put mouse mointer into initial position
pg.moveTo(x_start, y_start)

# loop over pixel rows
for y in range(len(blackAndWhiteImage)):
# init row
row = blackAndWhiteImage[y]

# loop over pixel cols
for x in range(len(row)):
if row[x] == 0:
# draw pixel!
pg.click(x_start + x, y_start + y, _pause=False)
print('Drawing at:', x_start + x, y_start + y)

# animation speed
time.sleep(0.008)

0 comments on commit 653f17a

Please sign in to comment.