Pictures, and you can play like this.

Source: Internet
Author: User

A few days ago, I was in the Linux software, found a more fun software, called Aview, he can convert a picture into a text pattern. As a result, we recommend software to our colleagues. Gy classmates feel interesting, and then home with the script and program also made the same effect.

The whole good, the old Wang two weeks ago just told you about the image processing and text recognition, so stir hot, with the previous program, add a few lines of code, on the same effect. Let's show you the results first:

Original:


Effects in the shell after conversion :

Yes, it feels OK ~

as programmers, there is a little bit of curiosity, want to know how to do it? Look down with Lao Wang.

• Main process

The above is the main process code, relatively simple, about the line. Here's how:

1, read out the documents from the data of the project catalogue ;

2, in order to output better in the Shell , the file to do a long-width compression;

3. Read the RGB valueof each pixel of the image ;

4, RGB to do grayscale processing;

5. Print the grayscale image into text output.

What, isn't it easy? Specifically, we go down:

• Read files

Reading a file is simple, just use the system library and read the file into memory.

• File Length-width compression

We take the read file and do the long-width compression. I write functions that support the length-to-width ratio compression. When compressing, it is possible to transform itself through coordinates, or it can be implemented by the function of the system. I'm just here to figure out the simple, system function.


• Read pixels RGB value

we will image each pixel of the RGB values are read out and placed in a two-dimensional array for easy processing.

• Grayscale

The next step is to convert each pixel's RGB values are converted to grayscale values. Gray value, in fact, is to make a weighted RGB tricolor, also equivalent to the value of the Y-channel in YUV . Lao Wang in the previous "How to search Pictures" in detail about how to do grayscale, if you want to learn more about, you can subscribe to the old Wang:simplemain for inspection.

• Print out the grayscale values

Well, we have the gray value, the last step is to turn him into text printout (Lao Wang can't wait ... )

We first define some characters that are used to show different shades of gray. Because the range of grayscale values is [0,255], the larger thevalue, the whiter the brighter, and the smaller the value, the darker it becomes. Because our shell background is black, when I define a character, I give a large gray value to a character that looks more plump.

we then map the grayscale values to the corresponding characters. For example, we have a total of five characters, then each of the gray values corresponds to one character: Grayscale value [0,11], first character - dot [.] ; grayscale values [12,23]-> A second character - comma [,]; Grayscale value [252,255], and the first character [@]

as long as the final result is printed out to Shell (or console) to get our article the beginning of the, is not very simple ah, here the old Wang printed some pictures:

Actually understand this principle, also can put the video in the way of text play out. The principle is to extract pictures of each frame of the video, and then draw with text. Just when drawing, pay attention to the problem of line wrapping and fallback.

Well, Lao Wang is a whim today, so the article is very short, it is here ~ ^_^

If you are interested in an old king who only speaks technical dry, please pay attention to Lao Wang's public number: Simplemain


Pictures, and you can play like this.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.