{"id":18828404,"url":"https://github.com/dealfonso/pycanvashanddraw","last_synced_at":"2026-01-22T18:30:15.299Z","repository":{"id":62592757,"uuid":"519549264","full_name":"dealfonso/pycanvashanddraw","owner":"dealfonso","description":"This is a utility to draw a set of points and to generate an image as if it was hand drawn by a human.","archived":false,"fork":false,"pushed_at":"2022-07-30T15:20:38.000Z","size":798,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2024-12-30T06:11:52.763Z","etag":null,"topics":["drawing","handdraw","image","python","python-library"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dealfonso.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-07-30T15:14:13.000Z","updated_at":"2022-08-01T06:52:06.000Z","dependencies_parsed_at":"2022-11-03T23:00:25.878Z","dependency_job_id":null,"html_url":"https://github.com/dealfonso/pycanvashanddraw","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dealfonso%2Fpycanvashanddraw","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dealfonso%2Fpycanvashanddraw/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dealfonso%2Fpycanvashanddraw/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dealfonso%2Fpycanvashanddraw/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dealfonso","download_url":"https://codeload.github.com/dealfonso/pycanvashanddraw/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239763648,"owners_count":19692812,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["drawing","handdraw","image","python","python-library"],"created_at":"2024-11-08T01:24:55.968Z","updated_at":"2026-01-22T18:30:15.244Z","avatar_url":"https://github.com/dealfonso.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Canvas Hand Draw\nThis is a utility to draw a set of points and to generate an image as if it was hand drawn by a human.\n\nThe need of having this component comes from an IA application, where a drawing is captured from a hand device (i.e. tablet or smartphone), and then the image is classified using a Neural Network. The points are captured to show the drawing to a human, who makes the initial classification to train the NN.\n\nThe effect is shown in the next image:\n\n![Osito](img/osito.gif)\n\nAnd using the same input data, it is possible to obtain different resolutions, colors, etc. by varying the settings:\n\n![Osito 128](img/osito.128.gif)\n![Osito 128 pen size 4](img/osito.128.4.gif)\n\n\u003e Most of the code of this library is a port to python of library [canvashanddraw](https://github.com/dealfonso/canvashanddraw).\n\n**Technical facts**\n- Includes tools to optimize the number of points, by skipping those that are too near to the line described by the adjacents points.\n- It is possible to simulate the drawing dynamics by considering that the distance between the points is related to the speed of drawing. In that case, the faster a line is, the thinner it will be drawn, to simulate a ball pen.\n\n## Installing\n\n### Using pip\n\nThe easier method to install `canvashanddraw` is using pip:\n\n```console\npip install canvashanddraw\n```\n\n### From sources\n\nThe alternate method is to clone the repo, install the dependencies and install by hand\n\n```console\n$ git clone https://github.com/dealfonso/pycanvashanddraw\n$ cd pycanvashanddraw\n$ pip install pillow imageio aggdraw\n$ python setup.py install\n```\n\n### Dependencies\n\nThe dependencies from `canvashanddraw` are installed when installing from pip, but you can also install them by hand:\n\n```console\npip install pillow imageio aggdraw\n```\n\n**WARNING:** `canvashanddraw` depends on [`aggdraw`](https://github.com/pytroll/aggdraw) library, which is also in pip (so it is automatically installed when installing from pip). The problem is that at the time of writing this text, the current version of that library does not produce the best results. Instead, my advise is to remove the version installed using pip and to install the latest `aggdraw` by hand:\n\n```console\n$ pip uninstall aggdraw\n...\n$ mkdir -p ./tmp\n$ cd ./tmp\n$ git clone https://github.com/pytroll/aggdraw\n$ cd aggdraw\n$ python setup.py build_ext -i\n$ python setup.py install\n```\n\n## Using\n\nCanvas Hand Draw is conceived both as a command line utility and a library so that you can include it in your application.\n\n### Command Line Utility\n\nIf you have a set of points in a json file (e.g. file \"five.json\")\n\n**five.json**\n\n```json\n[{\"x\": 211.33, \"y\": 130}, {\"x\": 210, \"y\": 130}, {\"x\": 199.33, \"y\": 130}, {\"x\": 177.66, \"y\": 130}, {\"x\": 154.33, \"y\": 130}, {\"x\": 135.33, \"y\": 130.66}, {\"x\": 124.33, \"y\": 132.33}, {\"x\": 120, \"y\": 133}, {\"x\": 118.66, \"y\": 133.33}, {\"x\": 118.66, \"y\": 133.66}, {\"x\": 118.66, \"y\": 134}, {\"x\": 118.66, \"y\": 138.66}, {\"x\": 118.66, \"y\": 144.33}, {\"x\": 118.33, \"y\": 159.33}, {\"x\": 116.66, \"y\": 176.66}, {\"x\": 114.66, \"y\": 191.33}, {\"x\": 113.33, \"y\": 201.33}, {\"x\": 112.66, \"y\": 206.33}, {\"x\": 112.33, \"y\": 208.33}, {\"x\": 112.33, \"y\": 209.33}, {\"x\": 112.33, \"y\": 210}, {\"x\": 113, \"y\": 209.66}, {\"x\": 118, \"y\": 208.66}, {\"x\": 131.33, \"y\": 205.66}, {\"x\": 150.66, \"y\": 202.33}, {\"x\": 171, \"y\": 200.33}, {\"x\": 186.66, \"y\": 200}, {\"x\": 197.33, \"y\": 200.66}, {\"x\": 205.33, \"y\": 203.66}, {\"x\": 210.33, \"y\": 207.33}, {\"x\": 213, \"y\": 212}, {\"x\": 213.66, \"y\": 219.66}, {\"x\": 212, \"y\": 230.33}, {\"x\": 208.33, \"y\": 241}, {\"x\": 202.66, \"y\": 251}, {\"x\": 195.66, \"y\": 260.66}, {\"x\": 183.33, \"y\": 272.33}, {\"x\": 173, \"y\": 279.66}, {\"x\": 165.33, \"y\": 283.33}, {\"x\": 150, \"y\": 289}, {\"x\": 137, \"y\": 292.33}, {\"x\": 127.66, \"y\": 294.66}, {\"x\": 122, \"y\": 295.66}, {\"x\": 119.33, \"y\": 296}, {\"x\": 119, \"y\": 296}]\n```\n\nYou can run the next command line:\n\n```console\n$ canvashanddraw -i five.json -o five.png -w 64\n```\n\nTo get the next drawing:\n\n![Five](img/five.png)\n\n### In your application\n\nHaving the same file `five.json`, you can use the next piece of code\n\n```python\nfrom canvashanddraw.points import Points\nfrom canvashanddraw.drawhelper import DrawHelper, Options\nimport json\n\npoints = json.load(open('five.json'))\npoints = Points(points)\nhelper = DrawHelper(points, Options(canvasSize = 64, canvasMargin = 4, lineWidth = 4, lineColor = \"#f00\"))\nhelper.draw().save('five-red.png')\n```\n\nTo generate the next drawing:\n\n![Five Red](img/five-red.png)\n\n## Defining the points\n\nThe points used to draw are defined in user-scale and they are later scaled to the target output.\n\nMoreover, a single draw may consist of multiple drawings. In such case, the array of points used to define the drawing should include a `null` or an empty point (e.g. `[]`) to separate the drawings:\n\n```json\n[{\"x\": 211.33, \"y\": 130}, {\"x\": 210, \"y\": 130}, {\"x\": 199.33, \"y\": 130}, {\"x\": 177.66, \"y\": 130}, null, {\"x\": 135.33, \"y\": 130.66}, {\"x\": 124.33, \"y\": 132.33}, {\"x\": 120, \"y\": 133}, {\"x\": 118.66, \"y\": 133.33}, {\"x\": 118.66, \"y\": 133.66}, [], {\"x\": 165.33, \"y\": 283.33}, {\"x\": 150, \"y\": 289}, {\"x\": 137, \"y\": 292.33}, {\"x\": 127.66, \"y\": 294.66}, {\"x\": 122, \"y\": 295.66}, {\"x\": 119.33, \"y\": 296}, {\"x\": 119, \"y\": 296}]\n```\n\n## Options\n\nThere are multiple options to customize your results: the line width, the target resolution, the color, etc.\n\nIf using the CLI app, you are invited to use option `--help` to get the information about the different options.\n\nWhen using the library, please check class `canvashanddraw.drawhelper.Options`:\n\n```python\nclass Options:\n    \"\"\"A class to represent the options for drawing\"\"\"\n    canvasSize = 64\n    canvasMargin = 4\n    lineWidth = 4\n    lineColor = '#000000'\n    drawDynamics = True\n    antiAliasing = True\n    keepAspectRatio = True\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdealfonso%2Fpycanvashanddraw","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdealfonso%2Fpycanvashanddraw","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdealfonso%2Fpycanvashanddraw/lists"}