mirror of
https://github.com/hastagAB/Awesome-Python-Scripts.git
synced 2024-11-23 20:11:07 +00:00
Toonify Scripts (#154)
* Toonify Script Added * Update README.md * Update toonify-API-2.py
This commit is contained in:
parent
0a2ceccb4b
commit
cef99f37d3
39
Toonify/README.md
Normal file
39
Toonify/README.md
Normal file
|
@ -0,0 +1,39 @@
|
|||
## HOW TO USE
|
||||
|
||||
#### Using OpenCv ([link](./toonify-opencv.py))
|
||||
|
||||
|
||||
- To just view the image
|
||||
```python
|
||||
python3 toonify-opencv.py -i img_path
|
||||
```
|
||||
|
||||
|
||||
- To view and download the image
|
||||
```python
|
||||
python3 toonify-opencv.py -i img_path -o download_path
|
||||
```
|
||||
|
||||
#### Using Toonify-API(by DeepAI)
|
||||
|
||||
|
||||
##### For local image ([link](./toonify-API-1.py))
|
||||
|
||||
```python
|
||||
python3 toonify-API-1.py -i img_path -k api_key
|
||||
|
||||
```
|
||||
|
||||
##### For URLS ([link](./toonify-API-2.py))
|
||||
|
||||
```python
|
||||
python3 toonify-API-2.py -i img_path -k api_key
|
||||
|
||||
```
|
||||
|
||||
> NOTE: The toonify image works well with .jpg format and might give some problem with other formats
|
||||
|
||||
|
||||
For more details on toonify API:
|
||||
|
||||
[toonify API doc](https://deepai.org/machine-learning-model/toonify)
|
18
Toonify/toonify-API-1.py
Normal file
18
Toonify/toonify-API-1.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import argparse
|
||||
import requests
|
||||
|
||||
aq = argparse.ArgumentParser()
|
||||
aq.add_argument('-i', '--input', required=True, help="input image path")
|
||||
|
||||
aq.add_argument('-k', '--apikey', required=True, help="api-key")
|
||||
|
||||
args = vars(aq.parse_args())
|
||||
|
||||
r = requests.post(
|
||||
"https://api.deepai.org/api/toonify",
|
||||
files={
|
||||
'image': open(args['input'], 'rb'),
|
||||
},
|
||||
headers={'api-key': args['apikey']}
|
||||
)
|
||||
print(r.json()['output_url'])
|
18
Toonify/toonify-API-2.py
Normal file
18
Toonify/toonify-API-2.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
import argparse
|
||||
import requests
|
||||
|
||||
aq = argparse.ArgumentParser()
|
||||
aq.add_argument('-i', '--input', required=True, help="input image link")
|
||||
|
||||
aq.add_argument('-k', '--apikey', required=True, help="api-key")
|
||||
|
||||
args = vars(aq.parse_args())
|
||||
|
||||
r = requests.post(
|
||||
"https://api.deepai.org/api/toonify",
|
||||
files={
|
||||
'image': args['input'],
|
||||
},
|
||||
headers={'api-key': args['apikey']}
|
||||
)
|
||||
print(r.json()['output_url'])
|
32
Toonify/toonify-opencv.py
Normal file
32
Toonify/toonify-opencv.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
# importing libraries
|
||||
import cv2
|
||||
import numpy as np
|
||||
import argparse
|
||||
|
||||
aq = argparse.ArgumentParser()
|
||||
|
||||
aq.add_argument('-i', '--input', required=True, help="input image path")
|
||||
|
||||
aq.add_argument('-o', '--output', help="path where you want to download the image")
|
||||
|
||||
args = vars(aq.parse_args())
|
||||
# reading image
|
||||
img = cv2.imread(args['input'])
|
||||
|
||||
# Edges
|
||||
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
||||
gray = cv2.medianBlur(gray, 5)
|
||||
edges = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_MEAN_C,
|
||||
cv2.THRESH_BINARY, 9, 9)
|
||||
|
||||
# Cartoonization
|
||||
color = cv2.bilateralFilter(img, 2, 250, 250)
|
||||
cartoon = cv2.bitwise_or(color, color, mask=edges)
|
||||
|
||||
if(args['output']):
|
||||
cv2.imwrite(args['output'], cartoon)
|
||||
|
||||
|
||||
cv2.imshow("Cartoon", cartoon)
|
||||
cv2.waitKey(0)
|
||||
cv2.destroyAllWindows()
|
Loading…
Reference in New Issue
Block a user