![]() It provides lots of fancy skills to control the terminals: adding text, erasing it, changing its appearance, etc. curses is a library who supplies a terminal-independent screen-painting and keyboard-handling facility for text-based terminals. I use curses to deal with the refreshing problem. If we just start playing music and then do some normal display in terminal, there is a high probability that it will be a mess: the video is not fluid at all and the music is misaligned. However, the flash during two ASCII images is a big problem, and the synchronization with the sound is another. The basic idea is to display the generated results one by one, with or without the music. But to play a ASCII art video, we will need more attention. To generate ASCII art from a video, it’s quite simple. close () if ( k & 0xff = ord ( 'q' )): break cap. COLOR_BGR2RGB )) trans_data = transform_ascii ( frame ) print ( trans_data ) tmp. resize ( frame, ( 0, 0 ), fx = wratio, fy = hratio ) frame = Image. The code to convert a video to a series of ASCII art files is as below:ĭef convert_video (): fn = input ( "input file name : " ) hratio = float ( input ( "input height zoom ratio(default 1.0) : " ) or "1.0" ) wratio = float ( input ( "input width zoom ratio(default 1.0) : " ) or "1.0" ) cap = cv2. To do so, we need to import OpenCV library, which is a famous cross-platform computer vision library. And for each frame of a video, we do exactly the same process and save the result in a file. So, converting video to ASCII art is basically the same with what we did in the previous part, except that we have to process the pictures one by one. Convert video to ASCII artĮssentially, video is what many pictures displayed one after the other in the background sound. It’s definitely not the best result we can get, but, you’ve got the idea. close ()įor example, here’s what it do to a random image of galaxy. size, ' ' ) fo = open ( 'result.txt', 'w' ) trans_data = transform_ascii ( image_file ) print ( trans_data ) fo. size * hratio ))) print ( u 'Size info:', image_file. Here’s the code:ĭef convert_image (): fn = input ( "input file name : " ) hratio = float ( input ( "input height zoom ratio(default 1.0) : " ) or "1.0" ) wratio = float ( input ( "input width zoom ratio(default 1.0) : " ) or "1.0" ) image_file = Image. So we loop through each pixel in the image and store the converted result in memory. So suppose we have n characters in the dictionary, each character will correspond to 256/n values. So the function convert() is used to transform it to a gray image.Īfter the transformation, we need to map the gray value to a certain character in CODE_LIB, which is the dictionary that we have previously decided to use in ASCII art. However we won’t be needing the values of “RGB”. One thing important, for color images, regardless of whether the image format is PNG, BMP, or JPG, in PIL, after the Open() of the Image module is opened, the mode of the returned image object is “RGB”. ![]() ![]() The main idea of this part is to map the gray value of each pixel in the image to the value corresponding to the dictionary we defined. Here I’ll show some code and explain how it works. With only about 100 lines of code, we can generate and displaye the ASCII art. More interestingly, ASCII art is actually very easy to generate in python. simple characters, amazing and yet expressive. It has now become an interesting and somewhat retro artistic expression.įor example, an image of ASCII art of Jackie Chan on the Internet is shown below. However, because of the rapid development of technology, we don’t really need ASCII art to be used to transfer image information any more. It is originally used because text is more stable and faster than images. ASCII art is a graphic design technique that uses computers for presentation and consists of pictures pieced together from the 95 printable (from a total of 128) characters defined by the ASCII Standard from 1963 and ASCII compliant character sets with proprietary extended characters. ![]() This is surely something interesting to talk about. This time I will be talking about a small project that can be used to generate ASCII Art from images or videos, and eventually play the generated ASCII video with music on. It has been a long time since the last time I wrote a blog.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |