Last active
April 5, 2019 05:21
-
-
Save ivder/2e0e23b3a3978226c24ec7fed8a53696 to your computer and use it in GitHub Desktop.
icon
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 | |
# Input image | |
input = cv2.imread('0.jpg') | |
# Get input size | |
width, height, _ = input.shape | |
# Desired "pixelated" size | |
w, h = (64, 64) | |
# Resize input to "pixelated" size | |
temp = cv2.resize(input, (w, h), interpolation=cv2.INTER_LINEAR) | |
# Initialize output image | |
output = cv2.resize(temp, (width, height), interpolation=cv2.INTER_NEAREST) | |
gray = cv2.cvtColor(output, cv2.COLOR_BGR2GRAY) | |
'''equ = cv2.equalizeHist(gray) | |
(thresh, bw) = cv2.threshold(equ, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) | |
blur = cv2.blur(bw,(2,2)) | |
kernel = np.ones((5,5),np.uint8) | |
opening = cv2.morphologyEx(blur, cv2.MORPH_OPEN, kernel)''' | |
(thresh, bw) = cv2.threshold(gray, 128, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU) | |
kernel = np.ones((5,5),np.uint8) | |
morph = cv2.morphologyEx(bw, cv2.MORPH_CLOSE, kernel) | |
output = cv2.cvtColor(morph, cv2.COLOR_GRAY2BGR) | |
cv2.rectangle(output,(50,5),(150,130),(0,0,255),2) | |
cv2.putText(output, '?',(80,100), cv2.FONT_HERSHEY_SIMPLEX, 2,(0,0,0),2,cv2.LINE_AA) | |
cv2.imwrite("icon.jpg", output) | |
cv2.imshow('opening', output) | |
cv2.waitKey(0) | |
cv2.destroyAllWindows() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment