|
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 * |
4 | 5 |
|
5 |
| -imageFileName = raw_input("enter the image name with absolute path ") |
| 6 | +photo = askopenfilename() |
| 7 | +img = cv2.imread(photo) |
6 | 8 |
|
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