-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWebCam.cpp
More file actions
82 lines (60 loc) · 1.37 KB
/
WebCam.cpp
File metadata and controls
82 lines (60 loc) · 1.37 KB
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
81
82
// ESCAPI: https://github.com/jarikomppa/escapi
#define CONSOLE_GAME_ENGINE_IMPLEMENTATION
#include "ConsoleGameEngine.hpp"
#include "escapi.h"
constexpr int nVariates = 16;
class Example : public ConsoleGameEngine
{
public:
Example()
{
sAppName = L"Example";
sFont = L"Times New Roman";
}
SimpleCapParams capture;
int nCameras;
private:
union Color
{
int rgb;
uint8_t c[4];
};
protected:
bool OnUserCreate() override
{
nCameras = setupESCAPI();
if (nCameras == 0)
return false;
capture.mWidth = ScreenWidth();
capture.mHeight = ScreenHeight();
capture.mTargetBuf = new int[capture.mWidth * capture.mHeight];
if (initCapture(0, &capture) == 0)
return false;
return true;
}
bool OnUserUpdate(float fDeltaTime) override
{
doCapture(0);
while (isCaptureDone(0) == 0) {}
for (int x = 0; x < ScreenWidth(); x++)
for (int y = 0; y < ScreenHeight(); y++)
{
// Get a pixel
Color pixel;
pixel.rgb = capture.mTargetBuf[y * ScreenWidth() + x];
// Convert to the Command Prompt pixel analogue
float fLuminance = (0.2987 * pixel.c[2] + 0.587 * pixel.c[1] + 0.114 * pixel.c[0]) / 255.0 * nVariates;
wchar_t c = (int)fLuminance + 'A';
// Display the pixel
Draw(x, y, c, FG_WHITE);
}
return true;
}
};
int main()
{
Example demo;
if (demo.ConstructConsole(256, 240, 4, 4) == RC_OK)
demo.Run();
return 0;
}