How to convert photo to a vector drawing I am using the following code to convert photo to a drawing:
import cv2
import numpy as np

img = cv2.imread(&quot;adventure.jpeg&quot;)

# 1) 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)

# 2) Color
color = cv2.bilateralFilter(img, 9, 300, 300)

# 3) Cartoon
cartoon = cv2.bitwise_and(color, color, mask=edges)


cv2.imshow(&quot;Image&quot;, img)
cv2.imshow(&quot;Cartoon&quot;, cartoon)
cv2.imshow(&quot;color&quot;, color)
cv2.imshow(&quot;edges&quot;, edges)
cv2.waitKey(0)
cv2.destroyAllWindows()

the result is as follows:

However I do not want the above result, what I want is this:

How do I do it using opencv / deep learning ?
This problem is known as "style transfer", and deep learning can achieve some pretty amazing results.



Here's a fantastic GitHub repo with an easy-to-use implementation of neural style transfer (usage instructions).  I think you'll have better luck using a pre-built model like this rather than training your own.

If you want to train your own, this repo might be a good starting point.  It has a training script included, you'll just need a bunch of training images and a style image.