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 0f2bba3

Browse files
Merge pull request avinashkranjan#597 from aliya-rahmani/master
Cartooning Image
2 parents a0c562b + e673b25 commit 0f2bba3

File tree

3 files changed

+47
-0
lines changed

3 files changed

+47
-0
lines changed

‎Cartooning Image/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Cartooning Image with OpenCV
2+
3+
We aim to transform images into its cartoon. Yes, we will CARTOONIFY the images. Thus, we will build a python application that will transform an image into its cartoon using OpenCV.
4+
5+
6+
## What is OpenCV?
7+
8+
OpenCV is an open-source python library used for computer vision and machine learning. It is mainly aimed at real-time computer vision and image processing. It is used to perform different operations on images which transform them using different techniques.
9+
In this article, we will try to perform some image transformation using the CV2 version of OpenCV.
10+
11+
## We will install opencv and numpy using the code below:
12+
```shell
13+
pip install opencv-python
14+
pip install numpy
15+
```
16+
17+
## Now, we will import required libraries that are cv2 and numpy using the code given below:
18+
```shell
19+
import cv2
20+
import numpy as np
21+
```
22+
23+
## Here's an example of cartooning the image:
24+
![Img](https://github.com/aliya-rahmani/Amazing-Python-Scripts/blob/master/Cartooning%20Image/cartoon.png)

‎Cartooning Image/cartoon.png

1.27 MB
Loading[フレーム]

‎Cartooning Image/cartooneffect.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
import cv2
3+
import numpy as np
4+
from tkinter.filedialog import *
5+
6+
photo = askopenfilename()
7+
img = cv2.imread(photo)
8+
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 によって変換されたページ (->オリジナル) /