Coder Social home page Coder Social logo

symisc / ascii_art Goto Github PK

View Code? Open in Web Editor NEW
698.0 26.0 79.0 212 KB

Real-Time ASCII Art Rendering Library

Home Page: https://pixlab.io/art

License: GNU General Public License v2.0

C 100.00%
machine-learning rendering image-processing algorithms ascii-art library ascii-glyphs tree graphics embedded

ascii_art's Introduction

ASCII Art

Real-Time ASCII Art Rendering Library - Live demo: https://art.pixlab.io

Integration Reference Guide: https://pixlab.io/art

ASCII Art is a single file C/C++ library that let you transform an input image or video frame into printable ASCII characters at real-time using a single decision tree. Real-time performance is achieved by using pixel intensity comparison inside internal nodes of the tree.

ASCII Camera Now Availabe On Unity Asset Store: https://assetstore.unity.com/packages/slug/165558

For a general overview on how the algorithm works, check the bottom of the demo page.

Output ASCII art is a related (and older) graphic design technique for producing images from printable characters. This implementation is based on the paper:

N. Markus, M. Fratarcangeli, I. S. Pandzic and J. Ahlberg, "Fast Rendering of Image Mosaics and ASCII Art", Computer Graphics Forum, 2015, http://dx.doi.org/10.1111/cgf.12597

Getting started

Embedding the library in your application is straightforward. All you have to do is drop the ascii_art.c and its header file in your source tree plus the hex model that can be downloaded here and perform the following API calls successively:

  1. Call AsciiArtInit first to initialize the ascii_render structure defined in the ascii_art.h header file.
  2. Prepare the image to be processed by converting it to the grayscale colorspace. You can rely on some external library like OpenCV cvtColor or the built-in AsciiArtLoadImage interface.
  3. Allocate a buffer big enough to hold the entire ASCII text output. The amount of bytes needed is returned via the AsciiArtTextBufSize interface. This step is optional if you do not want a text output but instead a binary ASCII glyphs image.
  4. Finally, transform the input image into ASCII glyphs/text via AsciiArtRender.

Below is a simple C program that demonstrates a typical usage of the ASCII Art C/C++ interfaces.

#include "ascii_art.h"

ascii_render sRender; /* Stack allocated */
	
/* Initialize the render structure */
AsciiArtInit(&sRender);
	
/* Load an image from disk */
int width, height;
unsigned char *zBlob = AsciiArtLoadImage(argv[1],&width,&height);
if( zBlob == 0 ){
	puts("Cannot load image");
	return;
}
	
/* Allocate a buffer big enough to hold the entire text output */
size_t nBytes = AsciiArtTextBufSize(&sRender, width, height);
unsigned char *zText = malloc(nBytes);
	
/* Finally, process */ 
AsciiArtRender(&sRender, zBlob, &width, &height, zText,1);
/* zBlob[] hold the binary ASCII glyphs now */
	
/* Output the result */
fwrite(zText, sizeof(char), nBytes, stdout);
	
/* Release memory */
free(zText);
free(zBlob);

sample.c source code

Resources

ascii_art's People

Contributors

symisc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ascii_art's Issues

`#ifdev` is causing undefined reference to `main' (I want to use AsciiArtLoadImage)

#endif /* STB_IMAGE_IMPLEMENTATION */

^this statement is causing

/usr/bin/ld: /usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/Scrt1.o: in function `_start':
(.text+0x24): undefined reference to `main'
collect2: error: ld returned 1 exit status

while I have defined main where I'm trying to use AsciiArtLoadImage, such that

int main() {
     const char* path = "me.bmp";
     int* h; int* w ;
     char* img = AsciiArtLoadImage(path, h, w);
     return 0;
 
 }

can work. Can anyone tell me how this scenario can work?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.