-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlive.cpp
65 lines (53 loc) · 1.78 KB
/
live.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
#include "capture.h"
#include "effects.h"
#include "kmeans.h"
#include "timing.h"
#include <csignal>
#include <opencv2/opencv.hpp>
/**
* live.cpp
* Process images in realtime from a single camera.
*/
bool stop = false;
void stop_handler(int s) { stop = true; }
int main(int argc, char** argv)
{
// Catch any stop signals to ensure proper cleanup
struct sigaction sigIntHandler;
sigIntHandler.sa_handler = stop_handler;
sigemptyset(&sigIntHandler.sa_mask);
sigIntHandler.sa_flags = 0;
sigaction(SIGINT, &sigIntHandler, NULL);
ImageCapture capture(0);
Kmeans kmeans_src(8, 100, &capture);
size_t last_frame = 0;
// Make window show up fullscreen
namedWindow("Window", cv::WINDOW_NORMAL);
setWindowProperty("Window", cv::WND_PROP_FULLSCREEN, cv::WINDOW_FULLSCREEN);
while (!stop) {
START_TIMING();
try {
struct Frame frame = capture.getFrame(last_frame);
Mat image = frame.image;
resize(image, image, image.size() / 2);
Mat canny_overlay = Effects::canny(image);
Mat posterized = Effects::posterize(image, kmeans_src.getMeans());
Mat halftone_overlay = Effects::halftone(image);
Mat combined = Effects::overlay(canny_overlay, halftone_overlay, posterized);
resize(combined, combined, combined.size() * 2);
imshow("Window", combined);
} catch (Exception e) {
std::cout << e.what() << std::endl;
break;
} catch (...) {
std::cout << "Caught unexpected exception!" << std::endl;
break;
}
STOP_TIMING("Frame Time");
if (waitKey(1) == 27)
break; // stop capturing by pressing ESC
}
capture.stop();
kmeans_src.stop();
return 0;
}