Skip to content

Commit 37661b4

Browse files
authored
Created easy_cartoonify.py
This is the first version of the project. Works completely fine with two cartoon styles, but I will add more and more image processing options later on.
1 parent 0e48c31 commit 37661b4

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import cv2
2+
import os
3+
from pathlib import Path
4+
5+
image_name = input("Please enter the name of the image file that you want to process: ") ## User input for the name of the image file.
6+
image_directory = input("Please enter the directory that may contain the image: ") ## User input for the path of the image file.
7+
8+
## This function looks for and finds the desired file. You can specify a parent directory for the fundtion to look for, however if you have no idea where a file is; this functio will find it for you, just slower. If you have no idea where a file is, just type "/".
9+
def find_the_image(file_name, directory_name):
10+
files_found = []
11+
for path, subdirs, files in os.walk(directory_name):
12+
for name in files:
13+
if(file_name == name):
14+
file_path = os.path.join(path,name)
15+
files_found.append(file_path)
16+
17+
print(files_found[0])
18+
return files_found[0] ## Return the path.
19+
20+
21+
image_path = Path(find_the_image(image_name, image_directory)) ## Inıtialize the path of the image file.
22+
new_working_directory = image_path.parent ## Initialize the parent directory of the image path.
23+
os.chdir(new_working_directory) ## Change the working directory of the script to the parent directory of the image path.
24+
25+
26+
color_image = cv2.imread(find_the_image(image_name, image_directory))
27+
##cv2.imshow("image_not_processed",color_image) ## Uncomment this to see the image without the process.
28+
##cv2.waitKey()
29+
##cv2.destroyAllWindows()
30+
31+
cartoon_style_selection = input("This script currently has 2 sytles. Please type 1 or 2. ")
32+
33+
if (cartoon_style_selection == "1"):
34+
cartoon_image_style_1 = cv2.stylization(color_image, sigma_s=150, sigma_r=0.25) ## Cartoonify process.
35+
cv2.imshow('cartoon_1', cartoon_image_style_1)
36+
cv2.waitKey()
37+
cv2.destroyAllWindows()
38+
elif (cartoon_style_selection == "2"):
39+
cartoon_image_style_2 = cv2.stylization(color_image, sigma_s=60, sigma_r=0.5) ## Cartoonify process.
40+
cv2.imshow('cartoon_2', cartoon_image_style_2)
41+
cv2.waitKey()
42+
cv2.destroyAllWindows()
43+
44+
else:
45+
print("Invalid style selection.")

0 commit comments

Comments
 (0)