Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 73aff3d

Browse files
Update cartooneffect.py
1 parent 78ba75e commit 73aff3d

File tree

1 file changed

+21
-23
lines changed

1 file changed

+21
-23
lines changed

‎Cartooning Image/cartooneffect.py‎

Lines changed: 21 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,23 @@
1-
import cv2
2-
import numpy as np
3-
import Image
1+
2+
import cv2
3+
import numpy as np
4+
from tkinter.filedialog import *
45

5-
imageFileName = raw_input("enter the image name with absolute path ")
6+
photo = askopenfilename()
7+
img = cv2.imread(photo)
68

7-
# reading image
8-
img = cv2.imread("imageFileName")
9-
10-
# Edges
11-
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
12-
gray = cv2.medianBlur(gray, 5)
13-
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
14-
cv2.THRESH_BINARY, 9, 9)
15-
16-
# Cartoonization
17-
color = cv2.bilateralFilter(img, 9, 250, 250)
18-
cartoon = cv2.bitwise_and(color, color, mask=edges)
19-
20-
21-
cv2.imshow("Image", img)
22-
cv2.imshow("edges", edges)
23-
cv2.imshow("Cartoon", cartoon)
24-
cv2.waitKey(0)
25-
cv2.destroyAllWindows()
9+
grey = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
10+
grey = cv2.medianBlur(grey, 5)
11+
edges = cv2.adaptiveThreshold(grey, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 9, 9)
12+
13+
#cartoonize
14+
color = cv2.bilateralFilter(img, 9, 250, 250)
15+
cartoon = cv2.bitwise_and(color, color, mask = edges)
16+
17+
cv2.imshow("Image", img)
18+
cv2.imshow("Cartoon", cartoon)
19+
20+
#save
21+
cv2.imwrite("cartoon.jpg", cartoon)
22+
cv2.waitKey(0)
23+
cv2.destroyAllWindows()

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /