-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlesson10.py
More file actions
73 lines (48 loc) · 1.79 KB
/
lesson10.py
File metadata and controls
73 lines (48 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import cv2
import numpy as np
#load the image to CARTOONIZE
'''
img= cv2.imread('gerry.png')
# convert the image to grayscale
img_gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
# apply median blur to remove noise
img_gray= cv2.medianBlur(img_gray,5)
#extract the edges with Laplacian
edges= cv2.Laplacian(img_gray,cv2.CV_8U, ksize=5)
# thresholding the edges
_, thresholded= cv2.threshold(edges,70,255, cv2.THRESH_BINARY_INV)
#get the colors with the bilateral filter
color_img= cv2.bilateralFilter(img, 10,250,250)
#merge color and edges
skt= cv2.cvtColor(thresholded,cv2.COLOR_GRAY2BGR)
sketch_img= cv2.bitwise_and(color_img,skt)
cv2.namedWindow('img', cv2.WINDOW_KEEPRATIO)
cv2.imshow('img', sketch_img)
cv2.waitKey(0)
'''
#video capture
cap= cv2.VideoCapture(0)
while True :
# read the current frame
img= cap.read()[1] # the read function will return a feedback boolean value and the proper image
# convert the image to grayscale
#img_gray= cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
#img_gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# img_gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_gray= cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# apply median blur to remove noise
img_gray= cv2.medianBlur(img_gray,5)
#extract the edges with Laplacian
edges= cv2.Laplacian(img_gray,cv2.CV_8U, ksize=5)
# thresholding the edges
_, thresholded= cv2.threshold(edges,70,255, cv2.THRESH_BINARY_INV)
#get the colors with the bilateral filter
color_img= cv2.bilateralFilter(img, 10,250,250)
#merge color and edges
skt= cv2.cvtColor(thresholded,cv2.COLOR_GRAY2BGR)
sketch_img= cv2.bitwise_and(color_img,skt)
cv2.namedWindow('img', cv2.WINDOW_KEEPRATIO)
cv2.imshow('img', sketch_img)
k=cv2.waitKey(10)
if k == ord('q'):
break