Answer the question
In order to leave comments, you need to log in
How to convert an image to text format?
It is necessary to write a program that receives an image file of the BMP type as input and converts it to a text format. In text format, display white as a space and black as an '8'. How can this be implemented? Convert to black and white first, then render it as a matrix? I would like to see at least small pieces of code, because I don’t understand how it all will look like.
Answer the question
In order to leave comments, you need to log in
The very idea of converting an image to monochrome (as I understand it, you initially need it), it's something like this:
I'm writing in c # Since I'm not very familiar with ++.
Color _pixelColor = img.GetPixel(x, y);
int _MonoNum = (_pixelColor.R + _pixelColor.G + _pixelColor.B)/3;
if (MonoNum<128) //if black color
{
matrix[x, y] = Convert.ToInt32("1");
}
else //white color
{
matrix[x, y] = Convert.ToInt32("0");
}
for (int x = 0; x < GlobalConst.width; x++)
for (int y = 0; y < GlobalConst.height; y++)
Judging by the description, you need a library for ascii graphics.
aalib
writing html5 generator ascii art
Everything is pretty simple. We take a picture, convert it to grayscale , split it into a grid (say 10*10 pixels), calculate the average brightness value for this piece and determine if the brightness is above the threshold value (for example 128) then this is a gap, if it is lower or equal, then our symbol.
Did you copy part of the text of the order?
In fact, the image is a matrix of pixels.
You can convert to black and white by determining the color of the pixel, if more than 8000000 (not exactly) it means white, if less then black.
We pass through the matrix, determining the color and writing along the way, that's all.
Google for the phrase ascii art generator
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question