├── Procfile ├── README.md ├── static ├── favicon.ico ├── upload_logo.png ├── download_logo.png ├── uploads │ └── raccoon-1.jpg └── downloads │ └── raccoon-1.jpg ├── requirements.txt ├── app.py ├── index.html └── templates └── index.html /Procfile: -------------------------------------------------------------------------------- 1 | web: gunicorn app:app -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Image-to-pencil-Sketch-Converter 2 | -------------------------------------------------------------------------------- /static/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Image-to-pencil-Sketch-Converter/HEAD/static/favicon.ico -------------------------------------------------------------------------------- /static/upload_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Image-to-pencil-Sketch-Converter/HEAD/static/upload_logo.png -------------------------------------------------------------------------------- /static/download_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Image-to-pencil-Sketch-Converter/HEAD/static/download_logo.png -------------------------------------------------------------------------------- /static/uploads/raccoon-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Image-to-pencil-Sketch-Converter/HEAD/static/uploads/raccoon-1.jpg -------------------------------------------------------------------------------- /static/downloads/raccoon-1.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DURGESH716/Image-to-pencil-Sketch-Converter/HEAD/static/downloads/raccoon-1.jpg -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | click==7.1 2 | Flask==1.1 3 | gunicorn==20.0 4 | itsdangerous==1.1 5 | Jinja2==2.11 6 | MarkupSafe==1.1 7 | numpy==1.19 8 | opencv-python==4.4.0 9 | Werkzeug==1.0 10 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | import cv2 2 | import os 3 | from flask import Flask,render_template,request,url_for,redirect,send_from_directory 4 | from werkzeug.utils import secure_filename 5 | 6 | UPLOAD_FOLDER = 'static/uploads/' 7 | DOWNLOAD_FOLDER = 'static/downloads/' 8 | ALLOWED_EXTENSIONS = {'png','jpg','jpeg','bmp'} 9 | 10 | app = Flask(__name__, static_url_path="/static") 11 | DIR_PATH = os.path.dirname(os.path.realpath(__file__)) 12 | app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER 13 | app.config['DOWNLOAD_FOLDER'] = DOWNLOAD_FOLDER 14 | # limit upload size upto 10mb 15 | app.config['MAX_CONTENT_LENGTH'] = 10 * 1024 * 1024 16 | 17 | def allowed_file(filename): 18 | return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS 19 | 20 | @app.route('/', methods=['GET', 'POST']) 21 | def index(): 22 | if request.method =='POST': 23 | if 'file' not in request.files: 24 | print('No file attached in the request') 25 | return redirect(request.url) 26 | file=request.files['file'] 27 | if file.filename == '': 28 | print("no file selected..") 29 | return redirect(request.url) 30 | if file and allowed_file(file.filename): 31 | filename = secure_filename(file.filename) 32 | file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) 33 | process_file(os.path.join(app.config['UPLOAD_FOLDER'], filename), filename) 34 | return redirect(url_for('uploaded_file', filename=filename)) 35 | return render_template('index.html') 36 | 37 | def process_file(path,filename): 38 | sketch(path,filename) 39 | 40 | def dodgeV2(image, mask): 41 | return cv2.divide(image, 255-mask, scale=256) 42 | 43 | def sketch(path,filename): 44 | img=cv2.imread(path) 45 | #cv2.imshow(img) 46 | img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) 47 | img_gray_inv = 255 - img_gray 48 | img_blur = cv2.GaussianBlur(img_gray_inv, ksize=(21, 21), 49 | sigmaX=0, sigmaY=0) 50 | img_blend = dodgeV2(img_gray, img_blur) 51 | #sketch = 'output_sketch_'+filename 52 | cv2.imwrite(os.path.join(app.config['DOWNLOAD_FOLDER'] + filename),img_blend) 53 | 54 | @app.route('/uploads/') 55 | def uploaded_file(filename): 56 | return send_from_directory(app.config['DOWNLOAD_FOLDER'], filename, as_attachment=True) 57 | 58 | if __name__ == '__main__': 59 | #app.run() 60 | port = int(os.environ.get("PORT", 5000)) 61 | app.run(host='0.0.0.0', port=port) -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Image-to-pencil-Sketch 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 39 |
40 |
41 |

Convert your pictures to sketches

42 |
Only Images of .png/.jpg/.jpeg/.bmp format are allowed.
43 |
44 |
45 |
46 | 47 | 48 |
49 |
50 |
51 |
52 |
53 | 54 | 55 | -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | Image-to-pencil-Sketch 12 | 13 | 15 | 16 | 17 | 18 | 19 | 20 | 39 |
40 |
41 |

Convert your pictures to sketches

42 |
Only Images of .png/.jpg/.jpeg/.bmp format are allowed.
43 |
44 |
45 |
46 | 47 | 48 |
49 |
50 |
51 |
52 |
53 | 54 | 55 | --------------------------------------------------------------------------------