-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.cpp
80 lines (48 loc) · 2.05 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <iostream>
#include <string>
int main() {
cv::VideoCapture webCam(0);
cv::Mat image;
cv::Mat imageDownScaled;
cv::Mat imageGrayScale;
cv::Mat imageBlackAndWhite;
int pixelColour;
std::string character;
cv::Size size(1000, 512);
cv::Scalar colour(0, 0, 0);
int spacing = 10;
cv::Point textLocation;
cv::Scalar textColour;
while (true) {
cv::Mat ASCIIImage(size, CV_8UC3, colour);
webCam.read(image);
cv::resize(image, imageDownScaled, cv::Size(89, 40), cv::INTER_LINEAR);
cv::cvtColor(imageDownScaled, imageGrayScale, cv::COLOR_BGR2GRAY);
for (int i = 0; i < imageGrayScale.rows; i++) {
for (int j = 0; j < imageGrayScale.cols; j++) {
pixelColour = imageGrayScale.at<uchar>(i,j);
if (pixelColour < 64) {
character = ".";
} else if (pixelColour >= 64 && pixelColour < 128) {
character = "*";
} else if (pixelColour >= 128 && pixelColour < 192) {
character = "x";
} else if (pixelColour >= 192 && pixelColour < 256) {
character = "#";
}
textLocation.x = j * spacing;
textLocation.y = i * spacing * 1.5;
textColour[0] = 255;
textColour[1] = 255;
textColour[2] = 255;
cv::putText(ASCIIImage, character, textLocation, cv::FONT_HERSHEY_PLAIN, 1, textColour, 1);
}
}
cv::imshow("ASCII feed", ASCIIImage);
cv::waitKey(1);
}
//cv::imshow("Image", imageGrayScale);
return 0;
}