Skip to content
Open
Show file tree
Hide file tree
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
Binary file added assets/Megamind.avi
Binary file not shown.
Binary file added assets/cat_damaged.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 assets/cat_mask.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 outputs/cat_inpainted.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions tutorial10.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import cv2
import numpy as np
import os

# Playing video from file:
cap = cv2.VideoCapture('assets/Megamind.avi')

try:
if not os.path.exists('data-single'):
os.makedirs('data-single')
except OSError:
print ('Error: Creating directory of data')

currentFrame = 0
while(True):
# Capture frame-by-frame
ret, frame = cap.read()

# Saves image of the current frame in jpg file
name = './data-single/frame' + str(currentFrame) + '.jpg'
print ('Creating...' + name)
cv2.imwrite(name, frame)

# To stop duplicate images
currentFrame += 1

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()


#lucciffer

51 changes: 51 additions & 0 deletions tutorial11.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import cv2
import numpy as np


def read_file(filename):
img = cv2.imread(filename)
cv2_imshow(img)
return img

def color_quantization(img, k):
# Transform the image
data = np.float32(img).reshape((-1, 3))

# Determine criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 20, 0.001)

# Implementing K-Means
ret, label, center = cv2.kmeans(data, k, None, criteria, 10, cv2.KMEANS_RANDOM_CENTERS)
center = np.uint8(center)
result = center[label.flatten()]
result = result.reshape(img.shape)
return result

def edge_mask(img, line_size, blur_value):
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
gray_blur = cv2.medianBlur(gray, blur_value)
edges = cv2.adaptiveThreshold(gray_blur, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, line_size, blur_value)
return edges


img = read_file(file_path)


line_size = 5
blur_value = 13

edges = edge_mask(img, line_size, blur_value)
cv2_imshow(edges)

total_color = 7

img = color_quantization(img, total_color)
cv2_imshow(img)
cv2.imwrite('./output_minus1.png', img)

blurred = cv2.bilateralFilter(img, d=7, sigmaColor=200,sigmaSpace=200)
cv2_imshow(blurred)

cartoon = cv2.bitwise_and(blurred, blurred, mask=edges)
cv2.imwrite('./output.png', cartoon)
cv2_imshow(cartoon)
14 changes: 14 additions & 0 deletions tutorial9.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import numpy as np
import cv2

# Open the image.
img = cv2.imread('assets/cat_damaged.png')

# Load the mask.
mask = cv2.imread('assets/cat_mask.png', 0)

# Inpaint.
dst = cv2.inpaint(img, mask, 3, cv2.INPAINT_NS)

# Write the output.
cv2.imwrite('outputs/cat_inpainted.png', dst)