A simple image/video to Desmos graph converter run locally

Overview

Desmos Bezier Renderer

A simple image/video to Desmos graph converter run locally

Sample

Result

Setup

Install dependencies

apt update
apt install git python3-dev python3-pip build-essential libagg-dev libpotrace-dev pkg-config

Clone repository

git clone [email protected]:kevinjycui/DesmosBezierRenderer.git
cd DesmosBezierRenderer

Install requirements

python3 -m venv env
. env/bin/activate
pip3 install -r requirements.txt

Create a directory called frames and add images named frame%d.png where %d represents the frame-number starting from 1. To render just a single image, add a single image named frame1.png in the directory. Works best with 360p to 480p resolution (may have to lower the resolution further with more complex frames).

You can change the DYNAMIC_BLOCK, BLOCK_SIZE, and MAX_EXPR_PER_BLOCK constants in backend.py to change the number of expressions the backend will send to the frontend per call (too much will cause a memory error, too little could kill the backend with too many requests). This only really matters if you are rendering a video.

mkdir frames
...

Run backend (This may take a while depending on the size and complexity of the frames). Should eventually show that the server is running on localhost:5000.

python3 backend.py

Load index.html into a web browser and run init() in the developer console. The image should start rendering or the video should start playing at a slow rate.

Comments
  • error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    Hey, I have the path at frames\frame%d.png, but it still isn't working. Everything is a png. Everything is in "frames". IDK what's wrong with it.

    `Traceback (most recent call last):

    File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds))

    File "/usr/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args))

    File "backend.py", line 118, in get_expressions for expr in get_latex(FRAME_DIR + '/frame%d.%s' % (frame+1, FILE_EXT)):

    File "backend.py", line 92, in get_latex path = get_trace(get_contours(filename))

    File "backend.py", line 62, in get_contours gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'`

    opened by FireClaw39 28
  • Issue in backend.py usind .bmp images

    Issue in backend.py usind .bmp images

    Full error traceback:

    multiprocessing.pool.RemoteTraceback: """ Traceback (most recent call last): File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "backend.py", line 118, in get_expressions for expr in get_latex(FRAME_DIR + '/frame%d.%s' % (frame+1, FILE_EXT)): File "backend.py", line 92, in get_latex path = get_trace(get_contours(filename)) File "backend.py", line 62, in get_contours gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    """

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last): File "backend.py", line 208, in frame_latex = pool.map(get_expressions, frame_latex) File "/usr/lib/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib/python3.8/multiprocessing/pool.py", line 771, in get raise self._value cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    Instead of using png images I'd used bmp images. In backend.py I changed value of File_Exit = bmp and wrote down full path to frame folder in Frame_Dir. Excuse me for my bad English, hope that somebody can help me with my problem

    opened by Maxxxutko 7
  • Blank Desmos Page

    Blank Desmos Page

    After getting rid of all errors, when I set f=1 on the page, the grid lines remove, but the page is blank. Im using the sample image provided in the github folder. The screenshot after is also blank. What could be the issue?

    opened by Green-Thanos 7
  • NameError: name 'frame' is not defined

    NameError: name 'frame' is not defined

    Traceback (most recent call last): File "/Users/userdir/DesmosBezierRenderer/backend.py", line 108, in frame_latex = pool.map(get_expressions, frame_latex) File "/Users/userdir/bin/homebrew/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/Users/userdir/bin/homebrew/Cellar/[email protected]/3.9.5/Frameworks/Python.framework/Versions/3.9/lib/python3.9/multiprocessing/pool.py", line 771, in get raise self._value NameError: name 'frame' is not defined

    opened by Noobyte1 6
  • Error

    Error

    """ Traceback (most recent call last): File "/usr/lib/python3.8/multiprocessing/pool.py", line 125, in worker result = (True, func(*args, **kwds)) File "/usr/lib/python3.8/multiprocessing/pool.py", line 48, in mapstar return list(map(*args)) File "backend.py", line 87, in get_expressions for expr in get_latex(FRAME_DIR + '/frame%d.%s' % (frame+1, FILE_EXT)): File "backend.py", line 62, in get_latex path = get_trace(get_contours(filename)) File "backend.py", line 36, in get_contours gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    """

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last): File "backend.py", line 107, in frame_latex = pool.map(get_expressions, frame_latex) File "/usr/lib/python3.8/multiprocessing/pool.py", line 364, in map return self._map_async(func, iterable, mapstar, chunksize).get() File "/usr/lib/python3.8/multiprocessing/pool.py", line 771, in get raise self._value cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    opened by Quantummatic 6
  • How does the html file work?

    How does the html file work?

    I ran the backend and opened the html file in my browser but I didn't understand how to get it running. I wrote f=1 in the first formula line but nothing happened. I also tried pressing the play button next to f=0 but that just created a loop with f constantly increasing and decreasing. Could you please help me with this? Screenshot 2021-05-10 202124

    opened by jyotirmay-zamre 6
  • Error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    Error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'

    continuation of #4 #4 worked and I installed potrace but when i ran backend.py it came up with a new error

    Traceback (most recent call last):
      File "backend.py", line 77, in <module>
        frame_latex.append(get_latex(FRAME_DIR + '/frame%d.png' % (i+1)))
      File "backend.py", line 51, in get_latex
        path = get_trace(get_contours(filename))
      File "backend.py", line 29, in get_contours
        gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
    cv2.error: OpenCV(4.5.1) /tmp/pip-req-build-ms668fyv/opencv/modules/imgproc/src/color.cpp:182: error: (-215:Assertion failed) !_src.empty() in function 'cvtColor'
    

    pls help me

    srry about all the issues

    opened by BabyBoy666 6
  • Desmos unloads the rendered image

    Desmos unloads the rendered image

    Hi! I have been trying to run the program via WSL for sometime now, but i can't figure out why desmos keeps removing the image. After starting backend.py, I boot up the index.html, and put f=1 in the equation, to which Desmos responds with l="some value" and starts the render. But, after a couple of seconds, the l value returns to 0, and the whole desmos graph is back to empty (I have read in a issue post that a download prompt appears, but nothing of that sort happens for me). I can guarantee the image starts rendering, but disappears suddenly.

    Is there something I am doing wrong? Any help would be much appreciated.

    opened by Nekoma-Ayaya 5
  • NameError: name 'height' is not defined

    NameError: name 'height' is not defined

    Error when running backend.py and then entering f = 1 in the formula field (in the index.html). Here's the error traceback (500 error): [2021-07-04 19:20:40,644] ERROR in app: Exception on /init [GET] Traceback (most recent call last): File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/_compat.py", line 39, in reraise raise value File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functions[rule.endpoint](**req.view_args) File "/Users/codingdanny/projects/fun/DesmosBezierRenderer/backend.py", line 141, in init return json.dumps({'height': height.value, 'width': width.value, 'total_frames': len(os.listdir(FRAME_DIR)), 'download_images': DOWNLOAD_IMAGES, 'show_grid': SHOW_GRID}) NameError: name 'height' is not defined 127.0.0.1 - - [04/Jul/2021 19:20:40] "GET /init HTTP/1.1" 500 -

    opened by CodingPenguin 5
  • ModuleNotFoundError: No Module named 'flask'

    ModuleNotFoundError: No Module named 'flask'

    I can't figure out why it is not working. I have uninstalled and installed the requirements folder but it still does not work. i think it cant find any module because all the external module have yellow underlines. Also i am very new to python and html.

    opened by HyperTNT 5
  • Possible things to add

    Possible things to add

    An option to show equations like this image instead of this image also, the graph disappears a few seconds after it is finished rendering, even if there is only one frame, so that's kind of annoying and an option to make it output a file with all of the equations(with end lines after each), so its possible to copy and paste it into online desmos

    opened by ghost 4
  • error at frontend

    error at frontend

    The entire process worked properly, but when loading index.html there are no results, I got an idea to do inspect and see console, and that was showing this error:

    index.html:29 GET http://127.0.0.1:5000/init net::ERR_SOCKET_NOT_CONNECTED (anonymous) @ index.html:29

    any help?

    opened by qalassa 2
  • Backend error

    Backend error

    I'm using wsl and running the command "python3 backend.py". and I get this error:

    Desmos Bezier Renderer Junferno 2021 https://github.com/kevinjycui/DesmosBezierRenderer

    Processing 513 frames... Please wait for processing to finish before running on frontend

    --> Processing complete in 6.9 seconds

    • Serving Flask app "backend" (lazy loading)
    • Environment: production WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
    • Debug mode: off
    • Running on http://127.0.0.1:5000/ (Press CTRL+C to quit) 127.0.0.1 - - [29/Jul/2022 16:48:50] "GET /init HTTP/1.1" 200 - [2022-07-29 16:48:59,070] ERROR in app: Exception on / [GET] Traceback (most recent call last): File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/app.py", line 2447, in wsgi_app response = self.full_dispatch_request() File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/app.py", line 1952, in full_dispatch_request rv = self.handle_user_exception(e) File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask_cors/extension.py", line 165, in wrapped_function return cors_after_request(app.make_response(f(*args, **kwargs))) File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/app.py", line 1821, in handle_user_exception reraise(exc_type, exc_value, tb) File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/_compat.py", line 39, in reraise raise value File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/app.py", line 1950, in full_dispatch_request rv = self.dispatch_request() File "/home/user/DesmosBezierRenderer/env/lib/python3.10/site-packages/flask/app.py", line 1936, in dispatch_request return self.view_functionsrule.endpoint File "/home/user/DesmosBezierRenderer/backend.py", line 126, in index frame = int(request.args.get('frame')) TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'
    opened by chenyichie 2
  • running html file gives Error code: RESULT_CODE_KILLED_BAD_MESSAGE on windows

    running html file gives Error code: RESULT_CODE_KILLED_BAD_MESSAGE on windows

    After following the guide provided, I tried running the index.html file to render an image, yet every time I do so, it kills the page and gives me Error code: RESULT_CODE_KILLED_BAD_MESSAGE. The only thing I have done differently is update numpy so that I could avoid an error with potrace, and it seems to have worked fine with it updated, yet it could possibly be the issue. Is there any other issue I could be running into that could cause the error?

    opened by No-Time-To-Explain 1
  • Feature To Add - Export to Desmos Website

    Feature To Add - Export to Desmos Website

    Hi guys, Great project! One feature I would suggest is to add the option to export the official Desmos website - so one can save a frame as a file - and then share it with people???? Regards,

    opened by BarelyOutOfTuesday 4
  • Will rename ordered files

    Will rename ordered files

    In certain scenarios, like if splitting a GIF into its PNG images, it will be ordered but be named weirdly. Rather than manually changing like 300, hopefully this will change any PNG file to the desired syntax. You can upload any random PNG file you want without renaming them and they will be summarily renamed.

    opened by Atlae 3
Owner
Kevin JY Cui
McGill University, B.Sc. Computer Science. Software Development. Sometimes known as Junferno on the internet
Kevin JY Cui
Official implementation of the paper 'Details or Artifacts: A Locally Discriminative Learning Approach to Realistic Image Super-Resolution' in CVPR 2022

LDL Paper | Supplementary Material Details or Artifacts: A Locally Discriminative Learning Approach to Realistic Image Super-Resolution Jie Liang*, Hu

null 150 Dec 26, 2022
Simple converter for deploying Stable-Baselines3 model to TFLite and/or Coral

Running SB3 developed agents on TFLite or Coral Introduction I've been using Stable-Baselines3 to train agents against some custom Gyms, some of which

Gary Briggs 16 Oct 11, 2022
Code for the CVPR2021 paper "Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition"

Patch-NetVLAD: Multi-Scale Fusion of Locally-Global Descriptors for Place Recognition This repository contains code for the CVPR2021 paper "Patch-NetV

QVPR 368 Jan 6, 2023
[CVPR'21] Locally Aware Piecewise Transformation Fields for 3D Human Mesh Registration

Locally Aware Piecewise Transformation Fields for 3D Human Mesh Registration This repository contains the implementation of our paper Locally Aware Pi

sfwang 70 Dec 19, 2022
Just playing with getting VQGAN+CLIP running locally, rather than having to use colab.

Just playing with getting VQGAN+CLIP running locally, rather than having to use colab.

Nerdy Rodent 2.3k Jan 4, 2023
Locally Enhanced Self-Attention: Rethinking Self-Attention as Local and Context Terms

LESA Introduction This repository contains the official implementation of Locally Enhanced Self-Attention: Rethinking Self-Attention as Local and Cont

Chenglin Yang 20 Dec 31, 2021
Just playing with getting CLIP Guided Diffusion running locally, rather than having to use colab.

CLIP-Guided-Diffusion Just playing with getting CLIP Guided Diffusion running locally, rather than having to use colab. Original colab notebooks by Ka

Nerdy Rodent 336 Dec 9, 2022
Locally Constrained Self-Attentive Sequential Recommendation

LOCKER This is the pytorch implementation of this paper: Locally Constrained Self-Attentive Sequential Recommendation. Zhankui He, Handong Zhao, Zhe L

Zhankui (Aaron) He 8 Jul 30, 2022
Locally cache assets that are normally streamed in POPULATION: ONE

Population One Localizer This is no longer needed as of the build shipped on 03/03/22, thank you bigbox :) Locally cache assets that are normally stre

Ahman Woods 2 Mar 4, 2022
A python script to dump all the challenges locally of a CTFd-based Capture the Flag.

A python script to dump all the challenges locally of a CTFd-based Capture the Flag. Features Connects and logins to a remote CTFd instance. Dumps all

Podalirius 77 Dec 7, 2022
Video-Captioning - A machine Learning project to generate captions for video frames indicating the relationship between the objects in the video

Video-Captioning - A machine Learning project to generate captions for video frames indicating the relationship between the objects in the video

null 1 Jan 23, 2022
SAS output to EXCEL converter for Cornell/MIT Language and acquisition lab

CORNELLSASLAB SAS output to EXCEL converter for Cornell/MIT Language and acquisition lab Instructions: This python code can be used to convert SAS out

null 2 Jan 26, 2022
UpChecker is a simple opensource project to host it fast on your server and check is server up, view statistic, get messages if it is down. UpChecker - just run file and use project easy

UpChecker UpChecker is a simple opensource project to host it fast on your server and check is server up, view statistic, get messages if it is down.

Yan 4 Apr 7, 2022
Simple-Image-Classification - Simple Image Classification Code (PyTorch)

Simple-Image-Classification Simple Image Classification Code (PyTorch) Yechan Kim This repository contains: Python3 / Pytorch code for multi-class ima

Yechan Kim 8 Oct 29, 2022
SimDeblur is a simple framework for image and video deblurring, implemented by PyTorch

SimDeblur (Simple Deblurring) is an open source framework for image and video deblurring toolbox based on PyTorch, which contains most deep-learning based state-of-the-art deblurring algorithms. It is easy to implement your own image or video deblurring or other restoration algorithms.

null 220 Jan 7, 2023
A static analysis library for computing graph representations of Python programs suitable for use with graph neural networks.

python_graphs This package is for computing graph representations of Python programs for machine learning applications. It includes the following modu

Google Research 258 Dec 29, 2022
The source code of the paper "Understanding Graph Neural Networks from Graph Signal Denoising Perspectives"

GSDN-F and GSDN-EF This repository provides a reference implementation of GSDN-F and GSDN-EF as described in the paper "Understanding Graph Neural Net

Guoji Fu 18 Nov 14, 2022
Pytorch implementation of “Recursive Non-Autoregressive Graph-to-Graph Transformer for Dependency Parsing with Iterative Refinement”

Graph-to-Graph Transformers Self-attention models, such as Transformer, have been hugely successful in a wide range of natural language processing (NL

Idiap Research Institute 40 Aug 14, 2022