Skip to content
python app to turn a photograph into a cartoon
Python Dart
Branch: master
Clone or download
Pull request Compare This branch is 17 commits ahead, 2 commits behind danmacnish:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
client
img
install
server
.dockerignore
.gitignore
LICENSE
README.md

README.md

Cartoonify REST Server

This is a REST server based on the Cartoonify project. The aim of this project is convert photographs into cartoons. First, the main objects of the scene are detected using a Single Shot Multibox Detector (SSD). In particular, a MobilenetSSD model was implemented in tensorflow and trained with the Coco dataset. Then, drawings from the Google QuickDraw dataset are randomly picked to replace the identified objects.

In this fork, as it is intended to run in a desktop computer, all the references to raspberry pi and arduino were removed.

This project contains a REST server written in Flask that exposes only two requests:

  • URL: /cartoon

    • Method: POST
    • Objective: converts the input image into a cartoon
    • Data params: { 'image': 'base64 encoded string with the image data'}
    • Success response:
      • Code: 200
      • Content: { 'cartoon': 'base64 encoded string with the cartoon data'}
    • Error response:
      • Code: 400
      • Content: {'msg': 'cause of the error (Invalid image format/no image was provided)'}
  • URL: /time

    • Method: GET
    • Objective: returns the current time for testing purpouses
    • Data params: None
    • Success response:
      • Code: 200
      • Content: Current time as a string

Installation

This project was tested on Debian GNU/Linux, Windows 10 Home and macOS High Sierra. The global requirements are:

  • OS 64 bits (non virtualized)

  • Python 3.6

  • Gtk3

GNU/Linux 64 bits

All the dependencies might have been installed previously in your computer so you only have to run the following commands from terminal:

  1. Install project dependencies:

    $ pip3 install -r install/requirements_desktop.txt

  2. Download the cartoon dataset (~1.4GB) and the tensorflow model (~30MB) by running:

    $ python3 install/download_assets.py

macOS High Sierra 64 bits

Install the main dependencies using brew. Once you have brew installed in your computer, run the following commands in a terminal:

$ brew install gtk+3 cairo py3cairo

The current version of python3 available in brew is 3.7 so, if this version is installed, you have to override it by typing:

$ brew unlink python

Then, install python 3.6 using the following formula:

$ brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/f2a764ef944b1080be64bd88dca9a1d80130c558/Formula/python.rb

Finally, install the project dependencies, datasets and models:

$ pip3 install -r install/requirements_desktop.txt

$ python3 install/download_assets.py

Note: the python version can be changed with the following command:

$ brew switch python 3.7.0

Windows 10 64 bits

  1. Download and install python 3.6 windows x86_64 web-based installer from here.

Important: mark the "Add Python 3.6 to PATH" checkbox in the first step!

Python 3.6 installation

To check the installation, open a Windows Command Prompt and type:

C:\\Users\User> python

  1. Download and install gtk+3 from here. Select the gtk3-runtime-XXX-win64.exe file.

  2. Download and install Visual C++ Redistributable for Visual Studio 2015

  3. Close the Windows Command Prompt and open it again.

  4. Install the project dependencies, datasets and models:

C:\Users\User> pip install -r install\requirements_desktop.txt

C:\Users\User> python install\download_assets.py

Standalone execution

You can run the Cartoonify project in a standalone mode. In the cartoonifydirectory, just execute:

$ python3 command_line.py path_to_image

If everything is ok, the original image and its cartoon version will be shown in a window.

Output of the standalone program in Win10

Note: In GNU/Linux, if no window is shown, install display, an image viewer from the package imagemagick.

REST server

For running the REST server, go to the server directory and create a environment variable for the flask app:

$ export FLASK_APP=server.py # GNU/Linux & macOS

C:\Users\User\cartoonify\server\> SET FLASK_APP=server.py # Windows

Run the server with the following command:

$ python3 -m flask run # GNU/Linux & macOS

C:\Users\User\cartoonify\server\> python -m flask run # Windows

To shutdown the server, hit Ctrl+C.

Python client

It was also implemented a client program, written in python, that receives a path to an image as an argument, makes the http request to the flask server and receives the cartoon image.

In GNU/Linux and macOS, execute in a new terminal:

$ python3 client.py path_to_image

In Windows, execute in a new Command prompt:

C:\Users\User\cartoonify\client\> python client.py path_to_image

Output of the client program in macOS

Dart client

Another client was implemented in dart. This script opens a file, makes the http request to the flask server and writes the cartoon image to an output file. Both input and output paths are hardcoded in the dart script (client/samples/image.jpg and client/samples/cartoon.png).

In order to test this client, install the dart framework or use the dart interpreter installed with flutter. Go to the dart client directory and execute pub get (pub is located in the bin directory of the dart sdk) to install the package dependencies. Finally, run the client as follows and check the output in the client\samples directory:

dart client.dart

You can’t perform that action at this time.