-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathX11ScreenCap.cxx
58 lines (55 loc) · 1.5 KB
/
X11ScreenCap.cxx
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
#include <opencv2/core.hpp>
#include <opencv2/videoio.hpp>
#include <opencv2/opencv.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/extensions/XTest.h>
int main(int argc, char* argv[] )
{
cv::namedWindow( "Controll Window", cv::WINDOW_NORMAL);
cv::resizeWindow("Controll Window", 1200, 600);
//Screenshot
Display* display = XOpenDisplay(NULL);;
Screen *screen = XScreenOfDisplay(display, 0);
Window root = DefaultRootWindow(display);
int x=0, y=0;
int w=WidthOfScreen(screen);
int h=HeightOfScreen(screen);
//X11 stuff:
XImage* img;
img = XGetImage(display, root, x, y, w, h, AllPlanes, ZPixmap);
cv::Mat Screen;
Screen = cv::Mat(h, w, CV_8UC4, img->data);
//Video Writer:
cv::VideoWriter video("Output.avi", CV_FOURCC('M','J','P','G'), 10, cv::Size(w,h));
cv::Mat Out;
while(true)
{
//GetScreenFrame:
img = XGetImage(display, root, x, y, w, h, AllPlanes, ZPixmap);
Screen = cv::Mat(h, w, CV_8UC4, img->data);
//Convert to usable format:
cvtColor(Screen, Out, CV_RGBA2RGB);
cv::imshow( "Controll Window", Out);
//Export Video:
video.write(Out);
//Clean memory:
Out.release();
Screen.release();
XDestroyImage(img);
//Stop on excape:
char c = (char)cv::waitKey(30);
if( c == 27 )
{
break;
}
}
//Relese Video:
video.release();
//Destory windows:
cv::destroyAllWindows();
return 0;
}